Toybrick

标题: 模型转化失败,非量化时模型可以转成功,量化时失败 [打印本页]

作者: liuwenhua    时间: 2020-8-17 14:28
标题: 模型转化失败,非量化时模型可以转成功,量化时失败
本帖最后由 liuwenhua 于 2020-8-17 14:29 编辑

模型转化时,量化未开启时,可以转成功,量化开启开启时。报错如下:
E   [Previous line repeated 4 more times]
E   File "rknn\base\RKNNlib\RKNNnetbuilder.py", line 331, in rknn.base.RKNNlib.RKNNnetbuilder.RKNNNetBuilder.build_layer
E   File "rknn\base\RKNNlib\RKNNnetbuilder.py", line 336, in rknn.base.RKNNlib.RKNNnetbuilder.RKNNNetBuilder.build_layer
E   File "rknn\base\RKNNlib\layer\RKNNlayer.py", line 287, in rknn.base.RKNNlib.layer.RKNNlayer.RKNNLayer.compute_tensor
E   File "rknn\base\RKNNlib\layer\reshapelayer.py", line 139, in rknn.base.RKNNlib.layer.reshapelayer.Reshape.compute_out_tensor
E   File "E:\usb_test\example\rknn_win_env\lib\site-packages\tensorflow\python\ops\gen_array_ops.py", line 7546, in reshape
E     "Reshape", tensor=tensor, shape=shape, name=name)
E   File "E:\usb_test\example\rknn_win_env\lib\site-packages\tensorflow\python\framework\op_def_library.py", line 787, in _apply_op_helper
E     op_def=op_def)
E   File "E:\usb_test\example\rknn_win_env\lib\site-packages\tensorflow\python\util\deprecation.py", line 488, in new_func
E     return func(*args, **kwargs)
E   File "E:\usb_test\example\rknn_win_env\lib\site-packages\tensorflow\python\framework\ops.py", line 3272, in create_op
E     op_def=op_def)
E   File "E:\usb_test\example\rknn_win_env\lib\site-packages\tensorflow\python\framework\ops.py", line 1790, in __init__
E     control_input_ops)
E   File "E:\usb_test\example\rknn_win_env\lib\site-packages\tensorflow\python\framework\ops.py", line 1629, in _create_c_op
E     raise ValueError(str(e))
E ValueError: Cannot reshape a tensor with 4096 elements to shape [1,2048] (2048 elements) for 'Reshape_510_5/Reshape_510_5' (op: 'Reshape') with input shapes: [2,2048,1,1], [2] and with input tensors computed as partial shapes: input[1] = [1,2048].
Build model failed!

运行代买如下

from rknn.api import RKNN
import cv2
import time
import numpy as np

if __name__ == '__main__':

    # Create RKNN object
    rknn = RKNN(verbose=True)
    rknn.config(channel_mean_value='0 0 0 1', reorder_channel='0 1 2',batch_size = 1)
    print('done')

    # Load tensorflow model
    ret = rknn.load_onnx(model = './model_embding_gpu_1.1.0.onnx')
    if ret != 0:
        print('Load model failed!')
        exit(ret)
    print('done')

    # Build model
    print('--> Building model')

    #ret = rknn.build(do_quantization=False)
    ret = rknn.build(do_quantization=True, dataset='./dataset.txt')
    if ret != 0:
        print('Build model failed!')
        exit(ret)
    print('done')
    # Export rknn model
    print('--> Export RKNN model')
    ret = rknn.export_rknn('./person_reid_quantization.rknn')
    if ret != 0:
        print('Export model failed!')
        exit(ret)
    print('done')

    rknn.release()






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