Views
No views yet
| Feature | Specification |
|---|---|
| Architecture | ResNet-18 (Pretrained on ImageNet, Finetuned on CIFAR-10) |
| Input Size | 32×32 pixels (RGB) |
| Number of Classes | 10 |
| Framework | PyTorch |
| Parameters | ~11 million |
| Training Dataset | CIFAR-10 |
| Baseline Accuracy | ~80% |
airplane ✈️automobile 🚗bird 🐦cat 🐱deer 🦌dog 🐕frog 🐸horse 🐎ship 🚢truck 🚚pip install torch torchvision huggingface_hub pillow requests1import torch
2import torch.nn as nn
3from torchvision import models, transforms
4from huggingface_hub import hf_hub_download
5from PIL import Image
6
7# Configuration
8REPO_ID = "Phoenix21/resnet18-cifar10-baseline"
9FILENAME = "resnet18_cifar10_baseline.pth"
10
11# 1. Initialize model architecture
12model = models.resnet18(pretrained=False)
13model.fc = nn.Linear(model.fc.in_features, 10) # CIFAR-10 has 10 classes
14
15# 2. Download and load weights
16model_path = hf_hub_download(repo_id=REPO_ID, filename=FILENAME)
17model.load_state_dict(torch.load(model_path, map_location=torch.device('cpu')))
18
19# 3. Set to evaluation mode
20model.eval()
21
22# 4. Prepare image transformation
23transform = transforms.Compose([
24 transforms.Resize((32, 32)),
25 transforms.ToTensor(),
26 transforms.Normalize(mean=[0.4914, 0.4822, 0.4465],
27 std=[0.2023, 0.1994, 0.2010]) # CIFAR-10 stats
28])
29
30# 5. Load and preprocess image
31image = Image.open("your_image.jpg").convert("RGB")
32input_tensor = transform(image).unsqueeze(0)
33
34# 6. Make prediction
35with torch.no_grad():
36 output = model(input_tensor)
37 probabilities = torch.nn.functional.softmax(output[0], dim=0)
38
39# 7. Get results
40classes = ['airplane', 'automobile', 'bird', 'cat', 'deer',
41 'dog', 'frog', 'horse', 'ship', 'truck']
42confidence, prediction = torch.max(probabilities, 0)
43print(f"Prediction: {classes[prediction]} ({confidence.item()*100:.2f}%)")1# Example: Applying Gaussian blur to test robustness
2from torchvision.transforms import GaussianBlur
3
4distortion_transform = transforms.Compose([
5 transforms.Resize((32, 32)),
6 GaussianBlur(kernel_size=5, sigma=2.0), # Add distortion
7 transforms.ToTensor(),
8 transforms.Normalize(mean=[0.4914, 0.4822, 0.4465],
9 std=[0.2023, 0.1994, 0.2010])
10])
11
12# Test model with distorted images
13distorted_tensor = distortion_transform(image).unsqueeze(0)
14with torch.no_grad():
15 distorted_output = model(distorted_tensor)| File | Description |
|---|---|
resnet18_cifar10_baseline.pth | Model weights (PyTorch state dict) |
README.md | This documentation file |
config.json | Model configuration (if applicable) |
@misc{resnet18-cifar10-baseline,
author = {VisionDev-Copilot Project},
title = {ResNet-18 CIFAR-10 Baseline Model},
year = {2024},
publisher = {Hugging Face},
url = {https://huggingface.co/Phoenix21/resnet18-cifar10-baseline}
}