File size: 827 Bytes
7f44fbd
 
 
 
df7a0c9
7f44fbd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from transformers import MobileNetV2FeatureExtractor, MobileNetV2ForImageClassification
from PIL import Image

# Replace with the path to the directory containing the model files
model_folder = "mobilnetV2_ftprecmodelshuf.weights.best.hdf5"

# Load the feature extractor
feature_extractor = MobileNetV2FeatureExtractor.from_pretrained(model_folder)

# Load the model
model = MobileNetV2ForImageClassification.from_pretrained(model_folder)

# Load the image
image = Image.open("/path/to/your/image.jpg")

# Preprocess the image
inputs = feature_extractor(images=image, return_tensors="pt")

# Make predictions
outputs = model(**inputs)
logits = outputs.logits

# Model predicts one of the 1000 ImageNet classes
predicted_class_idx = logits.argmax(-1).item()
print("Predicted class:", model.config.id2label[predicted_class_idx])