Skip to content

An EfficientNetB2 feature extractor computer vision model to classify images of 7 food [samosa,pizza,steak,sushi,cup cakes,french fries,omelette]

Notifications You must be signed in to change notification settings

anshuS1310/Food-Classifier

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🍔 Food Image Classification using PyTorch + EfficientNet + Gradio

A deep learning project that classifies food images into 7 categories using a CNN-based EfficientNet model built with PyTorch.

The system provides a simple Gradio web interface where users can upload an image and instantly get predictions.


🚀 Features

✅ Image classification using EfficientNet
✅ 7 food categories
✅ Upload image and predict instantly
✅ Clean Gradio web interface
✅ GPU supported training (CUDA)
✅ Lightweight and fast inference


🧠 Classes Detected

The model classifies images into:

  • 🥟 Samosa
  • 🍕 Pizza
  • 🥩 Steak
  • 🍣 Sushi
  • 🧁 Cup Cakes
  • 🍟 French Fries
  • 🍳 Omelette

🛠 Tech Stack

Tool Purpose
PyTorch Model training & inference
EfficientNet CNN architecture
Torchvision Pretrained models & transforms
Gradio Web UI for predictions
CUDA GPU acceleration

📂 Project Structure

food-classifier/
│
├── dataset/              # food images dataset
├── models/               # saved trained weights (.pth)
├── train.py              # training script
├── predict.py            # inference code
├── app.py                # gradio interface
├── requirements.txt
└── README.md

⚙️ Installation

1️⃣ Clone repository

git clone https://github.com/yourusername/food-classifier.git
cd food-classifier

2️⃣ Create virtual environment (recommended)

python -m venv venv
source venv/bin/activate      # Linux/Mac
venv\Scripts\activate         # Windows

3️⃣ Install dependencies

pip install -r requirements.txt

or manually:

pip install torch torchvision gradio pillow opencv-python numpy

🏋️ Training the Model

python train.py

Training Details

  • Architecture: EfficientNet (CNN)
  • Framework: PyTorch
  • Loss Function: CrossEntropyLoss
  • Optimizer: Adam
  • Classes: 7
  • GPU supported (CUDA)

The trained model will be saved inside:

models/model.pth

▶️ Run the Web App (Gradio)

python app.py

Then open in browser:

http://127.0.0.1:7860

🖼 How It Works

  1. Upload an image
  2. Image is preprocessed
  3. EfficientNet extracts features
  4. Model predicts class
  5. Label + confidence shown on screen

💡 Example Usage

Upload:

📸 samosa.jpg

Output:

Prediction: Samosa
Confidence: 96.3%

📊 Model Architecture

EfficientNet is used because:

✅ High accuracy
✅ Fewer parameters
✅ Faster training
✅ Good for small datasets


🔮 Future Improvements

  • Add webcam support
  • Add top-3 predictions
  • Mobile deployment
  • Convert to TorchScript
  • Deploy on HuggingFace Spaces
  • Add more food classes

🤝 Contributing

Pull requests are welcome.
Feel free to open issues for improvements or suggestions.


📜 License

MIT License


👤 Author

Anshu Singh
ML Enthusiast

Built as a hands-on CNN + PyTorch learning project 🚀

About

An EfficientNetB2 feature extractor computer vision model to classify images of 7 food [samosa,pizza,steak,sushi,cup cakes,french fries,omelette]

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages