sovit-123 / fasterrcnn-pytorch-training-pipeline

PyTorch Faster R-CNN Object Detection on Custom Dataset
MIT License
223 stars 75 forks source link

Onnx conversion problem #141

Open capslocknanda opened 6 months ago

capslocknanda commented 6 months ago

Hi thank you for sharing this repo. I have successfully trained a model with fasterrcnn_squeezenet1_1_small_head. But while converting the model to onnx, I get some error. "torch.onnx.errors.SymbolicValueError: Unsupported: ONNX export of operator get_pool_ceil_padding, input size not accessible. Please feel free to request support or submit a pull request on PyTorch GitHub: https://github.com/pytorch/pytorch/issues [Caused by the value '219 defined in (%219 : Float(1, 64, , , strides=[10188864, 159201, 399, 1], requires_grad=1, device=cpu) = onnx::Relu(%input.7), scope: torchvision.models.detection.faster_rcnn.FasterRCNN::/torch.nn.modules.container.Sequential::backbone/torch.nn.modules.activation.ReLU::backbone.1 # /home/subhajit/miniconda3/envs/detectron/lib/python3.8/site-packages/torch/nn/functional.py:1469:0 )' (type 'Tensor') in the TorchScript graph. The containing node has kind 'onnx::Relu'.]" "Inputs:

0: input.7 defined in (%input.7 : Float(1, 64, , , strides=[10188864, 159201, 399, 1], requires_grad=0, device=cpu) = onnx::Conv[dilations=[1, 1], group=1, kernel_shape=[3, 3], pads=[0, 0, 0, 0], strides=[2, 2]](%input.3, %backbone.0.weight, %backbone.0.bias), scope: torchvision.models.detection.faster_rcnn.FasterRCNN::/torch.nn.modules.container.Sequential::backbone/torch.nn.modules.conv.Conv2d::backbone.0 # /home/subhajit/miniconda3/envs/detectron/lib/python3.8/site-packages/torch/nn/modules/conv.py:456:0

)  (type 'Tensor')
Outputs:
    #0: 219 defined in (%219 : Float(1, 64, *, *, strides=[10188864, 159201, 399, 1], requires_grad=1, device=cpu) = onnx::Relu(%input.7), scope: torchvision.models.detection.faster_rcnn.FasterRCNN::/torch.nn.modules.container.Sequential::backbone/torch.nn.modules.activation.ReLU::backbone.1 # /home/subhajit/miniconda3/envs/detectron/lib/python3.8/site-packages/torch/nn/functional.py:1469:0
)  (type 'Tensor')"

If you have any idea how to tackle this that will be helpful.
thanks.
sovit-123 commented 6 months ago

Hi. Can you please check that you have PyTorch version at least 1.12.1 and ONNX version 1.12.0?

I trained Faster RCNN ResNet FPN V2 with PyTorch 2.2.0 and was able to successfully covert with ONNX version 1.120. I have also update the requirements file with proper ONNX versions for conversion and GPU and CPU inference.