Pytroch模型转为paddle
Created by: zhulingling1995
先将pytorch训练的人脸检测模型(https://github.com/biubug6/Pytorch_Retinaface)转换为onnx模型后,通过代码“x2paddle --framework=onnx --model=FaceDetector.onnx --save_dir=pd_model”将onnx模型转换为PaddlePaddle时,出现以下错误,其中安装的版本信息onnx==1.6.0,onnxruntime==1.0.0,paddlepaddle==1.8.3,x2paddle==0.7.4,想请教大家如何解决这个问题?非常感谢
Now translating model from onnx to paddle. model ir_version: 4, op version: 9 2020-07-29 15:56:19,665-WARNING: During conversion of your model, some operators will be assignd node.out_shape==None, refer to https://github.com/onnx/onnx/blob/master/docs/ShapeInference.md 2020-07-29 15:56:19.998788235 [W:onnxruntime:Default, graph.cc:2367 CleanUnusedInitializers] Removing initializer '96'. It is not used by any node and should be removed from the model. 2020-07-29 15:56:20.005413695 [W:onnxruntime:Default, graph.cc:2367 CleanUnusedInitializers] Removing initializer '78'. It is not used by any node and should be removed from the model. 2020-07-29 15:56:20.005944613 [W:onnxruntime:Default, graph.cc:2367 CleanUnusedInitializers] Removing initializer '72'. It is not used by any node and should be removed from the model. 2020-07-29 15:56:20.006321312 [W:onnxruntime:Default, graph.cc:2367 CleanUnusedInitializers] Removing initializer '60'. It is not used by any node and should be removed from the model. 2020-07-29 15:56:20.006406835 [W:onnxruntime:Default, graph.cc:2367 CleanUnusedInitializers] Removing initializer '6'. It is not used by any node and should be removed from the model. 2020-07-29 15:56:20.006489645 [W:onnxruntime:Default, graph.cc:2367 CleanUnusedInitializers] Removing initializer '276'. It is not used by any node and should be removed from the model. 2020-07-29 15:56:20.006552170 [W:onnxruntime:Default, graph.cc:2367 CleanUnusedInitializers] Removing initializer '270'. It is not used by any node and should be removed from the model. 2020-07-29 15:56:20.006634179 [W:onnxruntime:Default, graph.cc:2367 CleanUnusedInitializers] Removing initializer '198'. It is not used by any node and should be removed from the model. 2020-07-29 15:56:20.006698052 [W:onnxruntime:Default, graph.cc:2367 CleanUnusedInitializers] Removing initializer '246'. It is not used by any node and should be removed from the model. 2020-07-29 15:56:20.006761391 [W:onnxruntime:Default, graph.cc:2367 CleanUnusedInitializers] Removing initializer '24'. It is not used by any node and should be removed from the model. 2020-07-29 15:56:20.006842911 [W:onnxruntime:Default, graph.cc:2367 CleanUnusedInitializers] Removing initializer '54'. It is not used by any node and should be removed from the model. 2020-07-29 15:56:20.006906436 [W:onnxruntime:Default, graph.cc:2367 CleanUnusedInitializers] Removing initializer '228'. It is not used by any node and should be removed from the model. 2020-07-29 15:56:20.006968558 [W:onnxruntime:Default, graph.cc:2367 CleanUnusedInitializers] Removing initializer '222'. It is not used by any node and should be removed from the model. 2020-07-29 15:56:20.007051038 [W:onnxruntime:Default, graph.cc:2367 CleanUnusedInitializers] Removing initializer '132'. It is not used by any node and should be removed from the model. 2020-07-29 15:56:20.007125220 [W:onnxruntime:Default, graph.cc:2367 CleanUnusedInitializers] Removing initializer '282'. It is not used by any node and should be removed from the model. 2020-07-29 15:56:20.007190124 [W:onnxruntime:Default, graph.cc:2367 CleanUnusedInitializers] Removing initializer '36'. It is not used by any node and should be removed from the model. 2020-07-29 15:56:20.007271495 [W:onnxruntime:Default, graph.cc:2367 CleanUnusedInitializers] Removing initializer '336'. It is not used by any node and should be removed from the model. 2020-07-29 15:56:20.007336129 [W:onnxruntime:Default, graph.cc:2367 CleanUnusedInitializers] Removing initializer '192'. It is not used by any node and should be removed from the model. 2020-07-29 15:56:20.007417346 [W:onnxruntime:Default, graph.cc:2367 CleanUnusedInitializers] Removing initializer '252'. It is not used by any node and should be removed from the model. 2020-07-29 15:56:20.007479943 [W:onnxruntime:Default, graph.cc:2367 CleanUnusedInitializers] Removing initializer '186'. It is not used by any node and should be removed from the model. 2020-07-29 15:56:20.007542059 [W:onnxruntime:Default, graph.cc:2367 CleanUnusedInitializers] Removing initializer '174'. It is not used by any node and should be removed from the model. 2020-07-29 15:56:20.007624857 [W:onnxruntime:Default, graph.cc:2367 CleanUnusedInitializers] Removing initializer '354'. It is not used by any node and should be removed from the model. 2020-07-29 15:56:20.007688440 [W:onnxruntime:Default, graph.cc:2367 CleanUnusedInitializers] Removing initializer '162'. It is not used by any node and should be removed from the model. 2020-07-29 15:56:20.007770040 [W:onnxruntime:Default, graph.cc:2367 CleanUnusedInitializers] Removing initializer '420'. It is not used by any node and should be removed from the model. 2020-07-29 15:56:20.007848168 [W:onnxruntime:Default, graph.cc:2367 CleanUnusedInitializers] Removing initializer '318'. It is not used by any node and should be removed from the model. 2020-07-29 15:56:20.007911525 [W:onnxruntime:Default, graph.cc:2367 CleanUnusedInitializers] Removing initializer '330'. It is not used by any node and should be removed from the model. 2020-07-29 15:56:20.007992578 [W:onnxruntime:Default, graph.cc:2367 CleanUnusedInitializers] Removing initializer '240'. It is not used by any node and should be removed from the model. 2020-07-29 15:56:20.008055867 [W:onnxruntime:Default, graph.cc:2367 CleanUnusedInitializers] Removing initializer '150'. It is not used by any node and should be removed from the model. 2020-07-29 15:56:20.008118000 [W:onnxruntime:Default, graph.cc:2367 CleanUnusedInitializers] Removing initializer '138'. It is not used by any node and should be removed from the model. 2020-07-29 15:56:20.008201686 [W:onnxruntime:Default, graph.cc:2367 CleanUnusedInitializers] Removing initializer '12'. It is not used by any node and should be removed from the model. 2020-07-29 15:56:20.008266650 [W:onnxruntime:Default, graph.cc:2367 CleanUnusedInitializers] Removing initializer '210'. It is not used by any node and should be removed from the model. 2020-07-29 15:56:20.008348209 [W:onnxruntime:Default, graph.cc:2367 CleanUnusedInitializers] Removing initializer '108'. It is not used by any node and should be removed from the model. 2020-07-29 15:56:20.008411845 [W:onnxruntime:Default, graph.cc:2367 CleanUnusedInitializers] Removing initializer '102'. It is not used by any node and should be removed from the model. 2020-07-29 15:56:20.008474208 [W:onnxruntime:Default, graph.cc:2367 CleanUnusedInitializers] Removing initializer '216'. It is not used by any node and should be removed from the model. 2020-07-29 15:56:20.008557561 [W:onnxruntime:Default, graph.cc:2367 CleanUnusedInitializers] Removing initializer '234'. It is not used by any node and should be removed from the model. 2020-07-29 15:56:20.008638776 [W:onnxruntime:Default, graph.cc:2367 CleanUnusedInitializers] Removing initializer '144'. It is not used by any node and should be removed from the model. 2020-07-29 15:56:20.008704282 [W:onnxruntime:Default, graph.cc:2367 CleanUnusedInitializers] Removing initializer '258'. It is not used by any node and should be removed from the model. 2020-07-29 15:56:20.008785856 [W:onnxruntime:Default, graph.cc:2367 CleanUnusedInitializers] Removing initializer '18'. It is not used by any node and should be removed from the model. 2020-07-29 15:56:20.008849768 [W:onnxruntime:Default, graph.cc:2367 CleanUnusedInitializers] Removing initializer '168'. It is not used by any node and should be removed from the model. 2020-07-29 15:56:20.008913018 [W:onnxruntime:Default, graph.cc:2367 CleanUnusedInitializers] Removing initializer '120'. It is not used by any node and should be removed from the model. 2020-07-29 15:56:20.008995512 [W:onnxruntime:Default, graph.cc:2367 CleanUnusedInitializers] Removing initializer '126'. It is not used by any node and should be removed from the model. 2020-07-29 15:56:20.009058990 [W:onnxruntime:Default, graph.cc:2367 CleanUnusedInitializers] Removing initializer '366'. It is not used by any node and should be removed from the model. 2020-07-29 15:56:20.009121541 [W:onnxruntime:Default, graph.cc:2367 CleanUnusedInitializers] Removing initializer '204'. It is not used by any node and should be removed from the model. 2020-07-29 15:56:20.009202604 [W:onnxruntime:Default, graph.cc:2367 CleanUnusedInitializers] Removing initializer '264'. It is not used by any node and should be removed from the model. 2020-07-29 15:56:20.009268713 [W:onnxruntime:Default, graph.cc:2367 CleanUnusedInitializers] Removing initializer '180'. It is not used by any node and should be removed from the model. 2020-07-29 15:56:20.009352018 [W:onnxruntime:Default, graph.cc:2367 CleanUnusedInitializers] Removing initializer '372'. It is not used by any node and should be removed from the model. 2020-07-29 15:56:20.009414308 [W:onnxruntime:Default, graph.cc:2367 CleanUnusedInitializers] Removing initializer '288'. It is not used by any node and should be removed from the model. 2020-07-29 15:56:20.009476712 [W:onnxruntime:Default, graph.cc:2367 CleanUnusedInitializers] Removing initializer '90'. It is not used by any node and should be removed from the model. 2020-07-29 15:56:20.009557580 [W:onnxruntime:Default, graph.cc:2367 CleanUnusedInitializers] Removing initializer '294'. It is not used by any node and should be removed from the model. 2020-07-29 15:56:20.009621673 [W:onnxruntime:Default, graph.cc:2367 CleanUnusedInitializers] Removing initializer '342'. It is not used by any node and should be removed from the model. 2020-07-29 15:56:20.009703031 [W:onnxruntime:Default, graph.cc:2367 CleanUnusedInitializers] Removing initializer '30'. It is not used by any node and should be removed from the model. 2020-07-29 15:56:20.009765887 [W:onnxruntime:Default, graph.cc:2367 CleanUnusedInitializers] Removing initializer '300'. It is not used by any node and should be removed from the model. 2020-07-29 15:56:20.009829021 [W:onnxruntime:Default, graph.cc:2367 CleanUnusedInitializers] Removing initializer '66'. It is not used by any node and should be removed from the model. 2020-07-29 15:56:20.009910580 [W:onnxruntime:Default, graph.cc:2367 CleanUnusedInitializers] Removing initializer '384'. It is not used by any node and should be removed from the model. 2020-07-29 15:56:20.009974169 [W:onnxruntime:Default, graph.cc:2367 CleanUnusedInitializers] Removing initializer '306'. It is not used by any node and should be removed from the model. 2020-07-29 15:56:20.010037312 [W:onnxruntime:Default, graph.cc:2367 CleanUnusedInitializers] Removing initializer '312'. It is not used by any node and should be removed from the model. 2020-07-29 15:56:20.010117751 [W:onnxruntime:Default, graph.cc:2367 CleanUnusedInitializers] Removing initializer '360'. It is not used by any node and should be removed from the model. 2020-07-29 15:56:20.010180699 [W:onnxruntime:Default, graph.cc:2367 CleanUnusedInitializers] Removing initializer '438'. It is not used by any node and should be removed from the model. 2020-07-29 15:56:20.010262153 [W:onnxruntime:Default, graph.cc:2367 CleanUnusedInitializers] Removing initializer '114'. It is not used by any node and should be removed from the model. 2020-07-29 15:56:20.010326591 [W:onnxruntime:Default, graph.cc:2367 CleanUnusedInitializers] Removing initializer '348'. It is not used by any node and should be removed from the model. 2020-07-29 15:56:20.010410177 [W:onnxruntime:Default, graph.cc:2367 CleanUnusedInitializers] Removing initializer '324'. It is not used by any node and should be removed from the model. 2020-07-29 15:56:20.010474783 [W:onnxruntime:Default, graph.cc:2367 CleanUnusedInitializers] Removing initializer '84'. It is not used by any node and should be removed from the model. 2020-07-29 15:56:20.010555787 [W:onnxruntime:Default, graph.cc:2367 CleanUnusedInitializers] Removing initializer '156'. It is not used by any node and should be removed from the model. 2020-07-29 15:56:20.010619029 [W:onnxruntime:Default, graph.cc:2367 CleanUnusedInitializers] Removing initializer '378'. It is not used by any node and should be removed from the model. 2020-07-29 15:56:20.010701090 [W:onnxruntime:Default, graph.cc:2367 CleanUnusedInitializers] Removing initializer '390'. It is not used by any node and should be removed from the model. 2020-07-29 15:56:20.010767027 [W:onnxruntime:Default, graph.cc:2367 CleanUnusedInitializers] Removing initializer '396'. It is not used by any node and should be removed from the model. 2020-07-29 15:56:20.010861360 [W:onnxruntime:Default, graph.cc:2367 CleanUnusedInitializers] Removing initializer '402'. It is not used by any node and should be removed from the model. 2020-07-29 15:56:20.010944279 [W:onnxruntime:Default, graph.cc:2367 CleanUnusedInitializers] Removing initializer '408'. It is not used by any node and should be removed from the model. 2020-07-29 15:56:20.011007588 [W:onnxruntime:Default, graph.cc:2367 CleanUnusedInitializers] Removing initializer '414'. It is not used by any node and should be removed from the model. 2020-07-29 15:56:20.011070053 [W:onnxruntime:Default, graph.cc:2367 CleanUnusedInitializers] Removing initializer '42'. It is not used by any node and should be removed from the model. 2020-07-29 15:56:20.011157802 [W:onnxruntime:Default, graph.cc:2367 CleanUnusedInitializers] Removing initializer '426'. It is not used by any node and should be removed from the model. 2020-07-29 15:56:20.011220231 [W:onnxruntime:Default, graph.cc:2367 CleanUnusedInitializers] Removing initializer '432'. It is not used by any node and should be removed from the model. 2020-07-29 15:56:20.011303514 [W:onnxruntime:Default, graph.cc:2367 CleanUnusedInitializers] Removing initializer '48'. It is not used by any node and should be removed from the model. Total nodes: 377 Traceback (most recent call last): File "/home/zhulingling/anaconda3/lib/python3.6/site-packages/x2paddle/core/op_mapper.py", line 122, in save_inference_model inputs, outputs = model.x2paddle_net() File "pd_model/model_with_code/model.py", line 8, in x2paddle_net x2paddle_647 = fluid.layers.create_parameter(dtype='float32', shape=[2], name='x2paddle_647', attr='x2paddle_647', default_initializer=Constant(0.0)) File "/home/zhulingling/anaconda3/lib/python3.6/site-packages/paddle/fluid/layers/tensor.py", line 148, in create_parameter check_type(attr, 'attr', (type(None), ParamAttr), 'create_parameter') File "/home/zhulingling/anaconda3/lib/python3.6/site-packages/paddle/fluid/data_feeder.py", line 97, in check_type (input_name, op_name, expected_type, type(input), extra_message)) TypeError: The type of 'attr' in create_parameter must be (<class 'NoneType'>, <class 'paddle.fluid.param_attr.ParamAttr'>), but received <class 'str'>.
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "/home/zhulingling/anaconda3/bin/x2paddle", line 8, in sys.exit(main()) File "/home/zhulingling/anaconda3/lib/python3.6/site-packages/x2paddle/convert.py", line 232, in main onnx2paddle(args.model, args.save_dir, params_merge) File "/home/zhulingling/anaconda3/lib/python3.6/site-packages/x2paddle/convert.py", line 175, in onnx2paddle mapper.save_inference_model(save_dir, params_merge) File "/home/zhulingling/anaconda3/lib/python3.6/site-packages/x2paddle/core/op_mapper.py", line 158, in save_inference_model .format(py_code_dir)) Exception: Paddle code was saved in pd_model/model_with_code/model.py, but seems there's wrong exist, please check model.py manually.