dpdl-benchmark/oxford_flowers102
Viewer β’ Updated β’ 8.19k β’ 7.2k β’ 12
Model: nailarais1/image-classifier-efficientnet
Author: Naila Rais
Task: Image Classification Β· 102 Flower Species
pip install torch torchvision pillow
import torch
import torchvision.transforms as transforms
from PIL import Image
# Load model
checkpoint = torch.load('best_model.pth', map_location='cpu')
model = ... # Your model architecture
model.load_state_dict(checkpoint['model_state_dict'])
model.eval()
# Predict flower
def predict_flower(image_path):
transform = transforms.Compose([
transforms.Resize(256),
transforms.CenterCrop(224),
transforms.ToTensor(),
transforms.Normalize(mean=[0.485, 0.456, 0.406],
std=[0.229, 0.224, 0.225])
])
image = Image.open(image_path).convert('RGB')
image_tensor = transform(image).unsqueeze(0)
with torch.no_grad():
outputs = model(image_tensor)
_, predicted = torch.max(outputs, 1)
return predicted.item()
# Get flower name
flower_id = predict_flower('your_flower.jpg')
flower_name = class_names[flower_id] # Use class_config.json
print(f"Predicted: {flower_name}")
102 species including:
# Get top-5 predictions
def top_k_predictions(image_path, k=5):
# ... (implementation)
return [
{"flower": "rose", "confidence": 0.98},
{"flower": "tulip", "confidence": 0.01},
# ...
]
MIT License - Free for personal and commercial use β
Download and start classifying flowers today! πΈ
Model by Naila Rais Β· Hosted on Hugging Face