Upload README.md with huggingface_hub
Browse files
README.md
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
tags:
|
| 3 |
+
- image-classification
|
| 4 |
+
- pytorch
|
| 5 |
+
- waste-classification
|
| 6 |
+
- mobilenetv2
|
| 7 |
+
- computer-vision
|
| 8 |
+
- recycling
|
| 9 |
+
license: mit
|
| 10 |
+
metrics:
|
| 11 |
+
- accuracy
|
| 12 |
+
pipeline_tag: image-classification
|
| 13 |
+
---
|
| 14 |
+
|
| 15 |
+
# ποΈ Smart Waste Classification Model
|
| 16 |
+
|
| 17 |
+
A fine-tuned **MobileNetV2** model for classifying waste items into 6 categories using computer vision.
|
| 18 |
+
|
| 19 |
+
## Model Performance
|
| 20 |
+
- **Validation Accuracy**: 97.46%
|
| 21 |
+
- **Framework**: PyTorch
|
| 22 |
+
- **Architecture**: MobileNetV2
|
| 23 |
+
|
| 24 |
+
## Classes
|
| 25 |
+
|
| 26 |
+
| Class | Description | Color |
|
| 27 |
+
|-------|-------------|-------|
|
| 28 |
+
| π΅ **plastic** | Bottles, bags, containers | Blue |
|
| 29 |
+
| π **paper** | Newspapers, cardboard, magazines | Brown |
|
| 30 |
+
| π **metal** | Cans, foil, batteries | Gray |
|
| 31 |
+
| π **glass** | Bottles, jars | Green |
|
| 32 |
+
| π’ **organic** | Food waste, plant matter | Dark Green |
|
| 33 |
+
| β« **non-recyclable** | Mixed/contaminated waste | Black |
|
| 34 |
+
|
| 35 |
+
## Quick Usage
|
| 36 |
+
|
| 37 |
+
```python
|
| 38 |
+
import torch
|
| 39 |
+
from torchvision import models, transforms
|
| 40 |
+
from PIL import Image
|
| 41 |
+
from huggingface_hub import hf_hub_download
|
| 42 |
+
|
| 43 |
+
# Download model
|
| 44 |
+
model_path = hf_hub_download(repo_id="karthikeya09/smart_image_recognation", filename="best_model.pth")
|
| 45 |
+
|
| 46 |
+
# Load model
|
| 47 |
+
model = models.mobilenet_v2(weights=None)
|
| 48 |
+
model.classifier = torch.nn.Sequential(
|
| 49 |
+
torch.nn.Dropout(p=0.2),
|
| 50 |
+
torch.nn.Linear(1280, 6)
|
| 51 |
+
)
|
| 52 |
+
checkpoint = torch.load(model_path, map_location='cpu')
|
| 53 |
+
model.load_state_dict(checkpoint['model_state_dict'])
|
| 54 |
+
model.eval()
|
| 55 |
+
|
| 56 |
+
# Define transforms
|
| 57 |
+
transform = transforms.Compose([
|
| 58 |
+
transforms.Resize((224, 224)),
|
| 59 |
+
transforms.ToTensor(),
|
| 60 |
+
transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
|
| 61 |
+
])
|
| 62 |
+
|
| 63 |
+
# Predict
|
| 64 |
+
classes = ['glass', 'metal', 'non-recyclable', 'organic', 'paper', 'plastic']
|
| 65 |
+
image = Image.open('your_image.jpg').convert('RGB')
|
| 66 |
+
input_tensor = transform(image).unsqueeze(0)
|
| 67 |
+
|
| 68 |
+
with torch.no_grad():
|
| 69 |
+
outputs = model(input_tensor)
|
| 70 |
+
probs = torch.nn.functional.softmax(outputs, dim=1)
|
| 71 |
+
confidence, predicted = torch.max(probs, 1)
|
| 72 |
+
|
| 73 |
+
print(f'Predicted: {classes[predicted.item()]} ({confidence.item()*100:.1f}%)')
|
| 74 |
+
```
|
| 75 |
+
|
| 76 |
+
## Training Details
|
| 77 |
+
|
| 78 |
+
- **Dataset**: ~21,000 waste images
|
| 79 |
+
- **Training Split**: 70% train, 15% val, 15% test
|
| 80 |
+
- **Optimizer**: Adam (lr=0.001)
|
| 81 |
+
- **Class Weights**: Used to handle class imbalance
|
| 82 |
+
- **Data Augmentation**: Random crop, flip, rotation, color jitter
|
| 83 |
+
- **Input Size**: 224x224 RGB
|
| 84 |
+
|
| 85 |
+
## Dataset Distribution
|
| 86 |
+
|
| 87 |
+
| Category | Images |
|
| 88 |
+
|----------|--------|
|
| 89 |
+
| Organic | 6,620 |
|
| 90 |
+
| Glass | 4,022 |
|
| 91 |
+
| Paper | 3,882 |
|
| 92 |
+
| Metal | 3,428 |
|
| 93 |
+
| Plastic | 1,870 |
|
| 94 |
+
| Non-recyclable | 1,394 |
|
| 95 |
+
|
| 96 |
+
## Model Architecture
|
| 97 |
+
|
| 98 |
+
```
|
| 99 |
+
MobileNetV2 (pretrained on ImageNet)
|
| 100 |
+
βββ classifier
|
| 101 |
+
βββ Dropout(p=0.2)
|
| 102 |
+
βββ Linear(1280, 6)
|
| 103 |
+
```
|
| 104 |
+
|
| 105 |
+
## License
|
| 106 |
+
|
| 107 |
+
MIT License
|
| 108 |
+
|
| 109 |
+
## Author
|
| 110 |
+
|
| 111 |
+
**K Karthikeya Gupta**
|