🐶 Dog Breed Classification – ResNet50
A high-accuracy dog breed classifier trained on 120 breeds
📌 Overview
This repository contains a fine-tuned ResNet50 model for dog breed classification.
Given an input dog image, the model predicts the most likely breed among 120 classes.
This model is designed for:
🐕 Dog breed classification
🖼️ Image understanding & retrieval
🧪 Educational deep-learning projects
🚀 Plug-and-play inference in Streamlit / Python / FastAPI
🧠 Model Architecture
Backbone: ResNet50 (ImageNet pretrained)
Head: Fully-connected layer with softmax
Loss: Cross Entropy
Optimizer: AdamW
Training Epochs: 15
Input Size: 224×224
Number of classes: {len(id2breed)}
📁 Files Included
File Description
resnet50_dog.pth Trained model weights
id2breed.json Mapping {class_index → breed_name}
README.md Model card (this file)
The mapping file is essential for converting numerical model outputs into human-readable breed names.
🔍 Inference Example (Python)
import torch
from torchvision import transforms
from PIL import Image
from huggingface_hub import hf_hub_download
import json
1. Download files
repo_id = "djhua0103/dog-breed-resnet50"
ckpt_path = hf_hub_download(repo_id, "resnet50_dog_best.pth")
json_path = hf_hub_download(repo_id, "id2breed.json")
2. Load label mapping
with open(json_path, "r") as f:
id2breed = json.load(f)
3. Build model
from torchvision.models import resnet50
model = resnet50(weights=None)
model.fc = torch.nn.Linear(model.fc.in_features, len(id2breed))
model.load_state_dict(torch.load(ckpt_path, map_location="cpu"))
model.eval()
4. Preprocess image
transform = transforms.Compose([
transforms.Resize((224,224)),
transforms.ToTensor()
])
img = Image.open("dog.jpg")
x = transform(img).unsqueeze(0)
5. Predict
with torch.no_grad():
logits = model(x)
prob = logits.softmax(dim=1)
idx = prob.argmax().item()
breed = id2breed[str(idx)]
print("Predicted breed:", breed)
🚀 Use in Streamlit
This model can be easily integrated into any Streamlit app:
from huggingface_hub import hf_hub_download
from multimodal_dog.models.classifier import DogClassifier
model = DogClassifier.from_hf(device="cpu")
breed, confidence = model.predict(image_tensor)
📊 Dataset
The dataset is based on the Kaggle Dogs Dataset (
https://www.kaggle.com/competitions/dog-breed-identification/), containing images of 120 dog breeds.
Labels are derived from labels.csv and converted into class indices using alphabetical ordering.
🏷️ Labels
All breed names are stored in id2breed.json.
📘 License
Specify your license (MIT / Apache / custom).
🙌 Acknowledgements
ResNet50 from PyTorch
Hugging Face Hub
Dataset provider (Kaggle / Stanford Dogs)