Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,113 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
# Trash Classification Project
|
3 |
+
|
4 |
+
## Overview
|
5 |
+
|
6 |
+
This project focuses on trash classification using machine learning, leveraging multiple datasets with a total of 8,895 images from diverse sources.
|
7 |
+
|
8 |
+
## Datasets
|
9 |
+
|
10 |
+
### 1. Drinking Waste Classification
|
11 |
+
- **Images**: 4,832
|
12 |
+
- **Organization**: Directory-based sorting
|
13 |
+
- **Classes**: 4 recyclable categories
|
14 |
+
- Aluminium Cans
|
15 |
+
- Glass Bottles
|
16 |
+
- PET (Plastic) Bottles
|
17 |
+
- HDPE (Plastic) Milk Bottles
|
18 |
+
|
19 |
+
### 2. TACO (Trash Annotations in Context)
|
20 |
+
- **Images**: 1,530
|
21 |
+
- **Environment**: Diverse settings (woods, roads, beaches)
|
22 |
+
- **Format**: Raw images with annotation JSON
|
23 |
+
- **Note**: Requires category mapping for proper sorting
|
24 |
+
|
25 |
+
### 3. TrashNet
|
26 |
+
- **Images**: 2,533
|
27 |
+
- **Organization**: Directory-based sorting
|
28 |
+
- **Classes**: 6 categories
|
29 |
+
- Cardboard
|
30 |
+
- Glass
|
31 |
+
- Metal
|
32 |
+
- Paper
|
33 |
+
- Plastic
|
34 |
+
- Trash (miscellaneous)
|
35 |
+
|
36 |
+
|
37 |
+
### 4. Google Images API
|
38 |
+
- **Images**: 4,500
|
39 |
+
- **Organization**: Directory-based sorting
|
40 |
+
- **Collection**: Scraping images from google images API to expand dataset.
|
41 |
+
## Data Processing Pipeline
|
42 |
+
|
43 |
+
### Image Augmentation
|
44 |
+
We apply 14 different manipulations to expand the dataset:
|
45 |
+
| Transformation | Description |
|
46 |
+
|----------------|-------------|
|
47 |
+
| Grayscale | Convert to grayscale |
|
48 |
+
| Rotation | 90°, 180°, 270° rotations |
|
49 |
+
| Flipping | Horizontal and vertical flips |
|
50 |
+
| Noise | Add random noise |
|
51 |
+
| Blur | Apply Gaussian blur |
|
52 |
+
| Brightness | Brighten and darken |
|
53 |
+
| Color Effects | Invert colors, posterize, solarize |
|
54 |
+
| Equalization | Histogram equalization |
|
55 |
+
|
56 |
+
### Standardization
|
57 |
+
- All images are resized to 224×224 pixels
|
58 |
+
- Stored as NumPy arrays (.npy) or PyTorch tensors
|
59 |
+
|
60 |
+
## HuggingFace Dataset Upload Instructions
|
61 |
+
|
62 |
+
1. **Generate Image Variations**
|
63 |
+
```bash
|
64 |
+
python img_manipulation.py
|
65 |
+
```
|
66 |
+
|
67 |
+
2. **Standardize Images**
|
68 |
+
```bash
|
69 |
+
python standardize.py
|
70 |
+
```
|
71 |
+
|
72 |
+
3. **Upload to HuggingFace**
|
73 |
+
```bash
|
74 |
+
# Install HuggingFace CLI
|
75 |
+
pip install huggingface_hub
|
76 |
+
|
77 |
+
# Upload files
|
78 |
+
python upload_files.py
|
79 |
+
```
|
80 |
+
Note: Modify paths in upload_files.py to point to your data
|
81 |
+
|
82 |
+
|
83 |
+
## Model Architecture: ResNet
|
84 |
+
We implement a ResNet (Residual Network) architecture for our trash classification task, leveraging the power of deep residual learning. ResNet represents a significant advancement over traditional Convolutional Neural Networks (CNNs) by introducing skip connections that allow information to bypass layers. This solution addresses the vanishing gradient problem that plagued deep networks, where gradients become extremely small during backpropagation, preventing effective training of deeper layers.
|
85 |
+
|
86 |
+
Unlike conventional CNNs where performance degrades as network depth increases beyond a certain point, ResNets can be substantially deeper (50, 101, or even 152 layers) while maintaining or improving accuracy. The key innovation is the residual block structure, which learns residual mappings instead of direct mappings, making optimization easier. This allows the network to decide whether to use or skip certain layers during training, effectively creating an ensemble of networks with different depths.
|
87 |
+
|
88 |
+
For our trash classification task, this architecture provides superior feature extraction capabilities, capturing both fine-grained details and higher-level abstractions necessary for distinguishing between various waste materials.
|
89 |
+
|
90 |
+
### Key Features
|
91 |
+
|
92 |
+
- **Architecture**: ResNet with Bottleneck blocks
|
93 |
+
- **Implementation**: Built using TinyGrad for efficient training
|
94 |
+
- **Structure**:
|
95 |
+
- Initial 7×7 convolution with stride 2
|
96 |
+
- Four residual layers with bottleneck blocks
|
97 |
+
- Global average pooling
|
98 |
+
- Fully connected layer for classification
|
99 |
+
- **Residual Learning**: Uses skip connections to address the vanishing gradient problem
|
100 |
+
- **Configuration**:
|
101 |
+
- Input size: 224×224×3 (RGB images)
|
102 |
+
- Output: 3 classes (Compostable, Non-recyclable, Recyclable)
|
103 |
+
|
104 |
+
### Training Process
|
105 |
+
|
106 |
+
- **Optimizer**: SGD with momentum (0.9)
|
107 |
+
- **Learning Rate**: 0.001
|
108 |
+
- **Batch Size**: Variable (configurable)
|
109 |
+
- **Metrics**: Accuracy, Precision, Recall, F1-score
|
110 |
+
|
111 |
+
### Performance Evaluation
|
112 |
+
|
113 |
+
The model is evaluated on a held-out test set with comprehensive metrics to ensure robust classification across all waste categories.
|