billahaiml commited on
Commit
f2f38ab
·
verified ·
1 Parent(s): 49e1d6f

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +70 -0
README.md ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ tags:
4
+ - image-classification
5
+ - pytorch
6
+ - resnet18
7
+ - transfer-learning
8
+ - computer-vision
9
+ pipeline_tag: image-classification
10
+ ---
11
+
12
+ # Cat vs Dog Classifier (ResNet18 Transfer Learning)
13
+
14
+ This model is a fine-tuned **ResNet18** for binary image classification: **cat** vs **dog**.
15
+
16
+ ## Model Details
17
+
18
+ - **Base model:** ResNet18 (pretrained on ImageNet)
19
+ - **Framework:** PyTorch
20
+ - **Task:** Binary image classification (cat, dog)
21
+ - **Input size:** 128x128 RGB images
22
+ - **Training method:**
23
+ 1. Feature extraction — froze all layers except the final fully connected layer, trained for 5 epochs.
24
+ 2. Fine-tuning — unfroze `layer4` of ResNet18 and trained further with a lower learning rate for 5 epochs.
25
+
26
+ ## Dataset
27
+
28
+ Trained on a small subset of **CIFAR-10** (cat and dog classes only), with 100 images per class for training and 50 images per class for testing.
29
+
30
+ ## How to Use
31
+
32
+ ```python
33
+ import torch
34
+ import torch.nn as nn
35
+ from torchvision import models, transforms
36
+ from huggingface_hub import hf_hub_download
37
+ from PIL import Image
38
+
39
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
40
+ class_names = {0: "cat", 1: "dog"}
41
+
42
+ transform = transforms.Compose([
43
+ transforms.Resize((128, 128)),
44
+ transforms.ToTensor(),
45
+ transforms.Normalize(mean=[0.485, 0.456, 0.406],
46
+ std=[0.229, 0.224, 0.225]),
47
+ ])
48
+
49
+ weights_path = hf_hub_download(repo_id="billahaiml/cat-dog-resnet18", filename="cat_dog_resnet18.pth")
50
+
51
+ model = models.resnet18(weights=None)
52
+ model.fc = nn.Linear(model.fc.in_features, 2)
53
+ model.load_state_dict(torch.load(weights_path, map_location=device))
54
+ model = model.to(device)
55
+ model.eval()
56
+
57
+ img = Image.open("your_image.jpg").convert("RGB")
58
+ img_tensor = transform(img).unsqueeze(0).to(device)
59
+
60
+ with torch.no_grad():
61
+ output = model(img_tensor)
62
+ probs = torch.softmax(output, dim=1)[0]
63
+ pred = class_names[torch.argmax(probs).item()]
64
+
65
+ print(f"Prediction: {pred}")
66
+ ```
67
+
68
+ ## Limitations
69
+
70
+ This model was trained on a very small dataset (100 images per class), so it is intended for educational/demo purposes rather than production use.