Views
No views yet
1{
2 "model_name": "resnet34",
3 "dropout_rate": 0.4682019316470914,
4 "learning_rate": 0.00027817005315620047,
5 "weight_decay": 1.4677013775851028e-05,
6 "batch_size": 2
7}1import torch
2import torch.nn as nn
3from PIL import Image
4import torchvision.transforms as transforms
5import torchvision.models as models
6
7# Load model (define TransferLearningModel class first)
8model = TransferLearningModel(num_classes=4, dropout_rate=0.4682019316470914, model_name='resnet34')
9model.load_state_dict(torch.load('pytorch_model.bin'))
10model.eval()
11
12# Preprocess image
13transform = transforms.Compose([
14 transforms.Resize((224, 224)),
15 transforms.ToTensor(),
16 transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
17])
18
19# Load and preprocess image
20image = Image.open('cheese_image.jpg').convert('RGB')
21input_tensor = transform(image).unsqueeze(0)
22
23# Make prediction
24with torch.no_grad():
25 output = model(input_tensor)
26 probabilities = torch.softmax(output, dim=1)
27 predicted_class = torch.argmax(probabilities, dim=1).item()
28
29class_names = ["Low Texture", "Medium-Low Texture", "Medium-High Texture", "High Texture"]
30print(f"Predicted class: {class_names[predicted_class]}")1@model{rlogh/cheese-texture-classifier-automl,
2 title={Cheese Texture Classifier (AutoML)},
3 author={Rumi Loghmani},
4 year={2024},
5 url={https://huggingface.co/rlogh/cheese-texture-classifier-automl}
6}1@dataset{aslan-ng/cheese-image,
2 title={Cheese Image Dataset},
3 author={Aslan Noorghasemi},
4 year={2024},
5 url={https://huggingface.co/datasets/aslan-ng/cheese-image}
6}