TensorRT: tensorrt 6.0.1.5 torch1.3 onnx, build engine from onnx file fail, Network must have at least one out...

def simple_conv1d():
    class TestNet(torch.nn.Module):
        def __init__(self):
            super(TestNet, self).__init__()
            self.conv = torch.nn.Conv1d(2, 4, kernel_size=(1,))
            return
        def forward(self, x):
            res = self.conv(x)
            return res
    x = torch.randn(3, 2, 10)
    net = TestNet()
    onnx_file_path = "simple_conv1d.onnx"
    torch.onnx.export(net, x, onnx_file_path, export_params=True, verbose=True, input_names=["data"])
    TRT_LOGGER = trt.Logger(trt.Logger.INFO)
    with trt.Builder(TRT_LOGGER) as builder:
        with builder.create_network() as network:
            with trt.OnnxParser(network,TRT_LOGGER) as parser:
                with open(onnx_file_path, 'rb') as model:
                    parser.parse(model.read())
                builder.max_workspace_size = 1<<30
                builder.fp16_mode = False
                builder.max_batch_size = 32
                builder.strict_type_constraints = False
                engine = builder.build_cuda_engine(network)
                with open("simple_conv1d.trt", "wb") as f:
                    f.write(engine.serialize())
    return

even such simple conv1d still fail… got error [TensorRT] ERROR: Network must have at least one output

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 16

Most upvoted comments

Also, for users that are using a compatible version of Pytorch and experience the following related error:

[TensorRT] ERROR: Unused Input: data

A current work-around is to add some dummy layer (like Identity) and mark that as an output so that the input is considered “used”