♻️ RecycleNet: MobileNetV3 (Small & Large) for Waste Classification (ONNX)
RecycleNet provides edge-optimized, production-ready deep learning models designed to classify municipal solid waste into 6 recyclable and non-recyclable streams: Cardboard, Glass, Metal, Paper, Plastic, and Trash.
The complete training pipeline, distributed hyperparameter optimization (Ray Tune), MLflow tracking, and dual-serving (FastAPI & Rust Axum) source code are open-source in the PilotLeoYan/RecycleNet-K8s repository.
This repository hosts two production ONNX variants serialized in opset 18 with dynamic batching:
- ⚡
recyclenet-small.onnx(~6.1 MB, 1.52M params): Ultra-compact model engineered for resource-constrained edge hardware, embedded systems, microcontrollers, Raspberry Pi, and client-side WebAssembly. - 🚀
recyclenet-large.onnx(~16.4 MB, 4.21M params): High-capacity model delivering significantly higher classification accuracy (83.11% accuracy, 80.51% macro F1, 0.9790 AUC), engineered for high-throughput cloud microservices (FastAPI, Rust Axum) and edge servers.
📊 Comprehensive Model Comparison
Both models were evaluated on the held-out test split (15% of the TrashNet dataset, 379 samples) with zero data leakage:
| Specification / Metric | MobileNetV3-Small (recyclenet-small.onnx) | MobileNetV3-Large (recyclenet-large.onnx) | $\Delta$ (Large vs Small) |
|---|---|---|---|
| Backbone Architecture | mobilenet_v3_small | mobilenet_v3_large | Higher capacity |
| Total Parameters | 1,524,006 (~1.52M) | 4,209,718 (~4.21M) | +2,685,712 (+176%) |
| ONNX File Size | 6.08 MB (6,378,525 B) | 16.35 MB (17,143,261 B) | +10.27 MB |
| Test Accuracy | 78.10% | 83.11% | +5.01% |
| Macro F1-Score | 74.91% | 80.51% | +5.60% |
| ROC-AUC (One-vs-Rest) | 0.9472 | 0.9790 | +0.0318 |
| Test Loss | 0.6512 | 0.4879 | -0.1633 (lower is better) |
| Numerical Parity ($\Delta_{\max}$) | $2.15 \times 10^{-6}$ | $5.72 \times 10^{-6}$ | Both within $< 10^{-5}$ tolerance |
| Input Shape | [batch_size, 3, 224, 224] | [batch_size, 3, 224, 224] | Identical interface |
| Output Shape | [batch_size, 6] | [batch_size, 6] | Identical interface |
| Target Deployment | Embedded / IoT / Raspberry Pi | Cloud APIs / Rust / High-Accuracy | Flexible trade-off |
📈 Per-Class Detailed Performance Breakdown
The table below contrasts the per-class precision, recall, and F1-score across both model architectures on the test split:
| Class ID | Category | Support | MobileNetV3-Small F1 | MobileNetV3-Large F1 | Large Precision | Large Recall | Large F1 $\Delta$ |
|---|---|---|---|---|---|---|---|
0 | Cardboard | 59 | 88.29% | 87.85% | 97.92% | 79.66% | -0.44% |
1 | Glass | 78 | 79.78% | 85.88% | 79.35% | 93.59% | +6.10% |
2 | Metal | 61 | 77.31% | 82.64% | 83.33% | 81.97% | +5.33% |
3 | Paper | 91 | 80.92% | 84.44% | 85.39% | 83.52% | +3.52% |
4 | Plastic | 66 | 74.24% | 81.75% | 78.87% | 84.85% | +7.51% |
5 | Trash | 24 | 48.89% | 60.47% | 68.42% | 54.17% | +11.58% |
[!TIP] Key Architectural Insight: The increased capacity of
MobileNetV3-Largeyields the most dramatic improvements on complex, ambiguous classes. Trash F1 jumped by +11.58% (precision from 52.4% to 68.4%) and Plastic F1 increased by +7.51% (recall from 74.2% to 84.8%), where subtle texture cues require the richer feature representation of the larger backbone.
🛠️ Input & Output Specification
Both models strictly adhere to the identical tensor contract, allowing seamless drop-in substitution without code modifications.
Input Tensor
- Name:
image - Shape:
[batch_size, 3, 224, 224](Dynamic batch dimension, 3 RGB channels, $224 \times 224$ pixels) - Data Type:
float32 - Normalization (Standard ImageNet):
- $\mu = [0.485, 0.456, 0.406]$
- $\sigma = [0.229, 0.224, 0.225]$
Output Tensor
- Name:
logits - Shape:
[batch_size, 6](Raw, unnormalized class logits) - Data Type:
float32
Class Mapping
{
"0": "cardboard",
"1": "glass",
"2": "metal",
"3": "paper",
"4": "plastic",
"5": "trash"
}
🚀 Quickstart with ONNX Runtime (Python)
Run inference with either variant without installing PyTorch:
import numpy as np
import onnxruntime as ort
from PIL import Image
from huggingface_hub import hf_hub_download
# Choose variant: 'recyclenet-small.onnx' or 'recyclenet-large.onnx'
MODEL_FILENAME = "recyclenet-large.onnx"
# 1. Download model from Hugging Face Hub
model_path = hf_hub_download(
repo_id="LeoYan/recyclenet-mobilenetv3",
filename=MODEL_FILENAME,
)
# 2. Preprocess input image (ImageNet normalization)
def preprocess(image_path: str) -> np.ndarray:
image = Image.open(image_path).convert("RGB").resize((224, 224))
img_data = np.array(image, dtype=np.float32) / 255.0 # Scale to [0, 1]
mean = np.array([0.485, 0.456, 0.406], dtype=np.float32)
std = np.array([0.229, 0.224, 0.225], dtype=np.float32)
normalized = (img_data - mean) / std
# Transform shape: [H, W, C] -> [1, C, H, W]
return np.expand_dims(np.transpose(normalized, (2, 0, 1)), axis=0)
# 3. Execute Inference
labels = {0: "cardboard", 1: "glass", 2: "metal", 3: "paper", 4: "plastic", 5: "trash"}
session = ort.InferenceSession(model_path)
input_name = session.get_inputs()[0].name
input_tensor = preprocess("sample_bottle.jpg")
logits = session.run(None, {input_name: input_tensor})[0]
probabilities = np.exp(logits) / np.sum(np.exp(logits), axis=-1, keepdims=True)
predicted_class = int(np.argmax(probabilities, axis=1)[0])
confidence = float(probabilities[0][predicted_class])
print(f"Model: {MODEL_FILENAME}")
print(f"Prediction: {labels[predicted_class]} ({confidence * 100:.2f}%)")
🔬 Training Pipeline & Reproducibility
Both models were trained using the MLOps pipeline available in PilotLeoYan/RecycleNet-K8s:
- Dataset: TrashNet (2,527 images partitioned 70% train, 15% validation, 15% test).
- Transfer Learning: Backbone pre-trained on ImageNet-1k with custom 6-class classification head and fine-tuning.
- Hyperparameter Optimization: Distributed search with Ray Tune (ASHA scheduler) sweeping learning rate, weight decay, and batch size.
- Tracking & Model Registry: Logged with MLflow Tracking (
mlflow.db) capturing parameters, per-epoch loss/metrics, and confusion matrices. - Parity Verification: Validated with
onnx.checkerand rigorous PyTorch vs ONNX Runtime output delta tests ($\Delta_{\max} < 10^{-5}$). - Serving Backends:
- FastAPI (
src/api): Python REST API with lifespan-managed session cache. - Rust Axum (
rust_inference): Compiled native microservice usingortandaxumachieving sub-millisecond p95 latency.
- FastAPI (
📜 Citation & License
Shared under the MIT License. If you use these models in your academic research or industry project, please cite:
@misc{recyclenet2026,
author = {Ortega Rivera, Leonardo F.},
title = {RecycleNet: Deep Learning & MLOps for Real-Time Waste Classification},
year = {2026},
publisher = {Hugging Face},
howpublished = {\url{https://huggingface.co/LeoYan/recyclenet-mobilenetv3}},
url = {https://github.com/PilotLeoYan/RecycleNet-K8s}
}