🍏 FruitGuard AI β€” Fruit Freshness Detection Model

This repository hosts the official trained Deep Learning model for FruitGuard AI, a high-precision computer vision model classifying fruits as Fresh or Spoiled with 99.84% accuracy.

  • GitHub Repository: HafizRehan5833/system7_project
  • Model Architecture: MobileNetV2 (Transfer Learning from ImageNet)
  • Input Resolution: 224 Γ— 224 RGB
  • Classes: fresh (0), spoiled (1)
  • Supported Varieties: Apple, Banana, Grape, Guava, Jujube, Orange, Pomegranate, Strawberry

πŸ“Š Evaluation & Benchmark Results

Evaluated on 1,850 completely held-out test images:

Metric Fresh Fruit Spoiled Fruit Overall System
Accuracy β€” β€” 99.84% (1,847 / 1,850)
Precision 99.68% 100.00% 99.84%
Recall 100.00% 99.67% 99.84%
F1-Score 0.9984 0.9984 0.9984

πŸ’» Quickstart: How to Use

1. Download & Load the Model

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

# Download weights from Hugging Face
model_path = hf_hub_download(
    repo_id="HafizRehan5833/fruit-freshness-detection",
    filename="fruit_freshness_model.keras"
)

# Load the Keras model
model = tf.keras.models.load_model(model_path, compile=False)

def predict_freshness(image_path: str):
    # Preprocess: RGB, 224x224
    image = Image.open(image_path).convert("RGB").resize((224, 224))
    batch = np.expand_dims(np.asarray(image, dtype=np.float32), axis=0)

    # In-graph rescaling is handled automatically by the model
    spoiled_probability = float(model.predict(batch, verbose=0).ravel()[0])
    fresh_probability = 1.0 - spoiled_probability

    label = "spoiled" if spoiled_probability >= 0.5 else "fresh"
    confidence = spoiled_probability if label == "spoiled" else fresh_probability

    return {
        "verdict": label,
        "confidence": round(confidence * 100, 2),
        "fresh_probability": round(fresh_probability, 4),
        "spoiled_probability": round(spoiled_probability, 4),
    }

# Example run:
# print(predict_freshness("test_apple.jpg"))

🏭 Real-World Applications

  • Automated Conveyor Sorting: Optical inspection in packhouses with pneumatic rejectors.
  • Retail Quality Control: Automated supermarket shelf monitoring and dynamic markdown pricing.
  • Cold Chain Logistics: Receiving dock QA verification to prevent cross-contamination.
  • Food Processing: Pre-crush filter for juices, puree, and baby food manufacturing.

For the complete technical specifications and enterprise architecture, visit the GitHub Repository.

Downloads last month
32
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support