Downloads · 30 days
0
delcenjo/flower-image-classifier
flower-image-classifier is a image classification model from delcenjo. Use it when you need a label for an image. It is set up for pytorch. The card lists the license as mit.
Try the live demo: https://huggingface.co/spaces/delcenjo/flower-classifier-demo Code on GitHub: https://github.com/delcenjo/flower-image-classifier
Downloads · 30 days
0
Access
Public
Updated Jun 21, 2026
Repo size
44.8 MB
Likes
0
Public
Click a slice to open those files.
.pt44.8 MB · 100%
From the Hugging Face model README
Try the live demo: https://huggingface.co/spaces/delcenjo/flower-classifier-demo Code on GitHub: https://github.com/delcenjo/flower-image-classifier
A small image classifier that recognises five flower species (daisy, dandelion, roses, sunflowers, tulips) using transfer learning on a pre-trained ResNet-18. The ImageNet backbone is frozen and only a new classification head is trained, so it runs well on CPU.
import torch
from PIL import Image
from torchvision import models, transforms
from huggingface_hub import hf_hub_download
ckpt = torch.load(
hf_hub_download("delcenjo/flower-image-classifier", "flower_classifier.pt"),
map_location="cpu",
)
classes = ckpt["classes"]
model = models.resnet18(weights=None)
model.fc = torch.nn.Linear(model.fc.in_features, len(classes))
model.load_state_dict(ckpt["model_state"])
model.eval()
preprocess = transforms.Compose([
transforms.Resize((128, 128)),
transforms.ToTensor(),
transforms.Normalize((0.485, 0.456, 0.406), (0.229, 0.224, 0.225)),
])
image = Image.open("flower.jpg").convert("RGB")
with torch.no_grad():
probs = model(preprocess(image).unsqueeze(0)).softmax(dim=1)[0]
print(classes[int(probs.argmax())], float(probs.max()))
Trained on a small dataset at 128x128 with a frozen backbone, so accuracy is modest. Unfreezing the last ResNet block and training at 224x224 would improve it.