Thank you for the support on this. I’ve managed to get rid of the errors above, and I have succeeded in running the trace on the loaded module. However, I now get an error when trying to save the model.
I tried 2 approaches, one in which I loaded the default model with pretrained weights, and one where I load in the necessary module for my custom trained model. The error is the same with both.



odom_detect.save(“odom_detect_traced.pt”)



Traceback (most recent call last):
File “”, line 1, in 
File “/home/benjamin/.local/lib/python3.6/site-packages/torch/jit/init.py”, line 1648, in save
return self._c.save(*args, **kwargs)
RuntimeError:
Could not export Python function call ‘SwishImplementation’. Remove calls to Python functions before export. Did you forget add @script or c annotation? If this is a nn.ModuleList, add it to constants:
/home/benjamin/.local/lib/python3.6/site-packages/efficientnet_pytorch/utils.py(52): forward
/home/benjamin/.local/lib/python3.6/site-packages/torch/nn/modules/module.py(534): _slow_forward
/home/benjamin/.local/lib/python3.6/site-packages/torch/nn/modules/module.py(548): call
/home/benjamin/.local/lib/python3.6/site-packages/efficientnet_pytorch/model.py(78): forward
/home/benjamin/.local/lib/python3.6/site-packages/torch/nn/modules/module.py(534): _slow_forward
/home/benjamin/.local/lib/python3.6/site-packages/torch/nn/modules/module.py(548): call
/home/benjamin/imagelift/opencv-text-recognition/src/model.py(193): forward
/home/benjamin/.local/lib/python3.6/site-packages/torch/nn/modules/module.py(534): _slow_forward
/home/benjamin/.local/lib/python3.6/site-packages/torch/nn/modules/module.py(548): call
/home/benjamin/imagelift/opencv-text-recognition/src/model.py(258): forward
/home/benjamin/.local/lib/python3.6/site-packages/torch/nn/modules/module.py(534): _slow_forward
/home/benjamin/.local/lib/python3.6/site-packages/torch/nn/modules/module.py(548): call
/home/benjamin/.local/lib/python3.6/site-packages/torch/jit/init.py(1027): trace_module
/home/benjamin/.local/lib/python3.6/site-packages/torch/jit/init.py(875): trace
(1): 
I have tried adding script methods “@torch.jit.script_method” to many of my forward functions, but I am not sure how deep it is possible for me to go with this, and if it will end up working or not.