Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pintrend导出onnx模型精度问题 #3845

Open
1 task done
aiwenzhu opened this issue Nov 8, 2024 · 1 comment
Open
1 task done

pintrend导出onnx模型精度问题 #3845

aiwenzhu opened this issue Nov 8, 2024 · 1 comment
Assignees
Labels
question Further information is requested

Comments

@aiwenzhu
Copy link

aiwenzhu commented Nov 8, 2024

问题确认 Search before asking

  • 我已经搜索过问题,但是没有找到解答。I have searched the question and found no related answer.

请提出你的问题 Please ask your question

训练好的pointrend模型使用官方的额export_onnx.py导出onnx发现在np.testing.assert_allclose(onnx_out, paddle_out, rtol=0, atol=1e-03)报错,代码如下,也使用了paddle2onnx来导出模型实测发现精度不一致

def export_onnx(args):
args.config = '/workspace/PaddleSeg/configs/pointrend/pointrend_resnet50_os8_voc12aug_512x512_40k.yml'
args.model_path = '/workspace/PaddleSeg/output/best_model118/model.pdparams'
args.width = 800
args.height = 640
assert args.config is not None,
'Please set --config path/to/yml'
cfg = Config(args.config)
builder = SegBuilder(cfg)
model = builder.model
if args.model_path is not None:
utils.load_entire_model(model, args.model_path)
logger.info('Loaded trained params of model successfully')

model.eval()
if args.print_model:
    print(model)

input_shape = [1, 3, args.height, args.width]
print("input shape:", input_shape)
input_data = np.random.random(input_shape).astype('float32')
model_name = os.path.basename(args.config).split(".")[0]

paddle_out = run_paddle(model, input_data)
print("out shape:", paddle_out.shape)
print("The paddle model has been predicted by PaddlePaddle.\n")

input_spec = paddle.static.InputSpec(input_shape, 'float32', 'x')
onnx_model_path = os.path.join(args.save_dir, model_name + "_model")
paddle.onnx.export(
    model, onnx_model_path, input_spec=[input_spec], opset_version=11)
print("Completed export onnx model.\n")

onnx_model_path = onnx_model_path + ".onnx"
onnx_out = check_and_run_onnx(onnx_model_path, input_data)
assert onnx_out.shape == paddle_out.shape
np.testing.assert_allclose(onnx_out, paddle_out, rtol=0, atol=1e-03)
print("The paddle and onnx models have the same outputs.\n")
@aiwenzhu aiwenzhu added the question Further information is requested label Nov 8, 2024
@TingquanGao TingquanGao reopened this Nov 13, 2024
@liuhongen1234567
Copy link
Collaborator

您好,可以提供一下paddle的版本和GPU环境吗?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants