Trashpanzee: Trash Can vs. Not Trash Classifier

Trashpanzee is a lightweight, edge-ready computer vision model designed to detect waste receptacles and trash cans in images.

Model Summary

  • Architecture: MobileNetV2
  • Format: TensorFlow Lite (model_unquant.tflite, Float32)
  • Model Size: ~2.09 MB
  • Input Resolution: 224 x 224 RGB
  • Input Normalization: (pixel_value / 127.5) - 1.0 (Values scaled to [-1.0, 1.0])
  • Classes:
    • 0: Trash Can
    • 1: Not Trash

Files Included

  • model_unquant.tflite: Unquantized floating-point TFLite model weights.
  • labels.txt: Class index mapping.
  • example_inference.py: Python script for loading and testing inference.

Quickstart (Python)

1. Install Dependencies

pip install huggingface_hub ai-edge-litert pillow numpy

2. Run Inference

import numpy as np
from PIL import Image
from huggingface_hub import hf_hub_download

# Multi-fallback interpreter import
try:
    from ai_edge_litert.interpreter import Interpreter
except ImportError:
    try:
        from tflite_runtime.interpreter import Interpreter
    except ImportError:
        import tensorflow as tf
        Interpreter = tf.lite.Interpreter

# Download from Hugging Face Hub
repo_id = "HalfDemon09I/trashpanzee-classifier"  # Replace with target repo if different
model_path = hf_hub_download(repo_id=repo_id, filename="model_unquant.tflite")
labels_path = hf_hub_download(repo_id=repo_id, filename="labels.txt")

# Read labels (with typo cleanup: 'Not Tash' -> 'Not Trash')
labels = []
with open(labels_path, "r", encoding="utf-8") as f:
    for line in f:
        line = line.strip()
        if line:
            name = line.split(" ", 1)[-1]
            labels.append("Not Trash" if name.lower() == "not tash" else name)

# Initialize interpreter
interpreter = Interpreter(model_path=model_path)
interpreter.allocate_tensors()
input_details = interpreter.get_input_details()
output_details = interpreter.get_output_details()

# Load and preprocess input image
image = Image.open("sample.jpg").convert("RGB").resize((224, 224))
input_data = (np.array(image, dtype=np.float32) / 127.5) - 1.0
input_data = np.expand_dims(input_data, axis=0)

# Run inference
interpreter.set_tensor(input_details[0]["index"], input_data)
interpreter.invoke()
output_data = interpreter.get_tensor(output_details[0]["index"])[0]

# Display predictions
results = {labels[i]: float(output_data[i]) for i in range(len(labels))}
for label, score in sorted(results.items(), key=lambda x: x[1], reverse=True):
    print(f"{label}: {score * 100:.2f}%")

Intended Use & Applications

  • Mobile and edge IoT waste collection and tracking devices.
  • Robotic sorting and autonomous cleaning robots.
  • Educational and smart city recycling awareness applications.
Downloads last month
5
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support

Space using HalfDemon09I/trashpanzee-classifier 1