mohitsha's picture
mohitsha HF staff
Upload 2 files
c02e4ab verified
raw
history blame contribute delete
938 Bytes
import requests
from PIL import Image
from optimum.amd.ryzenai import RyzenAIModelForImageClassification
from transformers import AutoFeatureExtractor, pipeline
url = "http://images.cocodataset.org/val2017/000000039769.jpg"
image = Image.open(requests.get(url, stream=True).raw)
quantized_model_path = "mohitsha/transformers-resnet18-onnx-quantized-ryzen"
# The path and name of the runtime configuration file. A default version of this file can be
# found in the voe-4.0-win_​amd64 folder of the Ryzen AI software installation package under
# the name vaip_​config.json
vaip_config = ".\\vaip_config.json"
model = RyzenAIModelForImageClassification.from_pretrained(quantized_model_path, vaip_config=vaip_config)
feature_extractor = AutoFeatureExtractor.from_pretrained(quantized_model_path)
cls_pipe = pipeline("image-classification", model=model, feature_extractor=feature_extractor)
outputs = cls_pipe(image)
print(outputs)