Toybrick

标题: Could not load rknn model [打印本页]

作者: nvnn    时间: 2020-2-24 16:27
标题: Could not load rknn model
Dear admin,
I have a tensorflow model, I can convert it into rknn. However, I could not load that rknn model to run inferene.
The converting code is:
  1. from rknn.api import RKNN

  2. if __name__ == '__main__':

  3.   rknn = RKNN(verbose = True)
  4.   rknn.load_tensorflow(tf_pb='model1.pb',
  5.                         inputs=['input_1'],
  6.                         outputs=['conv2d_24/Sigmoid'],
  7.                         input_size_list=[[256, 256, 1]])
  8.   # rknn.config(channel_mean_value='0 0 0 255', reorder_channel='0 1 2')
  9.   rknn.config(channel_mean_value='0 255', reorder_channel='0 1 2')
  10.   
  11.   rknn.build(do_quantization=True, dataset='./dataset.txt')
  12.   #rknn.export_rknn('./mobilenet-ssd-8.rknn')
  13.   rknn.export_rknn('unet_tf.rknn')
  14.   exit(0)
复制代码
and the loading rknn model and run inference is:
  1. from rknn.api import RKNN
  2. import cv2
  3. if __name__ == '__main__':

  4.   rknn = RKNN(verbose = True)
  5.   print('-->loading model')
  6.   rknn.load_rknn('./unet_tf.rknn')
  7.   #rknn.load_rknn('./yolov3.rknn')
  8.   print('loading model done')

  9.   print('--> Init runtime environment')
  10.   ret = rknn.init_runtime()
  11.   if ret != 0:
  12.           print('Init runtime environment failed')
  13.           exit(ret)
  14.   print('done')
  15.   image = cv2.imread('0test.png')
  16.   print(image.shape)
  17.   gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
  18.   gray = cv2.resize(gray, (256,256))
  19.   out_boxes2 = rknn.inference(inputs=[gray])
  20.   print(out_boxes2)
复制代码
The error is:
  1. D [print_tensor:136]out(0): id[  85] vtl[1] const[0] shape[ 31, 31, 512, 1   ] fmt[u8 ] qnt[ASM zp=  0, scale=0.015807]
  2. D [setup_node:368]Setup node id[28] uid[48] op[CONCAT]
  3. E [op_check:321]Concat input dims size(31 vs 32)
  4. E [setup_node:383]Check node[28] CONCAT fail
  5. I [remove_client_ops:4942]remove_client_ops num=0
  6. I [remove_client_ops:4953]remove_client_ops finish
  7. Create RKNN model fail!
  8. E Catch exception when init runtime!
  9. E Traceback (most recent call last):
  10. E   File "rknn/api/rknn_base.py", line 988, in rknn.api.rknn_base.RKNNBase.init_runtime
  11. E   File "rknn/api/rknn_runtime.py", line 320, in rknn.api.rknn_runtime.RKNNRuntime.build_graph
  12. E Exception: RKNN init failed. error code: RKNN_ERR_MODEL_INVALID
  13. Init runtime environment failed
复制代码
Clearly, the error is shape missmatched. But why I don't have this error in my tensorflow model? I can run inference normally with my tf model but but not rknn.
The code and models are here:
https://drive.google.com/file/d/ ... JM/view?usp=sharing
Please have a look and give me suggestion. Thanks

作者: nvnn    时间: 2020-2-26 08:27
本帖最后由 nvnn 于 2020-2-26 14:27 编辑
hisping 发表于 2020-2-24 18:01
you expect a single channel when transform model,but you input three channels picture  when runnin ...
[update] SOLVED!!

Thanks for your reply. From my inference code, I already convert the input into grayscale image, so it should be a single channel input. Please clarify more if I have any mistake.
I've done another experiment that use 3 channels input and is the error still the same. My guess is that the deconvolution layer is not converted correctly in rknn. it misses 1 pixel when using decovolution layer?





欢迎光临 Toybrick (https://t.rock-chips.com/) Powered by Discuz! X3.3