Alexnet Jajanan Tradisional Classifier
This model is using pretrained Alexnet architecture from Pytorch and finetuned using Jajanan Tradisional Image from https://www.kaggle.com/datasets/nizamkurniawan/jajanan-tradisional-jawa-tengah
Model Details
Model Description
The model will detects the food name base on 6 labels given dataset for training. The labels are:
grontol
lanting
lumpia
putu ayu
serabi solo
wajik
Developed by: Ganda
Model type: Image Classification
License: GPL
How to Use the Model
import torch
import torchvision.models as models
import requests
from PIL import Image
from torchvision import transforms
import io
import torch.nn.functional as F
# Load the model architecture (Alexnet)
model = models.alexnet(weights=models.AlexNet_Weights.DEFAULT)
in_features = model.classifier[6].in_features
model.classifier[6] = nn.Linear(in_features, num_classes)
# Load the saved model weights
model_weights_path = './alexnet_jajanan_tradisional_classifier.pth'
model.load_state_dict(torch.load(model_weights_path))
# Put the model in evaluation mode
model.eval()
# URL of the image you want to classify
# image_url = 'https://thumbs.dreamstime.com/z/grontol-jagung-white-background-traditional-snacks-indonesia-boiled-shelled-corn-sprinkled-grated-coconut-176198473.jpg' # grontol
image_url = 'https://cdn1-production-images-kly.akamaized.net/vU-SI-sZB6d0igbNAbDHpf2xNe0=/1x483:1080x1091/1200x675/filters:quality(75):strip_icc():format(png)/kly-media-production/medias/4128409/original/068380200_1660826281-Putu_Ayu_____Jawa_Tengah.jpg' #putu ayu
response = requests.get(image_url)
if response.status_code == 200:
# Open the downloaded image with PIL
img = Image.open(io.BytesIO(response.content))
else:
print('Failed to download the image.')
transform = transforms.Compose([
transforms.Resize((200, 200)), # Resize to 200x200
transforms.ToTensor(), # Convert to Tensor
transforms.Normalize(mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5]) # Normalize
])
input_data = transform(img).unsqueeze(0) # Add a batch dimension
class_to_label = {0: 'grontol', 1: 'lanting', 2: 'lumpia', 3: 'putu ayu', 4: 'serabi solo', 5: 'wajik'}
with torch.no_grad():
output = model(input_data)
# Get the predicted class label
probabilities = F.softmax(output, dim=1)
# Get the predicted class and its confidence
predicted_class = torch.argmax(probabilities, dim=1).item()
confidence = probabilities[0, predicted_class].item() * 100 # Convert to percentage
# Print the predicted class
print('Predicted Class:', predicted_class)
print('Predicted Label:', class_to_label[predicted_class])
print(f'Confidence: {confidence:.2f}%')
Inference Providers
NEW
This model isn't deployed by any Inference Provider.
๐
Ask for provider support