mobilenetv3-small / python /example.py
inoryQwQ's picture
Upload python/example.py with huggingface_hub
088c799 verified
Raw
History Blame Contribute Delete
598 Bytes
#!/usr/bin/env python3
"""MobileNetV3-Small classification example."""
import sys, numpy as np
from PIL import Image
from inference import MobileNetV3Classifier
model_path = sys.argv[1] if len(sys.argv) > 1 else "../models/model.axmodel"
image_path = sys.argv[2] if len(sys.argv) > 2 else "../demo/demo.jpg"
img = Image.open(image_path).resize((224, 224))
data = np.array(img, dtype=np.float32).transpose(2, 0, 1)[np.newaxis] / 255.0
clf = MobileNetV3Classifier(model_path)
out = clf.classify(data)
top5 = np.argsort(-out[0])[:5]
print(f"Top-5 classes: {top5}")
print(f"Scores: {out[0][top5]}")