-
Notifications
You must be signed in to change notification settings - Fork 0
/
classify_vino.py
35 lines (32 loc) · 1.37 KB
/
classify_vino.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
from DNet import DNet
from utils import load_yaml
from torchsummary import summary
from dataset import ModelNetDataSet
from torch.utils.data import DataLoader
from openvino.runtime import Core
import numpy as np
import time
if __name__ == '__main__':
conf = load_yaml('config/deform.yaml')
# print(conf)
onnx_path = f'{conf["checkpoint"]}/model_nfeatures{conf["num_features"]}_ckpnt_{conf["epochs"]}.onnx'
eval_loader = DataLoader(dataset=ModelNetDataSet(conf, mode="test"), batch_size= 1)
nfeatures = 6 if conf['use_normal_vector'] else 3
npoints = conf['npoints']
ie = Core()
onnx_model = ie.read_model(model=onnx_path)
compiled_model = ie.compile_model(model=onnx_model, device_name="CPU")
output_layer = compiled_model.output(0)
print(f'Load ONNX: {onnx_path}')
i = 0
for points, target in eval_loader:
points = points.transpose(2, 1)
points = points.detach().numpy()
t1 = time.time()
onnx_pred = compiled_model([points])[output_layer]
t2 = time.time()
onxx_cls = np.argmax(onnx_pred, axis=1)
print("%03d" %(i+1), ': onnx cls = ', onxx_cls[0], ', target = ', target[0].item(), '. Inference time: %2.2f ms' %((t2-t1)*1000))
i += 1
if i >= 20:
break