forked from SharpAI/DeepCamera
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy2.py
More file actions
58 lines (44 loc) · 1.39 KB
/
Copy pathdeploy2.py
File metadata and controls
58 lines (44 loc) · 1.39 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import cv2
import tvm
import numpy as np
import time
from tvm.contrib import rpc, util, graph_runtime
# tvm module for compiled functions.
loaded_lib = tvm.module.load('../../model/net2.tar')
# json graph
loaded_json = open("../../model/net2").read()
# parameters in binary
loaded_params = bytearray(open("../../model/net2.params", "rb").read())
ctx = tvm.cl(0)
mod = graph_runtime.create(loaded_json, loaded_lib, ctx)
mod.load_params(loaded_params)
a = np.random.uniform(size=(1,3,112,112)).astype('float32')
print("first run, need calc graph")
start = time.time()
mod.run(data=a)
done = time.time()
print('cost {}'.format(done-start))
start = time.time()
for i in range (1,1000000):
a = np.random.uniform(size=(1,3,112,112)).astype('float32')
step_start = time.time()
mod.run(data=a)
step_end = time.time()
print('step {} cost {}'.format(i,(step_end - step_start)))
done = time.time()
print('everage {}'.format((done - start)/1000000))
out = mod.get_output(0, tvm.nd.empty((512,)))
print(out)
#for i in range(0,100):
#set_input, get_output, run = gmodule["set_input"], gmodule["get_output"], gmodule["run"]
#gmodule["load_params"](loaded_params)
#set_input("x", tvm.nd.array(x_np))
#run()
exit(0)
ctx = tvm.gpu(0)
gmodule = fcreate(loaded_json, loaded_lib, ctx.device_type, ctx.device_id)
#set_input("x", tvm.nd.array(x_np))
#run()
#out = tvm.nd.empty(shape)
#get_output(0, out)
#print(out.asnumpy())