Downloads · 30 days
0
pramudyalyza/dog-breeds-alexnet
dog-breeds-alexnet is a image classification model from pramudyalyza. Use it when you need a label for an image.
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…
Downloads · 30 days
0
Access
Public
Updated Sep 19, 2024
Repo size
228 MB
Likes
0
Public
Click a slice to open those files.
.bin228 MB · 100%
From the Hugging Face model README
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.
The dataset used for fine-tuning consists of images of 10 different dog breeds, organized into training, validation, and test sets.
train/: Contains the training images of dog breeds.valid/: Contains the validation images of dog breeds.test/: Contains the test images of dog breeds.The dataset was obtained from Kaggle. You can access it here.
The AlexNet model was fine-tuned using the following setup:
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()}")