-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathonnx_pred.py
37 lines (28 loc) · 1.01 KB
/
onnx_pred.py
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
27
28
29
30
31
32
33
34
35
36
37
# -*- coding:utf-8 -*-
# author:平手友梨奈ii
# e-mail:[email protected]
# datetime:1993/12/01
# filename:onnx_pred.py
# software: PyCharm
import onnx
import onnxruntime
from config import get_config
import torch
from PIL import Image
conf = get_config(False)
model = onnx.load('./insight.onnx')
print(onnx.checker.check_model(model))
# print(onnx.helper.printable_graph(model.graph))
face1 = Image.open('test_img/test1_res.jpg')
face2 = Image.open('test_img/test2_res.jpg')
# use onnxruntime to infer
session = onnxruntime.InferenceSession('./insight.onnx')
inputs_name = session.get_inputs()[0].name
print(inputs_name)
outputs_name = session.get_outputs()[0].name
print(outputs_name)
embed1 = session.run([], {'input1': conf.test_transform(face1).to('cpu').unsqueeze(0).numpy()})
# print(embed1)
embed2 = session.run([], {'input1': conf.test_transform(face2).to('cpu').unsqueeze(0).numpy()})
distance = torch.sum(torch.pow(torch.tensor(embed1[0] - embed2[0]), 2))
print(distance)