forked from VeriSilicon/tflite-vx-delegate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_model.py
33 lines (28 loc) · 995 Bytes
/
run_model.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
import utils
import argparse
import numpy as np
## test given model with random input
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument(
'-m',
'--model',
default="/tmp/mobilenet_v1_1.0_224_quant.tflite",
help = 'model to be compared'
)
parser.add_argument(
'-e',
'--ext_delegate',
help='external_delegate_library path'
)
args = parser.parse_args()
cpu_runner = utils.cpu()
(gold_input, gold_output) = cpu_runner.run_with_rand_data(args.model)
npu_runner = utils.npu(args.ext_delegate)
npu_output = npu_runner.run(args.model, gold_input)
idx = 0
for (gold, npu) in zip(gold_output, npu_output):
np.savetxt("/tmp/gold_{}".format(idx), gold.flatten())
np.savetxt("/tmp/npu_{}".format(idx), npu[1].flatten())
print("[{}]cosine_similarity = ".format(idx), utils.cosine_similarity(gold.flatten(), npu[1].flatten()))
idx = idx + 1