Views
No views yet
| 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.
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)7x7, stride=2 to 3x3, stride=1MaxPool layer removed (replaced with nn.Identity())1import torch
2import torch.nn as nn
3from torchvision.models import resnet18
4from huggingface_hub import hf_hub_download
5
6# Download the model from Hugging Face
7resnet_path = hf_hub_download(
8 repo_id="maqsudxo1ja/cifar100-cnn-resnet18",
9 filename="resnet18_cifar100.pth"
10)
11
12# Rebuild the architecture
13model = resnet18(weights=None)
14model.conv1 = nn.Conv2d(3, 64, kernel_size=3, stride=1, padding=1, bias=False)
15model.maxpool = nn.Identity()
16model.fc = nn.Linear(model.fc.in_features, 100)
17
18# Load the weights
19model.load_state_dict(torch.load(resnet_path, map_location="cpu"))
20model.eval()1import torchvision.transforms as transforms
2
3transform = transforms.Compose([
4 transforms.Resize((32, 32)),
5 transforms.ToTensor(),
6 transforms.Normalize((0.5071, 0.4865, 0.4409), (0.2673, 0.2564, 0.2762))
7])1from PIL import Image
2import torch
3
4image = Image.open("image.jpg").convert("RGB")
5input_tensor = transform(image).unsqueeze(0)
6
7with torch.no_grad():
8 output = model(input_tensor)
9 probs = torch.softmax(output, dim=1)[0]
10 top5_prob, top5_idx = torch.topk(probs, 5)
11
12# class names can be obtained via torchvision.datasets.CIFAR100(...).classes
13for i in range(5):
14 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)