EfficientNet-B1 Pizza/Steak/Sushi Classifier

I fine-tuned a pre-trained EfficientNet-B1 model to classify images into three categories: pizza, steak, and sushi.

Model Details

  • Architecture: torchvision.models.efficientnet_b1
  • Weights: EfficientNet_B1_Weights.DEFAULT
  • Modifications: I froze all the base feature layers

Training Procedure

I trained the model for 10 epochs using the Adam optimizer.

  • Batch Size: 32
  • Learning Rate: 0.001
  • Loss Function: CrossEntropyLoss
  • Transforms: I used the automatic transforms provided by the default EfficientNet-B1 weights.
  • Hardware: Trained using cuda (if available) with a set manual seed of 37 for reproducibility].

Dataset

I used a 20% subset of a pizza, steak, and sushi dataset. The data was split into train and test directories.

Evaluation Results

Accuracy and Loss Curves

Over the 10 epochs, both the training and testing loss steadily decreased, with the testing loss ending below 0.40. The testing accuracy outperformed the training accuracy early on and finished highly stable above 90%.

Loss and Accuracy Curves

Confusion Matrix

The model performs exceptionally well across all three classes on the test set:

  • Pizza: 45 correct, 0 misclassified as steak, 1 misclassified as sushi.
  • Steak: 56 correct, 0 misclassified as pizza, 2 misclassified as sushi.
  • Sushi: 42 correct, 3 misclassified as pizza, 1 misclassified as steak.

Confusion Matrix

Most Confident Wrong Predictions

I plotted the instances where the model was highly confident but incorrect. The model occasionally struggled with distinguishing close-up textures, such as predicting a steak dish as sushi with 0.82 confidence, or a sushi dish as pizza with 0.61 confidence.

Wrong Predictions

How to use

import torch
import torchvision

# 1. Load the model architecture
weights = torchvision.models.EfficientNet_B1_Weights.DEFAULT
model = torchvision.models.efficientnet_b1(weights=weights)

# 2. Modify the classifier to match the 3 classes
model.classifier = torch.nn.Sequential(
    torch.nn.Dropout(p=0.2, inplace=True),
    torch.nn.Linear(in_features=1280, out_features=3, bias=True),
)

# 3. Load the weights
model.load_state_dict(torch.load("EfficientNet_B1_20percent.pth", map_location="cpu"))
model.eval()
Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Dataset used to train Shad0wKillar/efficientnet-b1

Space using Shad0wKillar/efficientnet-b1 1

Collection including Shad0wKillar/efficientnet-b1