garythung/trashnet
Viewer β’ Updated β’ 5.05k β’ 3.45k β’ 30
Run prithivMLmods/Trash-Net on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Use HF Jobs to fine-tune https://huggingface.co/prithivMLmods/Trash-Net. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Use HF Jobs to run batch inference with https://huggingface.co/prithivMLmods/Trash-Net on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
How to use prithivMLmods/Trash-Net with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("image-classification", model="prithivMLmods/Trash-Net")
pipe("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/hub/parrots.png") # pip install -U transformers accelerate
# Load model directly
from transformers import AutoProcessor, AutoModelForImageClassification
processor = AutoProcessor.from_pretrained("prithivMLmods/Trash-Net")
model = AutoModelForImageClassification.from_pretrained("prithivMLmods/Trash-Net", device_map="auto")Trash-Net is an image classification vision-language encoder model fine-tuned from google/siglip2-base-patch16-224 for a single-label classification task. It is designed to classify images of waste materials into different categories using the SiglipForImageClassification architecture.
The model categorizes images into six classes:
Classification Report:
precision recall f1-score support
cardboard 0.9912 0.9739 0.9825 806
glass 0.9564 0.9641 0.9602 1002
metal 0.9523 0.9744 0.9632 820
paper 0.9520 0.9848 0.9681 1188
plastic 0.9835 0.9274 0.9546 964
trash 0.9127 0.9161 0.9144 274
accuracy 0.9626 5054
macro avg 0.9580 0.9568 0.9572 5054
weighted avg 0.9631 0.9626 0.9626 5054
!pip install -q transformers torch pillow gradio
import gradio as gr
from transformers import AutoImageProcessor
from transformers import SiglipForImageClassification
from transformers.image_utils import load_image
from PIL import Image
import torch
# Load model and processor
model_name = "prithivMLmods/Trash-Net"
model = SiglipForImageClassification.from_pretrained(model_name)
processor = AutoImageProcessor.from_pretrained(model_name)
def trash_classification(image):
"""Predicts the category of waste material in the image."""
image = Image.fromarray(image).convert("RGB")
inputs = processor(images=image, return_tensors="pt")
with torch.no_grad():
outputs = model(**inputs)
logits = outputs.logits
probs = torch.nn.functional.softmax(logits, dim=1).squeeze().tolist()
labels = {
"0": "cardboard",
"1": "glass",
"2": "metal",
"3": "paper",
"4": "plastic",
"5": "trash"
}
predictions = {labels[str(i)]: round(probs[i], 3) for i in range(len(probs))}
return predictions
# Create Gradio interface
iface = gr.Interface(
fn=trash_classification,
inputs=gr.Image(type="numpy"),
outputs=gr.Label(label="Prediction Scores"),
title="Trash Classification",
description="Upload an image to classify the type of waste material."
)
# Launch the app
if __name__ == "__main__":
iface.launch()
The Trash-Net model is designed to classify waste materials into different categories. Potential use cases include: