Search code examples
pytorchonnx

how to know model's input size in onnx?


The size of the input is not specified in the pytorch. Just size the kernel to make the output. The WinMLDashboard shows the width and height of the image input. How is that possible?


Solution

  • Do you mean when you serialize the network from pytorch to onnx? Because when you export from pytorch you need to define the size of the input as per documentation

    dummy_input = torch.randn(10, 3, 224, 224, device='cuda')
    model = torchvision.models.alexnet(pretrained=True).cuda()
    input_names = [ "actual_input_1" ] 
    output_names = [ "output1" ]
    
    torch.onnx.export(model, dummy_input, "alexnet.onnx", verbose=True, 
    input_names=input_names, output_names=output_names)