栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

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

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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

转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')

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1018375.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号