Instructions to use AIM-Focus-DEV/Image_classifier with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Keras
How to use AIM-Focus-DEV/Image_classifier with Keras:
# !pip install -U keras tensorflow huggingface_hub # Keras needs TensorFlow installed to read "hf://" paths, so the tensorflow backend is selected here; # "jax" and "torch" also work for computation once TensorFlow is installed. import os os.environ["KERAS_BACKEND"] = "tensorflow" import keras model = keras.saving.load_model("hf://AIM-Focus-DEV/Image_classifier") - Notebooks
- Google Colab
- Kaggle
File size: 973 Bytes
9d8daba | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | import streamlit as st
import requests
from PIL import Image
from io import BytesIO
CLASS_LABELS = {
0: "airplane",
1: "bird",
2: "car",
3: "cat",
4: "deer",
5: "dog",
6: "horse",
7: "monkey",
8: "ship",
9: "truck",
}
def get_classification(image_bytes):
response = requests.post("http://localhost:5000/classify", files={"file": image_bytes})
class_id = response.json()["classification"]
return CLASS_LABELS[class_id]
st.title("Image Classification")
st.write("Upload an image to classify")
uploaded_file = st.file_uploader("Choose an image", type=["jpg", "jpeg", "png"])
if uploaded_file is not None:
image = Image.open(uploaded_file)
st.image(image, caption="Uploaded Image", use_column_width=True)
if st.button("Classify"):
img_bytes = uploaded_file.read()
label = get_classification(img_bytes)
st.write("Prediction:", label)
|