metadata
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:
- Beagle
- Chihuahua
- Corgi
- Dalmation
- Doberman
- Golden Retriever
- Maltese
- Poodle
- Shiba Inu
- 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.
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.
# 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()}")