|
本帖最后由 xsky 于 2020-2-21 09:48 编辑
RKNN v1.3, Pytorch v1.2
只一个FC层,使用.load_pytorch载入也是出现这样的错误,该从哪分析
- import torch
- import numpy as np
- from rknn.api import RKNN
- if __name__ == '__main__':
- ic = 128
- oc = 128
- m = torch.nn.Linear(ic, oc)
- m.eval()
- m.float()
- x = torch.full((1, ic), fill_value=0.1, dtype=torch.float)
- pt = torch.jit.trace(m, x)
- pt_file = "fc{128x128}.pt"
- rknn = RKNN(verbose=True)
- rknn.config(batch_size=1, channel_mean_value='0 0 0 1', reorder_channel='0 1 2',
- epochs=1) # asymmetric_quantized-u8, quantized_dtype='dynamic_fixed_point-16'
- rknn_file = pt_file + '.rknn'
- pt.save(pt_file)
- rknn.load_pytorch(model=pt_file, input_size_list=[[1, ic]])
- onnx_file = pt_file + '.onnx'
- # torch.onnx.export(m, x, onnx_file,
- # export_params=True, # store the trained parameter weights inside the model file
- # # do_constant_folding=True, # whether to execute constant folding for optimization
- # opset_version=9, # the ONNX version to export the model to
- # input_names=['input'], # the model's input names
- # output_names=['output'] # the model's output names
- # # dynamic_axes={'input' : {0 : 'batch_size'}, # variable lenght axes
- # # 'output' : {0 : 'batch_size'}}
- # )
- # rknn.load_onnx(model=onnx_file)
- ret = rknn.build(do_quantization=False, dataset='./dataset.txt')
- rknn.export_rknn(rknn_file)
- rknn.release()
代码中,如果导出.onnx,再load_onnx是可以正常build的,load_pytorch后bulid报错和楼主应该是一样的消息
- fc{128x128}.pt ********************
- WARNING: Token 'COMMENT' defined, but not used
- WARNING: There is 1 unused token
- !!!!! Illegal character '"'
- Syntax error in input! LexToken(NAMED_IDENTIFIER,'fc',1,27)
- !!!!! Illegal character '"'
- D import clients finished
- 2020-02-20 20:40:13.391282: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
- I Build fc{128x128} complete.
- D Optimizing network with force_1d_tensor, swapper, merge_layer, auto_fill_bn, resize_nearest_transformer, auto_fill_multiply, merge_avgpool_conv1x1, auto_fill_zero_bias, proposal_opt_import
- D Optimizing network with conv2d_big_kernel_size_transform
- W Genreate input meta fail, please check model.
- W External input meta file "C:\Users\dm\AppData\Local\Temp\tmpyqrr_3bz\fc128x128_inputmeta.yml" is not exists.
- Traceback (most recent call last):
- File "E:/Work/_Code/dmax/test/lstm/fc.py", line 39, in <module>
- ret = rknn.build(do_quantization=False, dataset='./dataset.txt')
- File "D:\Program Files\Python\Python36\lib\site-packages\rknn\api\rknn.py", line 238, in build
- ret = self.rknn_base.build(do_quantization=do_quantization, dataset=dataset, pack_vdata=pre_compile, batch_size=rknn_batch_size)
- File "rknn\api\rknn_base.py", line 719, in rknn.api.rknn_base.RKNNBase.build
- File "rknn\api\rknn_base.py", line 2249, in rknn.api.rknn_base.RKNNBase._generate_inputmeta
- IndexError: list index out of range
load_pytorch没报错,在build时报的错:
W Genreate input meta fail, please check model.
W External input meta file "C:\Users\dm\AppData\Local\Temp\tmpszyfyeur\lstm1414_inputmeta.yml" is not exists.
rknn.config 中的参数 channel_mean_value='0 0 0 1', reorder_channel='0 1 2' 是三通道的,如果像这个,输入只是一个向量的,这里该怎么设置, channel_mean_value='0 0 1', reorder_channel='0 1 ' 么?但这里即便按chw三个维度设置,fc的输入输出均是[1,x]向量,onnx格式也能正常导出rknn。
|
|