Skip to content
ModelListedExternal
Download

Cat Dog Classifier

A ResNet50 transfer-learning classifier that distinguishes cats from dogs at 94% validation accuracy (AUC 0.98), trained in two stages on the Oxford-IIIT Pet dataset.

KindOtherVersionRevision 622f1d7

Model source

Kind
Other
File size
90.0 MB
Version
vRevision 622f1d7
Updated
Sep 16, 2026
Downloads
5
Source
Hugging Face

Source description

Cat vs Dog Classifier 🐱🐶

License: MIT Code on GitHub

A ResNet50 transfer-learning classifier that distinguishes cats from dogs at ~94% validation accuracy (AUC 0.98), trained in two stages on the Oxford-IIIT Pet dataset.

Full training code, Grad-CAM inference, and a complete beginner's guide: 👉 https://github.com/mtkl6/cat-dog-classifier

⚠️ The inference widget is disabled because this is a custom head on a torchvision backbone (not a transformers model) — load it with the snippet below.

Files

FileWhat
cat_dog_classifier.pttrained weights (raw state_dict, ~90 MB)
config.jsonarchitecture & preprocessing metadata

Usage

import torch, torch.nn as nn
from torchvision import models, transforms
from huggingface_hub import hf_hub_download
from PIL import Image

model = models.resnet50()
model.fc = nn.Sequential(nn.Dropout(0.4), nn.Linear(2048, 1))
weights = hf_hub_download("mtkl6/cat-dog-classifier", "cat_dog_classifier.pt")
model.load_state_dict(torch.load(weights, weights_only=True))
model.eval()

tf = transforms.Compose([
    transforms.Resize((224, 224)), transforms.ToTensor(),
    transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225]),
])
x = tf(Image.open("pet.jpg").convert("RGB")).unsqueeze(0)
p_dog = torch.sigmoid(model(x)).item()
print("dog" if p_dog > 0.5 else "cat", f"({max(p_dog, 1 - p_dog):.1%})")

Labels: 0 = cat, 1 = dog. The model outputs a single logit; apply sigmoid and threshold at 0.5.

Training

BackboneResNet50 (IMAGENET1K_V1), head Dropout(0.4) → Linear(2048, 1)
Stage 1frozen backbone, head only — lr 1e-3, 10 epochs → 86.3% val
Stage 2fine-tune layer4 — lr 1e-5, 10 epochs → 94.2% val, AUC 0.98
Loss / optimBCEWithLogitsLoss, Adam, ReduceLROnPlateau
Input224×224 RGB, ImageNet normalization
DatasetOxford-IIIT Pet (37 breeds → binary)

Citation

@software{cat_dog_classifier_2026,
  author = {Moritz (mtkl6)},
  title  = {Cat vs Dog Classifier: a ResNet50 transfer-learning tutorial},
  year   = {2026},
  url    = {https://github.com/mtkl6/cat-dog-classifier}
}

License

Code & weights: MIT. Dataset: Oxford-IIIT Pet (Parkhi et al., 2012), used under its own research/educational terms.

Sources

1 source
Hugging FacePrimaryVersion 622f1d7ab28959981e55f78e183fb102f7924fa6
huggingface.co/mtkl6/cat-dog-classifier/tree/622f1d7ab28959981e55f78e183fb102f7924fa6

Verified Sep 16

Model artifacts

1 artifact

cat_dog_classifier.pt

pt · 90.0 MB · SHA-256 b38e598c03bd…5b34 · Hugging Face

Download

Source excerpts

2 excerpts

--- license: mit pipeline_tag: image-classification library_name: pytorch inference: false tags: - pytorch - resnet - transfer-learning - image-classification - grad-cam - computer-vision --- # Cat vs Dog Classifier 🐱🐶 [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![Code on GitHub](https://img.shields.io/badge/Code-GitHub-181717.svg?logo=github)](https://github.com/mtkl6/cat-dog-classifier) A **ResNet50 transfer-learning** classifier that distinguishes cats from dogs at **~94% validation accuracy (AUC 0.98)**, trained in two stages on the Oxford-IIIT Pet dataset. Full training code, Grad-CAM inference, and a complete beginner's guide: 👉 **https://github.com/mtkl6/cat-dog-classifier** > ⚠️ The inference widget is disabled because this is a custom head on a > torchvision backbone (not a `transformers` model) — load it with the snippet below. ## Files | File | What | |---|---| | `cat_dog_classifier.pt` | trained weights (raw `state_dict`, ~90 MB) | | `config.json` | architecture & preprocessing metadata | ## Usage ```python import torch, torch.nn as nn from torchvision import models, transforms from huggingface_hub import hf_hub_download from PIL import Image model = models.resnet50() model.fc = nn.Sequential(nn.Dropout(0.4), nn.Linear(2048, 1)) weights = hf_hub_download("mtkl6/cat-dog-classifier", "cat_dog_classifier.pt") model.load_state_dict(torch.load(weights, weights_only=True)) model.eval() tf = transforms.Compose([ transforms.Resize((224, 224)), transforms.ToTensor(), transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225]), ]) x = tf(Image.open("pet.jpg").convert("RGB")).unsqueeze(0) p_dog = torch.sigmoid(model(x)).item() print("dog" if p_dog > 0.5 else "cat", f"({max(p_dog, 1 - p_dog):.1%})") ``` Labels: **0 = cat, 1 = dog**. The model outputs a single logit; apply `sigmoid` and threshold at 0.5. ## Training | | | |---|---| | Backbone | ResNet50 (`IMAGENET1K_V1`), head `Dropout(0.4) → Linear(2048, 1)` | | Stage 1 | frozen backbone, head only — `lr 1e-3`, 10 epochs → 86.3% val | | Stage 2 | fine-tune `layer4` — `lr 1e-5`, 10 epochs → **94.2% val, AUC 0.98** | | Loss / optim | `BCEWithLogitsLoss`, Adam, `ReduceLROnPlateau` | | Input | 224×224 RGB, ImageNet normalization | | Dataset | [Oxford-IIIT Pet](https://www.robots.ox.ac.uk/~vgg/data/pets/) (37 breeds → bi...

Source context: 5 downloads · 1 likes · Pipeline image-classification · Library pytorch · Repo mtkl6/cat-dog-classifier