-
-
Save LoipesMas/d7258a3d009e9b06c3684d77e341251b to your computer and use it in GitHub Desktop.
Inference in python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PIL import Image | |
import numpy as np | |
import onnxruntime as rt | |
session = rt.InferenceSession("./squeezenet1.0-13-qdq.onnx") | |
with open("path/to/image.png", "rb") as f: | |
image = Image.open(f) | |
frame = image.convert(mode="RGBA") | |
frame = np.array(frame) | |
frame = np.transpose(frame, (2, 0, 1)) | |
frame = frame[:3, 100:324, 100:324] | |
frame = np.expand_dims(frame, 0) | |
frame = frame.astype(np.float32) / 255.0 | |
print(f"{frame.shape=}") | |
print(f"{frame[0, :, 100, 100]=}") | |
print(f"{frame[0, :, 180, 50]=}") | |
scores = session.run( | |
["softmaxout_1"], | |
{"data_0": frame}, | |
) | |
scores = scores[0] | |
max_score = np.max(scores) | |
print(f"{max_score=}") | |
print(f"{np.where(scores >= max_score)=}") | |
print(f"{scores[0][322]=}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment