|
请教一下, 我在rknn上面跑yolov3的模型,.我的模型是keras训练的转成tensorflow的pb再转rknn, 没有量化, 跑出来的检测结果与未转
我目前运行在ubuntu18.04下, 输入图像大小640x448, 电脑配置是跑一次需要7~8分钟.
我有没有哪个环节弄错了? 代码如下:
if __name__ == '__main__':
os.chdir("./examples/bamboo")
print(os.getcwd())
# Create RKNN object
rknn = RKNN()
# Config for Model Input PreProcess
rknn.config(channel_mean_value='0 0 0 255', reorder_channel='0 1 2')
# Load TensorFlow Model
# print('--> Loading model')
# rknn.load_tensorflow(tf_pb='./frozen_model.pb',
# inputs=['input_1'],
# outputs=['conv2d_59/BiasAdd', 'conv2d_67/BiasAdd', 'conv2d_75/BiasAdd'],
# input_size_list=[[INPUT_HEIGHT, INPUT_WIDTH, 3]])
# print('done')
# # Build Model
# print('--> Building model')
# rknn.build(do_quantization=False, dataset='./dataset.txt')
# print('done')
# # Export RKNN Model
# rknn.export_rknn('./yolov3.rknn')
# # Direct Load RKNN Model
rknn.load_rknn('./yolov3.rknn')
# init runtime environment
print('--> Init runtime environment')
ret = rknn.init_runtime()
if ret != 0:
print('Init runtime environment failed')
exit(ret)
print('done')
# Set inputs
input_path = './test/CHANGTING/201911'
output_path = './test/CHANGTING/201911/Results-iv19-rknn'
if not os.path.exists(output_path):
os.makedirs(output_path)
for subdir, dirs, files in os.walk(input_path):
dirname = subdir.split('/')[-1]
if dirname == 'Annotations':
continue
for basename in files:
filename = os.path.join(subdir, basename)
print(filename)
src = cv2.imread(filename)
if src is None:
print("load image failed")
continue
img = cv2.cvtColor(src, cv2.COLOR_BGR2RGB)
img = cv2.resize(img, (INPUT_HEIGHT, INPUT_WIDTH), interpolation=cv2.INTER_CUBIC)
# Inference
#print('--> Running model')
outputs = rknn.inference(inputs=[img])
#print('done')
input0_data = outputs[0]
input1_data = outputs[1]
input2_data = outputs[2]
# input0_data = np.load('output0.npy')
# input1_data = np.load('output1.npy')
# input2_data = np.load('output2.npy')
outputs = [input0_data, input1_data, input2_data]
anchors = [[28,14], [31,54], [61,22], [95,8], [133,20], [191,40], [246,10], [441,19], [573,61]]
anchors = np.array(anchors)
boxes, scores, classes = yolo_eval(outputs, anchors, 12, np.array([448, 640]), 20, 0.3, 0.5)
if boxes is not None:
draw(src, boxes, scores, classes, [448, 640])
out_name = os.path.join(output_path, basename)
cv2.imwrite(out_name, src)
# cv2.imshow("results", orig_img)
# cv2.waitKeyEx(0)
rknn.release()
|
|