gpt4 book ai didi

input: kMAX dimensions in profile 0 are [2,3,128,128] but input has static dimensions [1,3,128,128]

转载 作者:知者 更新时间:2024-03-12 08:53:12 39 4
gpt4 key购买 nike

转tensorrt时报错:

input: kMAX dimensions in profile 0 are [2,3,128,128] but input has static dimensions [1,3,128,128]

原因1:

onnx导出是固定的bach_size

tensorrt是动态batch_size

导致报错了。

原因2,simplify时输入了固定的batch_size,导致的报错:

onnx_model = onnx.load("model2.onnx")  # load onnx model
    output_path = 'skip_simp.onnx'
    model_simp, check = simplify(onnx_model, input_shapes={'input': [1, 4, 128, 128]})

解决方法:

导出onnx用动态batch_size:

data = torch.randn(1, 4, 128, 128)#.cuda()

    model.eval()

    torch.onnx.export(model, data, "model2.onnx",  export_params=True,  opset_version=11,    do_constant_folding=True,  # whether to execute constant folding for optimization
                      input_names=['input'],  # the model's input names
                      output_names=['output'], dynamic_axes={'input': {0: 'batch_size'}, 'output': {0: 'batch_size'}})
                      # output_names=['output'], dynamic_axes={'input': {0: 'batch_size', 2: 'in_width', 3: 'int_height'}, 'output': {0: 'batch_size', 2: 'out_width', 3: 'out_height'}})

原因2的解决方法:

onnx_model = onnx.load("model2.onnx")  # load onnx model
    output_path = 'skip_simp2.onnx'
    model_simp, check = simplify(onnx_model, dynamic_input_shape=True)
    # model_simp, check = simplify(onnx_model)
    assert check, "Simplified ONNX model could not be validated"
    onnx.save(model_simp, output_path)
    print('finished exporting onnx')

39 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com