YSMlearnsCode commited on
Commit
91b5fdf
·
1 Parent(s): e61b0ad

corrected waste categories, added readme and model training notebook and sample images

Browse files
README.md CHANGED
@@ -10,8 +10,72 @@ app_file: app.py
10
  pinned: false
11
  ---
12
 
13
- # Mülltrenner9000
 
14
 
15
- Bin there, sorted that.
16
- An instance segmentation app for waste classification, built with Gradio and YOLOv8.
17
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  pinned: false
11
  ---
12
 
13
+ # Mülltrenner9000 ♻️
14
+ **Bin there, sorted that.**
15
 
16
+ An instance segmentation app for waste classification, built with Gradio and YOLOv11.
 
17
 
18
+ Mülltrenner9000 is a smart instance segmentation web app that classifies and segments waste into **59 categories**, recommending the correct **German recycling bin**—such as Gelbe Tonne, Restmüll, or Pfand—based on real-time object detection.
19
+
20
+ The model uses a fine-tuned **YOLOv11 segmentation** model (YOLO11m-seg) and offers an interactive Gradio-based UI for waste classification and bin assignment.
21
+
22
+ ---
23
+
24
+ 🔗 **Try it on Hugging Face Spaces**: [Mülltrenner9000 – Hugging Face Space](https://huggingface.co/spaces/Yas1n/mulltrenner9000)
25
+
26
+ ---
27
+ ## 🧠 What It Does
28
+
29
+ - ✅ **Instance Segmentation** of individual waste items
30
+ - ✅ **Classification** into correct bins:
31
+ - **Yellow Bin (Gelbe Tonne)** – Plastics & Metals
32
+ - **Grey Bin (Restmüll)** – General Waste
33
+ - **Green Bin (Biotonne)** – Biodegradable Waste
34
+ - **Blue Bin (Papiertonne)** – Paper & Cardboard
35
+ - **Glascontainer** – Glass Waste
36
+ - **Hazardous Waste (Sondermüll)** – e.g. Batteries, Chemicals
37
+ - **Deposit Return (Pfand)** – Refundable items
38
+ - ✅ **Real-time segmentation masks** with bin color overlays and labels
39
+
40
+ ---
41
+
42
+ ## 🗂 Dataset
43
+
44
+ - **Source:** [TACO: Trash Annotations in Context (Roboflow)](https://universe.roboflow.com/mohamed-traore-2ekkp/taco-trash-annotations-in-context/dataset/15)
45
+ - **Annotations:** Pixel-level masks + class labels
46
+ - **Images:** 3147 for training, 299 for validation
47
+ - **Classes:** 59 object types
48
+
49
+ ---
50
+
51
+ ## 🛠 Model Training
52
+
53
+ - **Model**: [YOLOv11 (YOLO11m-seg)](https://github.com/ultralytics/ultralytics)
54
+ - **Backbone**: Fine-tuned with heavy data augmentation (RandAugment, CLAHE, etc.)
55
+ - **Epochs**: Trained for 70 epochs
56
+ - **Batch Size**: 16
57
+ - **Optimizer**: SGD
58
+ - **Learning Rate**: Final stage LR tuned to `0.001`
59
+ - **Mixed Precision**: AMP enabled
60
+
61
+ ---
62
+
63
+ ## 🖼 Sample Output
64
+
65
+ Here is a sample segmentation and classification output of Mülltrenner9000:
66
+
67
+ ![Sample Output](images/sample_image.webp)
68
+ ![Sample Output](images/sample_image_1.webp)
69
+
70
+
71
+ ---
72
+
73
+ ## 🤝 Contribution
74
+
75
+ We welcome contributions from the community, whether it's in the form of bug reports, improvements, documentation, or new features.
76
+
77
+ ---
78
+
79
+ ## 📄 License
80
+
81
+ This project is licensed under the **MIT License**. See the `LICENSE` file for more details.
images/sample_image.webp ADDED
images/sample_image_1.webp ADDED
src/model/training_mulltrenner9000.ipynb ADDED
@@ -0,0 +1,279 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": null,
6
+ "metadata": {
7
+ "colab": {
8
+ "base_uri": "https://localhost:8080/"
9
+ },
10
+ "id": "3uIkSzt52mUL",
11
+ "outputId": "96aacaf4-2244-4799-e1df-4595c67125c7"
12
+ },
13
+ "outputs": [
14
+ {
15
+ "name": "stdout",
16
+ "output_type": "stream",
17
+ "text": [
18
+ "Mounted at /content/drive\n"
19
+ ]
20
+ }
21
+ ],
22
+ "source": [
23
+ "from google.colab import drive\n",
24
+ "drive.mount('/content/drive')"
25
+ ]
26
+ },
27
+ {
28
+ "cell_type": "code",
29
+ "execution_count": null,
30
+ "metadata": {
31
+ "id": "0TygyeSi2HZ1"
32
+ },
33
+ "outputs": [],
34
+ "source": [
35
+ "!pip install torch torchaudio torchvision roboflow ultralytics"
36
+ ]
37
+ },
38
+ {
39
+ "cell_type": "code",
40
+ "execution_count": null,
41
+ "metadata": {
42
+ "colab": {
43
+ "base_uri": "https://localhost:8080/"
44
+ },
45
+ "id": "KlFNecLz2UBJ",
46
+ "outputId": "c01b326d-7c25-4fd2-e004-70ec98233eed"
47
+ },
48
+ "outputs": [
49
+ {
50
+ "name": "stdout",
51
+ "output_type": "stream",
52
+ "text": [
53
+ "loading Roboflow workspace...\n",
54
+ "loading Roboflow project...\n"
55
+ ]
56
+ },
57
+ {
58
+ "name": "stderr",
59
+ "output_type": "stream",
60
+ "text": [
61
+ "Downloading Dataset Version Zip in TACO:-Trash-Annotations-in-Context-Dataset-15 to yolov11:: 100%|██████████| 326497/326497 [00:06<00:00, 53159.31it/s]"
62
+ ]
63
+ },
64
+ {
65
+ "name": "stdout",
66
+ "output_type": "stream",
67
+ "text": [
68
+ "\n"
69
+ ]
70
+ },
71
+ {
72
+ "name": "stderr",
73
+ "output_type": "stream",
74
+ "text": [
75
+ "\n",
76
+ "Extracting Dataset Version Zip to TACO:-Trash-Annotations-in-Context-Dataset-15 in yolov11:: 100%|██████████| 7206/7206 [00:01<00:00, 4606.91it/s]\n"
77
+ ]
78
+ }
79
+ ],
80
+ "source": [
81
+ "# Dataset import (https://universe.roboflow.com/mohamed-traore-2ekkp/taco-trash-annotations-in-context/dataset/15)\n",
82
+ "\n",
83
+ "from roboflow import Roboflow\n",
84
+ "rf = Roboflow(api_key=\"Enter your key\") # Enter your roboflow api key here\n",
85
+ "project = rf.workspace(\"mohamed-traore-2ekkp\").project(\"taco-trash-annotations-in-context\")\n",
86
+ "version = project.version(15)\n",
87
+ "dataset = version.download(\"yolov11\")"
88
+ ]
89
+ },
90
+ {
91
+ "cell_type": "code",
92
+ "execution_count": null,
93
+ "metadata": {
94
+ "colab": {
95
+ "base_uri": "https://localhost:8080/"
96
+ },
97
+ "id": "MtWiembb2fWJ",
98
+ "outputId": "5886ffd9-d982-4fd1-ee3a-98d922990587"
99
+ },
100
+ "outputs": [
101
+ {
102
+ "name": "stdout",
103
+ "output_type": "stream",
104
+ "text": [
105
+ "Creating new Ultralytics Settings v0.0.6 file ✅ \n",
106
+ "View Ultralytics Settings with 'yolo settings' or at '/root/.config/Ultralytics/settings.json'\n",
107
+ "Update Settings with 'yolo settings key=value', i.e. 'yolo settings runs_dir=path/to/dir'. For help see https://docs.ultralytics.com/quickstart/#ultralytics-settings.\n"
108
+ ]
109
+ }
110
+ ],
111
+ "source": [
112
+ "from ultralytics import YOLO"
113
+ ]
114
+ },
115
+ {
116
+ "cell_type": "code",
117
+ "execution_count": null,
118
+ "metadata": {
119
+ "id": "G829VIF32hw1"
120
+ },
121
+ "outputs": [],
122
+ "source": [
123
+ "#Training the model\n",
124
+ "\n",
125
+ "model = YOLO(\"/content/drive/MyDrive/best_heavy_59classes.pt\") # load pretrained model (YOLO11n-seg)\n",
126
+ "\n",
127
+ "# Train the model (single gpu)\n",
128
+ "results = model.train(data=\"/content/TACO:-Trash-Annotations-in-Context-Dataset-15/data.yaml\", epochs=50, imgsz=640)"
129
+ ]
130
+ },
131
+ {
132
+ "cell_type": "markdown",
133
+ "metadata": {
134
+ "id": "iBC5snDI12PQ"
135
+ },
136
+ "source": [
137
+ "### Visualization ###"
138
+ ]
139
+ },
140
+ {
141
+ "cell_type": "code",
142
+ "execution_count": null,
143
+ "metadata": {
144
+ "id": "ogkaAT740wVs"
145
+ },
146
+ "outputs": [],
147
+ "source": [
148
+ "# Waste Bin Mapping (German Mülltrennung System)\n",
149
+ "bin_map = {\n",
150
+ " \"Yellow Bin (Gelbe Tonne)\": [\n",
151
+ " \"Aluminium blister pack\", \"Aluminium foil\", \"Carded blister pack\", \"Clear plastic bottle\",\n",
152
+ " \"Disposable food container\", \"Disposable plastic cup\", \"Drink Carton\", \"Drink can\",\n",
153
+ " \"Foam cup\", \"Meal carton\", \"Metal lid\", \"Metal bottle cap\", \"Other plastic bottle\",\n",
154
+ " \"Other plastic container\", \"Other plastic cup\", \"Other plastic wrapper\", \"Plastic bottle cap\",\n",
155
+ " \"Plastic film\", \"Plastic glooves\", \"Plastic lid\", \"Plastic straw\", \"Polypropylene bag\",\n",
156
+ " \"Pop tab\", \"Single-use carrier bag\", \"Six pack rings\", \"Spread tub\", \"Squeezable tube\",\n",
157
+ " \"Tupperware\"\n",
158
+ " ],\n",
159
+ " \"Grey Bin (Restmüll)\": [\n",
160
+ " \"Cigarette\", \"Garbage bag\", \"Shoe\", \"Unlabeled litter\", \"Plastified paper bag\",\n",
161
+ " \"Styrofoam piece\", \"Rope & strings\", \"Foam food container\", \"Other plastic\",\n",
162
+ " \"Pizza box\", \"Tissues\"\n",
163
+ " ],\n",
164
+ " \"Green Bin (Biotonne)\": [\n",
165
+ " \"Food waste\"\n",
166
+ " ],\n",
167
+ " \"Blue Bin (Papiertonne)\": [\n",
168
+ " \"Egg carton\", \"Normal paper\", \"Other Carton\", \"Paper Bag\", \"Paper cup\", \"Paper straw\",\n",
169
+ " \"Pizza box\", \"Toilet tube\", \"Magazine paper\", \"Wrapping paper\", \"Corrugated carton\"\n",
170
+ " ],\n",
171
+ " \"Glascontainer\": [\n",
172
+ " \"Glass bottle\", \"Glass cup\", \"Glass jar\", \"Broken glass\"\n",
173
+ " ],\n",
174
+ " \"Hazardous Waste (Sondermüll)\": [\n",
175
+ " \"Battery\", \"Aerosol\", \"Scrap metal\"\n",
176
+ " ],\n",
177
+ " \"Deposit Return (Pfand)\": [\n",
178
+ " \"Drink can\", \"Clear plastic bottle\", \"Glass bottle\", \"Food Can\"\n",
179
+ " ]\n",
180
+ "}\n",
181
+ "\n",
182
+ "# Bin colors in BGR format (for OpenCV)\n",
183
+ "bin_colors = {\n",
184
+ " \"Yellow Bin (Gelbe Tonne)\": (0, 255, 255), # Yellow\n",
185
+ " \"Grey Bin (Restmüll)\": (128, 128, 128), # Gray\n",
186
+ " \"Green Bin (Biotonne)\": (0, 255, 0), # Green\n",
187
+ " \"Blue Bin (Papiertonne)\": (200, 0, 0), # Blue (bright)\n",
188
+ " \"Glascontainer\": (0, 0, 0), # Black\n",
189
+ " \"Hazardous Waste (Sondermüll)\": (0, 0, 255), # Red\n",
190
+ " \"Deposit Return (Pfand)\": (255, 0, 255) # Purple/Magenta\n",
191
+ "}\n",
192
+ "\n",
193
+ "class_to_bin = {cls: bin_type for bin_type, cls_list in bin_map.items() for cls in cls_list} #class name gives bin type\n",
194
+ "\n",
195
+ "from ultralytics import YOLO\n",
196
+ "import torch\n",
197
+ "import cv2\n",
198
+ "import numpy as np\n",
199
+ "import matplotlib.pyplot as plt\n",
200
+ "\n",
201
+ "# Load model\n",
202
+ "model = YOLO(\"/content/best_heavy_59classes.pt\") # enter path to your model\n",
203
+ "\n",
204
+ "# Load image\n",
205
+ "image_path = \"/content/IMG-20221229-WA0003_jpg.rf.fce2a8664e953ba379b83eb2e29a32cb.jpg\" # enter image path for testing\n",
206
+ "image = cv2.imread(image_path)\n",
207
+ "image = cv2.resize(image, (640, 640))\n",
208
+ "\n",
209
+ "# Run prediction\n",
210
+ "results = model(image_path)\n",
211
+ "result = results[0]\n",
212
+ "\n",
213
+ "# Get class names\n",
214
+ "class_names = model.names\n",
215
+ "\n",
216
+ "# Inverse mapping: class name → bin\n",
217
+ "class_to_bin = {cls: bin_name for bin_name, class_list in bin_map.items() for cls in class_list}\n",
218
+ "\n",
219
+ "# Get results\n",
220
+ "masks = result.masks.data.cpu().numpy() # [N, H, W]\n",
221
+ "boxes = result.boxes.xyxy.cpu().numpy() # [N, 4]\n",
222
+ "scores = result.boxes.conf.cpu().numpy() # [N]\n",
223
+ "class_ids = result.boxes.cls.cpu().numpy() # [N]\n",
224
+ "\n",
225
+ "overlay = image.copy()\n",
226
+ "\n",
227
+ "for i in range(len(class_ids)):\n",
228
+ " class_id = int(class_ids[i])\n",
229
+ " score = scores[i]\n",
230
+ " mask = masks[i]\n",
231
+ " box = boxes[i].astype(int)\n",
232
+ "\n",
233
+ " class_name = class_names[class_id]\n",
234
+ "\n",
235
+ " bin_type = next((bin_name for bin_name, items in bin_map.items() if class_name in items), \"Cannot detect trash type\")\n",
236
+ " color = bin_colors.get(bin_type, (255, 255, 255)) # fallback to white\n",
237
+ "\n",
238
+ " # Apply colored mask (blended)\n",
239
+ " mask_3c = np.stack([mask] * 3, axis=-1) # [H, W, 3]\n",
240
+ " color_array = np.array(color, dtype=np.uint8).reshape(1, 1, 3)\n",
241
+ " colored_mask = (mask_3c * color_array).astype(np.uint8)\n",
242
+ "\n",
243
+ " overlay = cv2.addWeighted(overlay, 1.0, colored_mask, 0.5, 0)\n",
244
+ "\n",
245
+ " # Draw bounding box\n",
246
+ " cv2.rectangle(overlay, (box[0], box[1]), (box[2], box[3]), color, 2)\n",
247
+ "\n",
248
+ " # Draw label (class name + score + bin)\n",
249
+ " label = f\"{class_name} ({int(score * 100)}%)\\n{bin_type}\"\n",
250
+ " for j, line in enumerate(label.split(\"\\n\")):\n",
251
+ " text_pos = (box[0], box[1] - 10 - 20 * j)\n",
252
+ " cv2.putText(overlay, line, text_pos, cv2.FONT_HERSHEY_SIMPLEX, 0.5, color, 2, cv2.LINE_AA)\n",
253
+ "\n",
254
+ "# Show the image\n",
255
+ "plt.figure(figsize=(14, 10))\n",
256
+ "plt.imshow(cv2.cvtColor(overlay, cv2.COLOR_BGR2RGB))\n",
257
+ "plt.axis(\"off\")\n",
258
+ "plt.title(\"YOLOv11 Mülltrennung Classification Overlay\")\n",
259
+ "plt.show()"
260
+ ]
261
+ }
262
+ ],
263
+ "metadata": {
264
+ "accelerator": "GPU",
265
+ "colab": {
266
+ "gpuType": "T4",
267
+ "provenance": []
268
+ },
269
+ "kernelspec": {
270
+ "display_name": "Python 3",
271
+ "name": "python3"
272
+ },
273
+ "language_info": {
274
+ "name": "python"
275
+ }
276
+ },
277
+ "nbformat": 4,
278
+ "nbformat_minor": 0
279
+ }
src/process/process.py CHANGED
@@ -11,7 +11,7 @@ FILENAME = "best_0.1.0.pt"
11
  bin_map = {
12
  "Yellow Bin (Gelbe Tonne)": [
13
  "Aluminium blister pack", "Aluminium foil", "Carded blister pack", "Clear plastic bottle",
14
- "Disposable food container", "Disposable plastic cup", "Drink Carton", "Drink can",
15
  "Foam cup", "Meal carton", "Metal lid", "Metal bottle cap", "Other plastic bottle",
16
  "Other plastic container", "Other plastic cup", "Other plastic wrapper", "Plastic bottle cap",
17
  "Plastic film", "Plastic glooves", "Plastic lid", "Plastic straw", "Polypropylene bag",
 
11
  bin_map = {
12
  "Yellow Bin (Gelbe Tonne)": [
13
  "Aluminium blister pack", "Aluminium foil", "Carded blister pack", "Clear plastic bottle",
14
+ "Disposable food container", "Disposable plastic cup", "Drink carton",
15
  "Foam cup", "Meal carton", "Metal lid", "Metal bottle cap", "Other plastic bottle",
16
  "Other plastic container", "Other plastic cup", "Other plastic wrapper", "Plastic bottle cap",
17
  "Plastic film", "Plastic glooves", "Plastic lid", "Plastic straw", "Polypropylene bag",