Downloads · 30 days
0
maqsudxo1ja/cifar100-cnn-resnet18
cifar100-cnn-resnet18 is a image classification model from maqsudxo1ja. Use it when you need a label for an image. It is set up for pytorch. The card lists the license as mit.
This repository contains two image classification models trained on the CIFAR-100 dataset: a Custom CNN built from scratch, and a ResNet18 model adapted via transfer learning.
Downloads · 30 days
0
Access
Public
Updated Jul 21, 2026
Repo size
50.5 MB
Likes
0
Public
Click a slice to open those files.
.pth50.5 MB · 100%
From the Hugging Face model README
This repository contains two image classification models trained on the CIFAR-100 dataset: a Custom CNN built from scratch, and a ResNet18 model adapted via transfer learning.
| Model | Top-1 Accuracy | Top-5 Accuracy | Parameters | File Size |
|---|---|---|---|---|
| Custom CNN | 55.21% | 84.12% | ~2.1M | 5.57 MB |
| ResNet18 (Transfer Learning) | 71.13% | — | ~11.2M | 45 MB |
Independently verified: on the full CIFAR-100 test set (10,000 images), the ResNet18 model achieved 70.53% accuracy.
CIFAR-100 consists of 60,000 color images (32x32 pixels) across 100 classes: 50,000 training images and 10,000 test images, with 600 images per class.
Input (3x32x32)
→ [Conv2D(32) + BatchNorm + ReLU] x2 → MaxPool → Dropout(0.25)
→ [Conv2D(64) + BatchNorm + ReLU] x2 → MaxPool → Dropout(0.3)
→ [Conv2D(128) + BatchNorm + ReLU] x2 → MaxPool → Dropout(0.4)
→ Flatten → Dense(512) → Dropout(0.5) → Dense(100)
Based on a ResNet18 pretrained on ImageNet, adapted for small (32x32) images as follows:
7x7, stride=2 to 3x3, stride=1MaxPool layer removed (replaced with nn.Identity())import torch
import torch.nn as nn
from torchvision.models import resnet18
from huggingface_hub import hf_hub_download
# Download the model from Hugging Face
resnet_path = hf_hub_download(
repo_id="maqsudxo1ja/cifar100-cnn-resnet18",
filename="resnet18_cifar100.pth"
)
# Rebuild the architecture
model = resnet18(weights=None)
model.conv1 = nn.Conv2d(3, 64, kernel_size=3, stride=1, padding=1, bias=False)
model.maxpool = nn.Identity()
model.fc = nn.Linear(model.fc.in_features, 100)
# Load the weights
model.load_state_dict(torch.load(resnet_path, map_location="cpu"))
model.eval()
import torchvision.transforms as transforms
transform = transforms.Compose([
transforms.Resize((32, 32)),
transforms.ToTensor(),
transforms.Normalize((0.5071, 0.4865, 0.4409), (0.2673, 0.2564, 0.2762))
])
from PIL import Image
import torch
image = Image.open("image.jpg").convert("RGB")
input_tensor = transform(image).unsqueeze(0)
with torch.no_grad():
output = model(input_tensor)
probs = torch.softmax(output, dim=1)[0]
top5_prob, top5_idx = torch.topk(probs, 5)
# class names can be obtained via torchvision.datasets.CIFAR100(...).classes
for i in range(5):
print(f"{classes[top5_idx[i]]}: {top5_prob[i]*100:.2f}%")
| Parameter | Value |
|---|---|
| Optimizer | Adam (weight_decay=1e-4) |
| Learning rate | 0.001 (with ReduceLROnPlateau) |
| Loss function | CrossEntropyLoss |
| Batch size | 128 |
| Data augmentation | RandomCrop, RandomHorizontalFlip |
| Early stopping | Patience = 5 epochs |
| Environment | Kaggle, GPU T4 x2 |
cnn_cifar100.pth — weights of the Custom CNN trained from scratchresnet18_cifar100.pth — weights of the fine-tuned ResNet18 (transfer learning)MIT License