Downloads · 30 days
0
24f2004275/cat-dog-classifier
cat-dog-classifier is a image classification model from 24f2004275. Use it when you need a label for an image. The card lists the license as mit.
A PyTorch image classifier that distinguishes cats from dogs, trained on the Kaggle Cat and Dog dataset.
Downloads · 30 days
0
Access
Public
Updated Jun 23, 2026
Repo size
450 MB
Likes
1
Public
Click a slice to open those files.
.pth450 MB · 100%
From the Hugging Face model README
A PyTorch image classifier that distinguishes cats from dogs, trained on the Kaggle Cat and Dog dataset.
| File | Architecture | Val Accuracy | Description |
|---|---|---|---|
mlp_classifier.pth | MLP | 61.1% | Fully connected baseline |
simple_cnn.pth | Simple CNN | 72.6% | 2-layer CNN from scratch |
transfer_learning_fc_only.pth | ResNet18 (FC only) | 97.6% | Frozen backbone, FC head |
transfer_learning_layer4_fc.pth | ResNet18 (Layer4+FC) | 98.1% | Partially unfrozen ResNet18 |
results.json | - | - | Training/validation metrics |
import torch
import torch.nn as nn
from torchvision import models, transforms
from PIL import Image
# Load model
model = models.resnet18()
model.fc = nn.Linear(model.fc.in_features, 2)
model.load_state_dict(torch.load("transfer_learning_layer4_fc.pth", weights_only=True))
model.eval()
# Preprocess
transform = transforms.Compose([
transforms.Resize((224, 224)),
transforms.ToTensor(),
transforms.Normalize([0.5, 0.5, 0.5], [0.5, 0.5, 0.5]),
])
image = Image.open("cat.jpg")
tensor = transform(image).unsqueeze(0)
# Predict
with torch.no_grad():
logits = model(tensor)
probs = torch.softmax(logits, dim=1)
predicted = torch.argmax(probs, dim=1).item()
classes = ["cat", "dog"]
print(f"Prediction: {classes[predicted]} ({probs[0][predicted]:.1%})")
| Model | Train Acc | Val Acc | Train Loss | Val Loss |
|---|---|---|---|---|
| MLP | 66.1% | 61.1% | 123.8 | 36.2 |
| CNN | 88.6% | 70.4% | 53.0 | 36.0 |
| Transfer Learning (FC only) | 96.5% | 97.2% | 18.1 | 3.7 |
| Transfer Learning (Layer4+FC) | 98.6% | 98.1% | 8.1 | 3.0 |