garythung/trashnet
Viewer • Updated • 5.05k • 1.38k • 28
How to use Stefaron/trash-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://Stefaron/trash-classifier")
This model is a fine-tuned ResNet50 for classifying trash images into categories such as plastic, paper, glass, metal, and others.
Load the model and use it for inference:
import tensorflow as tf
model = tf.keras.models.load_model("Stefaron/trash-classifier/best_model.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://Stefaron/trash-classifier")