Views
No views yet
88.60%Intended uses & limitations
- Intended use: Educational/demo purposes or as a starting point for further fine-tuning on similar image classification tasks.
- Not intended for: Production-critical tasks without further evaluation, as CIFAR-10 is relatively small-scale, and the model may not generalize to non-CIFAR data without additional fine-tuning.
torch.device("cuda")) if available, otherwise CPU.| Epoch | Training Loss | Training Accuracy | Validation Accuracy |
|---|---|---|---|
| 1 | 0.7013 | 76.52% | - |
| 2 | 0.4248 | 85.64% | - |
| 3 | 0.3185 | 89.07% | - |
| 4 | 0.2341 | 92.06% | - |
| 5 | 0.1762 | 93.86% | - |
| 6 | 0.1302 | 95.55% | - |
| 7 | 0.1085 | 96.31% | - |
| 8 | 0.0925 | 96.82% | - |
| 9 | 0.0765 | 97.37% | - |
| 10 | 0.0683 | 97.68% | - |
| 11 | 0.0655 | 97.83% | - |
| 12 | 0.0548 | 98.18% | - |
| 13 | 0.0513 | 98.27% | - |
| 14 | 0.0461 | 98.49% | - |
| 15 | 0.0470 | 98.41% | 88.60% |
Note: Validation accuracy was computed at the end of training (final epoch).
username/model_repo_name with the actual model repo id on Hugging Face.1import torch
2import torch.nn as nn
3from torchvision import models, transforms
4from huggingface_hub import hf_hub_download
5from PIL import Image
6
7# Download the weights from the Hugging Face Hub
8ckpt_path = hf_hub_download(repo_id="username/model_repo_name", filename="cnn_model.pth")
9
10# Define the same model architecture
11model = models.resnet18(pretrained=False)
12model.fc = nn.Linear(model.fc.in_features, 10) # for CIFAR-10
13model.load_state_dict(torch.load(ckpt_path, map_location="cpu"))
14model.eval()
15
16# Define transforms
17transform = transforms.Compose([
18 transforms.Resize((128, 128)),
19 transforms.ToTensor(),
20 transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5)),
21])
22
23# Example inference
24image = Image.open("your_image.jpg").convert("RGB")
25input_tensor = transform(image).unsqueeze(0) # add batch dimension
26with torch.no_grad():
27 logits = model(input_tensor)
28 predicted_class = logits.argmax(dim=1).item()
29
30print("Predicted class ID:", predicted_class)