efficientnet-b1 / README.md
Shad0wKillar's picture
Update README.md
a01a93f verified
---
license: mit
tags:
- vision
- image-classification
- pytorch
- efficientnet
datasets:
- Shad0wKillar/pizza_steak_sushi
metrics:
- accuracy
---
# 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](EfficientNet_B1_20percent.pth_curves.png)
### 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](EfficientNet_B1_20percent.pth_confusion_matrix.png)
### 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](EfficientNet_B1_20percent.pth_wrong_pred.png)
## How to use
```python
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()