Downloads ยท 30 days
37
30% of all-time downloads
nailarais1/image-classifier-efficientnet
image-classifier-efficientnet is a image classification model from nailarais1. Use it when you need a label for an image. It is set up for pytorch.
A PyTorch EfficientNet-B0 image classification model trained to recognize 102 flower categories from the Oxford 102 Category Flower Dataset.
Downloads ยท 30 days
37
30% of all-time downloads
All-time downloads
123
Public
Repo size
100 MB
Likes
1
Public
Click a slice to open those files.
.pth50.1 MB ยท 100%
From the Hugging Face model README
A PyTorch EfficientNet-B0 image classification model trained to recognize 102 flower categories from the Oxford 102 Category Flower Dataset.
| Metric | Result |
|---|---|
| Architecture | EfficientNet-B0 |
| Number of classes | 102 |
| Input size | 224 ร 224 |
| Best validation accuracy | 94.38% |
| Training epochs | 3 |
| Optimizer | AdamW |
| Learning rate | 0.001 |
The model was trained using transfer learning with an ImageNet-pretrained EfficientNet-B0 backbone.
This model was trained using the Oxford 102 Category Flower Dataset, created by Maria-Elena Nilsback and Andrew Zisserman.
The dataset contains 102 flower categories with variations in scale, pose, lighting, and appearance.
Official dataset page:
https://www.robots.ox.ac.uk/~vgg/data/flowers/102/
Please review the original dataset documentation and terms before using or redistributing dataset-derived material.
checkpoint.pth โ trained PyTorch checkpointmodel_config.json โ model architecture informationtraining_config.json โ training configurationclass_config.json โ exact class/index mappingslabels.txt โ flower labelsrequirements.txt โ Python dependenciesThe checkpoint.pth file contains:
epochmodel_state_dictoptimizer_state_dictclass_to_idxInstall the dependencies:
pip install torch torchvision pillow
Load the model:
import json
import torch
import torch.nn as nn
from torchvision import models, transforms
from PIL import Image
checkpoint = torch.load(
"checkpoint.pth",
map_location="cpu",
weights_only=False
)
model = models.efficientnet_b0(weights=None)
model.classifier[1] = nn.Linear(
model.classifier[1].in_features,
102
)
model.load_state_dict(
checkpoint["model_state_dict"]
)
model.eval()
with open(
"class_config.json",
"r",
encoding="utf-8"
) as f:
class_config = json.load(f)
idx_to_class = {
int(k): v
for k, v in class_config["idx_to_class"].items()
}
transform = transforms.Compose([
transforms.Resize(256),
transforms.CenterCrop(224),
transforms.ToTensor(),
transforms.Normalize(
[0.485, 0.456, 0.406],
[0.229, 0.224, 0.225]
)
])
image = Image.open(
"flower.jpg"
).convert("RGB")
x = transform(
image
).unsqueeze(0)
with torch.inference_mode():
probabilities = torch.softmax(
model(x),
dim=1
)
confidence, prediction = probabilities.max(
dim=1
)
idx = prediction.item()
print(
"Prediction:",
idx_to_class[idx]
)
print(
"Confidence:",
f"{confidence.item() * 100:.2f}%"
)
You can also get the five most likely flower categories:
with torch.inference_mode():
probabilities = torch.softmax(
model(x),
dim=1
)
values, indices = torch.topk(
probabilities,
k=5
)
for probability, index in zip(
values[0],
indices[0]
):
flower = idx_to_class[index.item()]
confidence = probability.item() * 100
print(
f"{flower}: {confidence:.2f}%"
)
The model was trained using transfer learning.
The best validation accuracy achieved during training was:
94.38%
This result corresponds to the validation split used during training.
Performance may vary on images that differ substantially from the training data.
An interactive Gradio application can be deployed using this model so that users can upload flower images directly through a web browser.
The demo can provide:
This model is designed to classify images into the 102 flower categories represented in the training dataset.
Predictions may be less reliable when:
This model should be considered an image-classification research/demo model and not a definitive botanical identification system.
If you use this model or the underlying dataset, please provide attribution to the original dataset authors.
Maria-Elena Nilsback and Andrew Zisserman
"Automated Flower Classification over a Large Number of Classes."
Proceedings of the Indian Conference on Computer Vision, Graphics and Image Processing (ICVGIP), 2008.
Oxford 102 Category Flower Dataset:
https://www.robots.ox.ac.uk/~vgg/data/flowers/102/
Naila Rais
Hugging Face:
nailarais1
Model:
nailarais1/image-classifier-efficientnet
Architecture:
EfficientNet-B0
Best validation accuracy:
94.38%