Downloads · 30 days
0
ash001/cats-dogs-transferlearning-cnn
cats-dogs-transferlearning-cnn is a image classification model from ash001. Use it when you need a label for an image. It is set up for pytorch. The card lists the license as apache-2.0.
A PyTorch image classifier for Cats vs Dogs, trained with transfer learning using a pretrained ResNet-18 backbone.
Downloads · 30 days
0
Access
Public
Updated Mar 2, 2026
Repo size
44.8 MB
Likes
0
Public
Click a slice to open those files.
.pt44.8 MB · 100%
From the Hugging Face model README
A PyTorch image classifier for Cats vs Dogs, trained with transfer learning using a pretrained ResNet-18 backbone.
This Hugging Face repo hosts the trained weights + small config files used by the Streamlit inference app.
pages/06_Cats_vs_Dogs_CNN.py)Stored under artifacts/:
model_state.pt — PyTorch state_dict for ResNet-18 (final FC trained)config.json — image size + normalization statsclass_names.json — class labels (index order)artifacts/config.json)config.json["cats", "dogs"] (from class_names.json)import json
import torch
import torch.nn as nn
from PIL import Image
from torchvision import models, transforms
from huggingface_hub import hf_hub_download
REPO_ID = "ash001/cats-dogs-transferlearning-cnn"
# Download artifacts
cfg_path = hf_hub_download(REPO_ID, "artifacts/config.json")
names_path = hf_hub_download(REPO_ID, "artifacts/class_names.json")
pt_path = hf_hub_download(REPO_ID, "artifacts/model_state.pt")
config = json.load(open(cfg_path, "r"))
class_names = json.load(open(names_path, "r"))
# Rebuild model architecture + load weights
model = models.resnet18(weights=None)
model.fc = nn.Linear(model.fc.in_features, int(config["num_classes"]))
state = torch.load(pt_path, map_location="cpu")
model.load_state_dict(state)
model.eval()
# Preprocess
tfm = transforms.Compose([
transforms.Resize(256),
transforms.CenterCrop(int(config["image_size"])),
transforms.ToTensor(),
transforms.Normalize(mean=config["mean"], std=config["std"]),
])
img = Image.open("your_image.jpg").convert("RGB")
x = tfm(img).unsqueeze(0)
with torch.no_grad():
logits = model(x)
probs = torch.softmax(logits, dim=1)[0].tolist()
pred_idx = int(torch.argmax(logits, dim=1).item())
print("Prediction:", class_names[pred_idx])
print("Probabilities:", dict(zip(class_names, probs)))