|
我在PC Ubuntu 16.04 上接了2个1808计算棒,预想是让它们同时处理2张图片,但是通过输出的日志来看,感觉是串行并不是并行的。有没有人做过相关的设计的,可以一起探讨下。
下面是我的测试代码,其实就是例程mobilenet_v1稍微改写了一点:
- import numpy as np
- import cv2
- import time
- from multiprocessing import Process
- from rknn.api import RKNN
- def get_time_stamp():
- ct = time.time()
- local_time = time.localtime(ct)
- data_head = time.strftime("%Y-%m-%d %H:%M:%S", local_time)
- data_secs = (ct - int(ct)) * 1000
- time_stamp = "%s.%03d" % (data_head, data_secs)
- return time_stamp
- def show_outputs(outputs):
- output = outputs[0][0]
- output_sorted = sorted(output, reverse=True)
- top5_str = 'mobilenet_v1\n-----TOP 5-----\n'
- for i in range(5):
- value = output_sorted[i]
- index = np.where(output == value)
- for j in range(len(index)):
- if (i + j) >= 5:
- break
- if value > 0:
- topi = '{}: {}\n'.format(index[j], value)
- else:
- topi = '-1: 0.0\n'
- top5_str += topi
- print(top5_str)
- def show_perfs(perfs):
- perfs = 'perfs: {}\n'.format(outputs)
- print(perfs)
- def infer_rknn(img_name, device_id):
- rknn = RKNN()
-
- # pre-process config
- print('--> config model')
- rknn.config(channel_mean_value='103.94 116.78 123.68 58.82', reorder_channel='0 1 2')
- print('done')
- rknn.load_rknn('./mobilenet_v1.rknn')
- ret = rknn.init_runtime(target='rk1808', device_id = device_id )
- if ret != 0:
- print('Init runtime environment failed')
- exit(ret)
-
- img = cv2.imread(img_name)
- img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
-
- print(device_id + '--> Running model')
- smp = get_time_stamp()
- print(device_id +':'+ smp)
-
- outputs = rknn.inference(inputs=[img])
- show_outputs(outputs)
-
- smp = get_time_stamp()
- print(device_id +':'+ smp)
-
- if __name__ == '__main__':
- p_infer1 = Process(target=infer_rknn, args=('dog1.jpg', 'TS018080190600023'))
- p_infer2 = Process(target=infer_rknn, args=('dog2.jpg', 'TS018080190600068'))
-
- p_infer1.start()
- p_infer2.start()
结果显示:
TS018080190600068--> Running model
TS018080190600068:2019-08-14 15:47:26.514
mobilenet_v1
-----TOP 5-----
[156]: 0.8837890625
[155]: 0.0677490234375
[188 205]: 0.00867462158203125
[188 205]: 0.00867462158203125
[263]: 0.0057525634765625
TS018080190600068:2019-08-14 15:47:26.592
TS018080190600023--> Running model
TS018080190600023:2019-08-14 15:47:26.819
mobilenet_v1
-----TOP 5-----
[156]: 0.8837890625
[155]: 0.0677490234375
[188 205]: 0.00867462158203125
[188 205]: 0.00867462158203125
[263]: 0.0057525634765625
TS018080190600023:2019-08-14 15:47:26.885
如果按预期的话,编号23和68的计算棒应该是差不过同步的吧?但实际显示在推理这边还是按先后顺序来的,是我的测试方法有问题还是?
|
|