File size: 3,095 Bytes
4ac1e80
 
 
 
 
 
 
 
 
 
 
 
9fa9e57
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4ac1e80
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
---
metrics:
- accuracy
pipeline_tag: image-classification
tags:
- dog
- breed
- AlexNet
- cnn
- image
- classification
---

# Dog Breeds Classifier (AlexNet Fine-tuned Model)

## Model Description
This is a fine-tuned version of the **AlexNet** model, designed to classify images into one of 10 different dog breeds. The original AlexNet architecture was pre-trained on the ImageNet dataset, and this version has been specifically adapted to classify dog breeds based on a custom dataset containing images of various dogs.

## Model Details
### Architecture
- **Base Model**: AlexNet
- **Final Layer**: The final fully connected layer has been modified to classify 10 dog breeds.
  - Input to the last fully connected layer: 4096 features
  - Output: 10 classes (one for each breed)
  
### Dataset
The dataset used for fine-tuning consists of images of 10 different dog breeds, organized into training, validation, and test sets.

#### Dog Breeds Included:
1. Beagle
2. Chihuahua
3. Corgi
4. Dalmation
5. Doberman
6. Golden Retriever
7. Maltese
8. Poodle
9. Shiba Inu
10. Siberian Husky

#### Data Format
- **Image Format**: JPG
- **Resolution**: The images were resized to 227x227 pixels to match AlexNet’s input requirements.
- **Dataset Structure**:
  - `train/`: Contains the training images of dog breeds.
  - `valid/`: Contains the validation images of dog breeds.
  - `test/`: Contains the test images of dog breeds.

#### Source:
The dataset was obtained from Kaggle. You can access it [here](https://www.kaggle.com/datasets/gpiosenka/70-dog-breedsimage-data-set/data?select=dogs.csv).

## Training
The AlexNet model was fine-tuned using the following setup:
- **Optimizer**: SGD
- **Learning Rate**: 0.001
- **Momentum**: 0.9
- **Loss Function**: CrossEntropyLoss
- **Training Epochs**: 10
- **Batch Size**: 32

## Usage
You can load and use this model for inference by following the code snippet below.

```python
# Install Required Libraries
pip install torch torchvision huggingface_hub

import torch
import torch.nn as nn
from torchvision import models
from huggingface_hub import hf_hub_download

# Load the fine-tuned AlexNet model
model = models.alexnet(pretrained=False)
num_features = model.classifier[6].in_features
model.classifier[6] = nn.Linear(num_features, 10)

# Download model weights from Hugging Face Hub
model_path = hf_hub_download(repo_id="pramudyalyza/dog-breeds-alexnet", filename="alexnet_model.bin")

# Load the model state
model.load_state_dict(torch.load(model_path))
model.eval()

# Example inference
from PIL import Image
from torchvision import transforms

# Define transformation
transform = transforms.Compose([
    transforms.Resize((227, 227)),
    transforms.ToTensor(),
    transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
])

# Load and preprocess an example image
image = Image.open("path_to_image.jpg")
image = transform(image).unsqueeze(0)

# Perform inference
with torch.no_grad():
    output = model(image)
    predicted_class = output.argmax(dim=1)
    print(f"Predicted Dog Breed: {predicted_class.item()}")
```