Skip to content

您好,我想咨询一下,onnx转rknn后,为什么输入层的误差这么大,是我的预处理出错了吗 #23

Open
@z5013

Description

@z5013
layer_name                                      simulator_error                             runtime_error                      
                                            entire              single                  entire           single_sim            
                                         cos      euc        cos      euc            cos      euc        cos      euc          
-----------------------------------------------------------------------------------------------------------------------
[Input] images                         1.00000 | 0.0       1.00000 | 0.0           1.00000 | 404.33    1.00000 | 404.33        
[exDataConvert] images_int8            1.00000 | 0.1896    1.00000 | 0.1896        
[Conv] 131                             
[Relu] 89                              0.99978 | 3.5098    0.99978 | 3.5098        0.99978 | 3.5098    1.00000 | 0.0           
[Conv] 134                             
[Relu] 92                              0.99868 | 4.9987    0.99868 | 4.9987        0.99868 | 4.9987    1.00000 | 0.0           
[Conv] 137                             
[Relu] 95                              0.99526 | 9.9630    0.99656 | 8.6235        0.99526 | 9.9630    1.00000 | 0.0           
[Conv] 140                             
[Relu] 98                              0.99744 | 16.443    0.99969 | 5.5234        0.99744 | 16.443    1.00000 | 0.0           
[MaxPool] 99                           0.99756 | 8.3143    0.99994 | 1.2698        0.99756 | 8.3143    1.00000 | 0.0           
[Conv] 143                             
[Relu] 102                             0.99548 | 10.145    0.99983 | 2.0447        0.99548 | 10.145    1.00000 | 0.0           
[Conv] 146                             
[Relu] 105                             0.99713 | 9.8246    0.99987 | 2.1592        0.99713 | 9.8251    1.00000 | 0.2776        
[MaxPool] 106                          0.99711 | 5.4939    0.99995 | 0.7312        0.99712 | 5.4886    1.00000 | 0.0           
[Conv] 149                             
[Relu] 109                             0.99741 | 4.4895    0.99988 | 0.9680        0.99743 | 4.4667    1.00000 | 0.0           
[Conv] 152                             
[Relu] 112                             0.99241 | 2.7811    0.99974 | 0.5176        0.99240 | 2.7846    1.00000 | 0.0220        
[MaxPool] 113                          0.99367 | 1.7026    0.99992 | 0.1912        0.99380 | 1.6843    1.00000 | 0.0           
[Conv] 155                             
[Relu] 116                             0.99738 | 1.7186    0.99986 | 0.3834        0.99746 | 1.6965    1.00000 | 0.0374        
[Conv] 158                             
[Relu] 119                             0.99299 | 4.1908    0.99943 | 1.1924        0.99366 | 3.9831    1.00000 | 0.0           
[Conv] 161                             
[Relu] 122                             0.99960 | 0.3034    0.99997 | 0.0780        0.99963 | 0.2924    1.00000 | 0.0           
[Conv] 164                             0.99473 | 1.5335    0.99968 | 0.4397        0.99376 | 1.6592    1.00000 | 0.0           
[Conv] GlobalAveragePool_26_2conv0     0.99647 | 0.8139    0.99995 | 0.1021        0.99544 | 0.9055    1.00000 | 0.0           
[Conv] 125                             0.99680 | 0.2554    0.99999 | 0.0173        0.99576 | 0.2870    1.00000 | 0.0           
[Reshape] output_2_int8                0.99680 | 0.2554    0.99999 | 0.0124        
[exDataConvert] output_2               0.99680 | 0.2554    0.99999 | 0.0124        0.99576 | 0.2870    1.00000 | 0.0           
[MaxPool] 127                          0.99575 | 3.0204    0.99987 | 0.5405        0.99618 | 2.8607    1.00000 | 0.0           
[Conv] 128                             0.99839 | 15.575    0.99934 | 9.9484        0.99846 | 15.255    1.00000 | 0.0           
[Transpose] output_1-rs                0.99839 | 15.575    0.99937 | 9.7783        0.99846 | 15.255    1.00000 | 0.0           
[Reshape] output_1_int8                0.99839 | 15.575    0.99937 | 9.7783        
[exDataConvert] output_1               0.99839 | 15.575    0.99937 | 9.7783        0.99846 | 15.255    1.00000 | 0.0           
I The error analysis results save to: snapshot/error_analysis.txt

这是我的量化分析代码

from rknn.api import RKNN
import cv2
mean_values=[[255*0.588]]
std_values=[[255*0.193]]

if __name__ == '__main__':
    # 第一步:创建RKNN对象
    rknn = RKNN(verbose=True)
 
    # 第二步:配置RKNN对象参数
    rknn.config(
        mean_values=[[255*0.588,255*0.588,255*0.588]],
        std_values=[[255*0.193,255*0.193,255*0.193]],
        target_platform='rv1106',
        quantized_algorithm='normal',
        quantized_dtype='w8a8',
        optimization_level=0,
      
        # 其余参数保持默认即可
    )
 
    # 第三步:调用load_pytorch接口导入pt模型
    rknn.load_onnx(model='./utils/plate_recognition_color.onnx',input_size_list=[[1, 3, 48, 168]])
 
    # 第四步:调用build接口构建RKNN模型
    rknn.build(
        do_quantization=True, # 表示开启rknn模型量化
        dataset='./utils/dataset.txt', # 量化所用到的数据集

    )
 
    # 导出rknn模型
    rknn.export_rknn(export_path='./resnet.rknn')
    img = './data/9-沪GCLE7G.jpg'
    img = cv2.imread(img)
    img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
    img = cv2.resize(img, (168, 48), interpolation=cv2.INTER_CUBIC)
    img = img.transpose(2, 0, 1)
    img = img.reshape(1, 3, 48, 168)
    # 第五步:使用accuracy_analysis 接口进行模型量化精度分析
    rknn.accuracy_analysis(
        inputs=[img], # 表示进行推理的图像
        output_dir='snapshot', # 表示精度分析的输出目录
        target='rv1106', # 默认为None,表示运行在模拟器上
        device_id='10.1.1.144:5555', # 设备的编号
    )
    # 最后一步:释放RKNN对象
    rknn.release()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions