I am trying to convert the pytorch model in this link to onnx model using the code below :
device=t.device('cuda:0' if t.cuda.is_available() else 'cpu')
print(device)
faster_rcnn = FasterRCNNVGG16()
trainer = FasterRCNNTrainer(faster_rcnn).cuda()
#trainer = FasterRCNNTrainer(faster_rcnn).to(device)
trainer.load('./checkpoints/model.pth')
dummy_input = t.randn(1, 3, 300, 300, device = 'cuda')
#dummy_input = dummy_input.to(device)
t.onnx.export(faster_rcnn, dummy_input, "model.onnx", verbose = True)
But I get the following error (Sorry for the block quote below stackoverflow wouldn't let the whole trace be in code format and wouldn't let the question be posted otherwise):
Traceback (most recent call last): small_object_detection_master_samirsen\onnxtest.py", line 44, in <module> t.onnx.export(faster_rcnn, dummy_input, "fasterrcnn_10120119_06025842847785781.onnx", verbose = True) File "C:\Users\HP\AppData\Local\Programs\Python\Python36\lib\site-packages\torch\onnx\__init__.py",
line 132, in export strip_doc_string, dynamic_axes) File "C:\Users\HP\AppData\Local\Programs\Python\Python36\lib\site-packages\torch\onnx\utils.py", line 64, in export example_outputs=example_outputs, strip_doc_string=strip_doc_string, dynamic_axes=dynamic_axes) File "C:\Users\HP\AppData\Local\Programs\Python\Python36\lib\site-packages\torch\onnx\utils.py", line 329, in _export _retain_param_name, do_constant_folding) File "C:\Users\HP\AppData\Local\Programs\Python\Python36\lib\site-packages\torch\onnx\utils.py", line 213, in _model_to_graph graph, torch_out = _trace_and_get_graph_from_model(model, args, training) File "C:\Users\HP\AppData\Local\Programs\Python\Python36\lib\site-packages\torch\onnx\utils.py", line 171, in _trace_and_get_graph_from_model trace, torch_out = torch.jit.get_trace_graph(model, args, _force_outplace=True) File "C:\Users\HP\AppData\Local\Programs\Python\Python36\lib\site-packages\torch\jit__init__.py", line 256, in get_trace_graph return LegacyTracedModule(f, _force_outplace, return_inputs)(*args, **kwargs) File "C:\Users\HP\AppData\Local\Programs\Python\Python36\lib\site-packages\torch\nn\modules\module.py", line 547, in call result = self.forward(*input, **kwargs) File "C:\Users\HP\AppData\Local\Programs\Python\Python36\lib\site-packages\torch\jit__init__.py", line 323, in forward out = self.inner(*trace_inputs) File "C:\Users\HP\AppData\Local\Programs\Python\Python36\lib\site-packages\torch\nn\modules\module.py", line 545, in call result = self._slow_forward(*input, **kwargs) File "C:\Users\HP\AppData\Local\Programs\Python\Python36\lib\site-packages\torch\nn\modules\module.py", line 531, in _slow_forward File "C:\Users\HP\AppData\Local\Programs\Python\Python36\lib\site-packages\torch\nn\modules\module.py", line 531, in _slow_forward result = self.forward(*input, **kwargs) File "D:\smallobject2\export test s\small_object_detection_master_samirsen\model\faster_rcnn.py", line 133, in forward h, rois, roi_indices) File "C:\Users\HP\AppData\Local\Programs\Python\Python36\lib\site-packages\torch\nn\modules\module.py", line 545, in call result = self._slow_forward(*input, **kwargs) File "C:\Users\HP\AppData\Local\Programs\Python\Python36\lib\site-packages\torch\nn\modules\module.py", line 531, in _slow_forward result = self.forward(*input, **kwargs) File "D:\smallobject2\export test s\small_object_detection_master_samirsen\model\faster_rcnn_vgg16.py", line 142, in forward pool = self.roi(x, indices_and_rois) File "C:\Users\HP\AppData\Local\Programs\Python\Python36\lib\site-packages\torch\nn\modules\module.py", line 545, in call result = self._slow_forward(*input, **kwargs) File "C:\Users\HP\AppData\Local\Programs\Python\Python36\lib\site-packages\torch\nn\modules\module.py", line 531, in _slow_forward result = self.forward(*input, **kwargs) File "D:\smallobject2\export test s\small_object_detection_master_samirsen\model\roi_module.py", line 85, in forward return self.RoI(x, rois) RuntimeError: Attempted to trace RoI, but tracing of legacy functions is not supported