You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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")
The text was updated successfully, but these errors were encountered:
问题确认 Search before asking
请提出你的问题 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')
The text was updated successfully, but these errors were encountered: