Closed cww97 closed 2 years ago
你好,可以参考下这个repo
你好, 第一种这是静态图模型转换onnx的方法。红色部分应该使用.pdmodel模型文件,而不是py代码文件。 你可以使用paddle.jit.save动转静api,输出静态图模型,再把静态图模型转换为onnx模型,具体实现如下:
pwd = os.getcwd() all_save = os.path.join(pwd, 'all_save') os.mkdir(all_save)
op = ResNet_50vd() op.eval() input_spec = paddle.static.InputSpec(shape=[None, 10, 320, 320], dtype='float32', name='image')
paddle.jit.save(op, os.path.join(all_save, 'static', 'model'), input_spec=[input_spec])
然后使用命令: paddle2onnx --model_dir all_save/static \ --model_filename all_save/static/model.pdmodel \ --params_filename all_save/static/model.pdiparams \ --save_file all_save/op12_static.onnx \ --opset_version 12
就可以输出onnx模型。
第二种方式是动态图模型直接转onnx,你所给的图中出现的问题是因为动态图layer重名了, 可以通过开启再关闭静态图重置消除这个问题:
paddle.enable_static() #开启静态图模式 paddle.disable_static() #关闭静态图,变回动态图模式 pwd = os.getcwd() all_save = os.path.join(pwd, 'all_save') os.mkdir(all_save)
op = ResNet_50vd() op.eval() input_spec = paddle.static.InputSpec(shape=[None, 10, 320, 320], dtype='float32', name='image') paddle.onnx.export(op, os.path.join(all_save, 'op' + '12'), input_spec=[input_spec], opset_version=12, enable_onnx_checker=True)
就可以把动态图模型转为onnx模型。
Since this issue has not been updated for more than three months, it will be closed, if it is not solved or there is a follow-up one, please reopen it at any time and we will continue to follow up. It is recommended to pull and try the latest code first. 由于该问题超过三个月未更新,将会被关闭,若问题未解决或有后续问题,请随时重新打开(建议先拉取最新代码进行尝试),我们会继续跟进。
这个模型 https://github.com/PaddlePaddle/PaddleClas/blob/release/2.1/docs/zh_CN/application/transfer_learning.md 页面里面有个.pdparams文件
根据这个文档 https://github.com/PaddlePaddle/Paddle2ONNX/blob/release/0.6/README_zh.md
两个都试了,都有问题
另一个
得到输出
想请问正确的姿势是什么,想直接取这个模型用