Skip to content
ModelListedExternal
Download

Cat Dog Classifier

A PyTorch image classifier that distinguishes cats from dogs, trained on the Kaggle Cat and Dog dataset.

KindOtherVersionRevision 41a33e4

Model source

Kind
Other
File size
42.7–295 MB
Version
vRevision 41a33e4
Updated
Sep 22, 2026
Downloads
0
Source
Hugging Face

Source description

Cat vs Dog Classifier

A PyTorch image classifier that distinguishes cats from dogs, trained on the Kaggle Cat and Dog dataset.

Models Included

FileArchitectureVal AccuracyDescription
mlp_classifier.pthMLP61.1%Fully connected baseline
simple_cnn.pthSimple CNN72.6%2-layer CNN from scratch
transfer_learning_fc_only.pthResNet18 (FC only)97.6%Frozen backbone, FC head
transfer_learning_layer4_fc.pthResNet18 (Layer4+FC)98.1%Partially unfrozen ResNet18
results.json--Training/validation metrics

Usage

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%})")

Training Details

  • Dataset: Kaggle Cat and Dog (8,007 train / 2,025 test)
  • Input: 224x224 RGB, normalized to [-1, 1]
  • Optimizer: Adam (lr=0.001)
  • Loss: CrossEntropyLoss
  • Epochs: MLP(3), CNN(5), Transfer Learning(3)

Results

ModelTrain AccVal AccTrain LossVal Loss
MLP66.1%61.1%123.836.2
CNN88.6%70.4%53.036.0
Transfer Learning (FC only)96.5%97.2%18.13.7
Transfer Learning (Layer4+FC)98.6%98.1%8.13.0

Sources

1 source
Hugging FacePrimaryVersion 41a33e4e44aa31d088e876a3374aa82e8ad0d6c7
huggingface.co/24f2004275/cat-dog-classifier/tree/41a33e4e44aa31d088e876a3374aa82e8ad0d6c7

Verified Sep 10

Model artifacts

4 artifacts

mlp_classifier.pth

pth · 295 MB · SHA-256 a05934f2d859…74ed · Hugging Face

Download

simple_cnn.pth

pth · 49.0 MB · SHA-256 04647db10d55…a3aa · Hugging Face

Download

transfer_learning_fc_only.pth

pth · 42.7 MB · SHA-256 0343cc65d245…2405 · Hugging Face

Download

transfer_learning_layer4_fc.pth

pth · 42.7 MB · SHA-256 4229d055a817…473a · Hugging Face

Download

Source excerpts

2 excerpts

--- license: mit tags: - image-classification - cats-dogs - pytorch - resnet18 - cnn - transfer-learning metrics: - accuracy --- # Cat vs Dog Classifier A PyTorch image classifier that distinguishes cats from dogs, trained on the [Kaggle Cat and Dog dataset](https://www.kaggle.com/datasets/tongpython/cat-and-dog). ## Models Included | 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 | ## Usage ```python 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%})") ``` ## Training Details - **Dataset**: Kaggle Cat and Dog (8,007 train / 2,025 test) - **Input**: 224x224 RGB, normalized to [-1, 1] - **Optimizer**: Adam (lr=0.001) - **Loss**: CrossEntropyLoss - **Epochs**: MLP(3), CNN(5), Transfer Learning(3) ## Results | 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 |

Source context: 0 downloads · 1 likes · Pipeline image-classification · Repo 24f2004275/cat-dog-classifier