Update README.md
Browse files
README.md
CHANGED
@@ -2,7 +2,30 @@
|
|
2 |
license: apache-2.0
|
3 |
datasets:
|
4 |
- garythung/trashnet
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
```py
|
8 |
Classification Report:
|
@@ -20,4 +43,68 @@ Classification Report:
|
|
20 |
weighted avg 0.9631 0.9626 0.9626 5054
|
21 |
```
|
22 |
|
23 |
-

|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
license: apache-2.0
|
3 |
datasets:
|
4 |
- garythung/trashnet
|
5 |
+
language:
|
6 |
+
- en
|
7 |
+
base_model:
|
8 |
+
- google/siglip2-base-patch16-224
|
9 |
+
pipeline_tag: image-classification
|
10 |
+
library_name: transformers
|
11 |
+
tags:
|
12 |
+
- Trash
|
13 |
+
- Classification
|
14 |
+
- Net
|
15 |
+
- biology
|
16 |
+
- SigLIP2
|
17 |
---
|
18 |
+
# **Trash-Net**
|
19 |
+
|
20 |
+
> **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.
|
21 |
+
|
22 |
+
The model categorizes images into six classes:
|
23 |
+
- **Class 0:** "cardboard"
|
24 |
+
- **Class 1:** "glass"
|
25 |
+
- **Class 2:** "metal"
|
26 |
+
- **Class 3:** "paper"
|
27 |
+
- **Class 4:** "plastic"
|
28 |
+
- **Class 5:** "trash"
|
29 |
|
30 |
```py
|
31 |
Classification Report:
|
|
|
43 |
weighted avg 0.9631 0.9626 0.9626 5054
|
44 |
```
|
45 |
|
46 |
+

|
47 |
+
|
48 |
+
# **Run with Transformers🤗**
|
49 |
+
|
50 |
+
```python
|
51 |
+
!pip install -q transformers torch pillow gradio
|
52 |
+
```
|
53 |
+
|
54 |
+
```python
|
55 |
+
import gradio as gr
|
56 |
+
from transformers import AutoImageProcessor
|
57 |
+
from transformers import SiglipForImageClassification
|
58 |
+
from transformers.image_utils import load_image
|
59 |
+
from PIL import Image
|
60 |
+
import torch
|
61 |
+
|
62 |
+
# Load model and processor
|
63 |
+
model_name = "prithivMLmods/Trash-Net"
|
64 |
+
model = SiglipForImageClassification.from_pretrained(model_name)
|
65 |
+
processor = AutoImageProcessor.from_pretrained(model_name)
|
66 |
+
|
67 |
+
def trash_classification(image):
|
68 |
+
"""Predicts the category of waste material in the image."""
|
69 |
+
image = Image.fromarray(image).convert("RGB")
|
70 |
+
inputs = processor(images=image, return_tensors="pt")
|
71 |
+
|
72 |
+
with torch.no_grad():
|
73 |
+
outputs = model(**inputs)
|
74 |
+
logits = outputs.logits
|
75 |
+
probs = torch.nn.functional.softmax(logits, dim=1).squeeze().tolist()
|
76 |
+
|
77 |
+
labels = {
|
78 |
+
"0": "cardboard",
|
79 |
+
"1": "glass",
|
80 |
+
"2": "metal",
|
81 |
+
"3": "paper",
|
82 |
+
"4": "plastic",
|
83 |
+
"5": "trash"
|
84 |
+
}
|
85 |
+
predictions = {labels[str(i)]: round(probs[i], 3) for i in range(len(probs))}
|
86 |
+
|
87 |
+
return predictions
|
88 |
+
|
89 |
+
# Create Gradio interface
|
90 |
+
iface = gr.Interface(
|
91 |
+
fn=trash_classification,
|
92 |
+
inputs=gr.Image(type="numpy"),
|
93 |
+
outputs=gr.Label(label="Prediction Scores"),
|
94 |
+
title="Trash Classification",
|
95 |
+
description="Upload an image to classify the type of waste material."
|
96 |
+
)
|
97 |
+
|
98 |
+
# Launch the app
|
99 |
+
if __name__ == "__main__":
|
100 |
+
iface.launch()
|
101 |
+
```
|
102 |
+
|
103 |
+
# **Intended Use:**
|
104 |
+
|
105 |
+
The **Trash-Net** model is designed to classify waste materials into different categories. Potential use cases include:
|
106 |
+
|
107 |
+
- **Waste Management:** Assisting in automated waste sorting and recycling.
|
108 |
+
- **Environmental Monitoring:** Identifying and categorizing waste in public spaces.
|
109 |
+
- **Educational Purposes:** Teaching waste classification and sustainability.
|
110 |
+
- **Smart Cities:** Enhancing waste disposal systems through AI-driven classification.
|