Export libtorch model which support variable input tensor

Do libtorch model support variable size of the tensor? Trying to train a classification on medical images(CT scans), but the number of slices are different for each file([512, 512, variable]). Is it possible to export the model witch support input of [1, variable, 512, 512]?

Every examples of libtorch use fix size input before export the model

img = torch.zeros((1,3,16,112,112)) #64,3,16,112,112; 16, 3, 1, 112, 112
traced_script_module.save("video_r3d_18.pt")

Thanks

Yes, it should be possible via torch.jit.script. Tracing via torch.jit.trace uses the passed input to trace all operations and might fail, if you are using different inputs in the deployment use case.

1 Like