Skip to content

net_decode.pt模型转onnx #13

@HandsLing

Description

@HandsLing

请问能提供一些net_decode.pt模型转onnx的思路吗。我转onnx的时候报错
torch.onnx.errors.SymbolicValueError: Unsupported: ONNX export of instance_norm for unknown channel size. [Caused by the value 'input.5 defined in (%skip.1 : Tensor, %skip0.1 : Tensor, %skip1.1 : Tensor, %input.5 : Tensor = prim::ListUnpack(%x.3), scope: model_p2p.conv_blocks_dbb.Hourglass_DBB_Mobile_Decode::
)' (type 'Tensor') in the TorchScript graph. The containing node has kind 'prim::ListUnpack'.]

我转onnx的代码如下:
decoder_input1 = torch.randn(1, 3, 384, 384).to(self.device)
decoder_input2 = torch.randn(1, 16, 192, 192).to(self.device)
decoder_input3 = torch.randn(1, 32, 96, 96).to(self.device)
decoder_input4 = torch.randn(1, 64, 48, 48).to(self.device)
decoder_input = (decoder_input1, decoder_input2, decoder_input3, decoder_input4)
param_val = torch.randn(1, 32).to(self.device)
input_names =["decoder_input1", "decoder_input2", "decoder_input3", "decoder_input4", "param_val"]
output_names = ['decoder_output']

    torch.onnx.export(self.generator, 
                    (decoder_input, param_val),
                    f'{data_dir}/net_decode.onnx',
                    opset_version=11,
                    input_names = input_names,
                    output_names = output_names,
                    dynamic_axes={  "decoder_input1": {0: "batch_size"}, 
                                    "decoder_input2": {0: "batch_size"},
                                    "decoder_input3": {0: "batch_size"},
                                    "decoder_input4": {0: "batch_size"},
                                    "param_val": {0: "batch_size"},
                                    'decoder_output': {0: 'batch_size'}}
                    )

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions