joe-siyuan-qiao / DetectoRS

DetectoRS: Detecting Objects with Recursive Feature Pyramid and Switchable Atrous Convolution
Apache License 2.0
1.14k stars 176 forks source link

Failed to export onnx model #84

Open dmenig opened 3 years ago

dmenig commented 3 years ago

Thanks for your error report and we appreciate it a lot.

Describe the bug pytorch2onnx.py is broken with available models

Reproduction

python tools/pytorch2onnx.py     DetectoRS_mstrain_400_1200_r50_40e.py DetectoRS_R50-0f1c8080.pth     --out onnx_model.onnx

Environment

root@23f5d92075d8:/veesion/DetectoRS# python mmdet/utils/collect_env.py 
sys.platform: linux
Python: 3.6.9 (default, Oct  8 2020, 12:12:24) [GCC 8.4.0]
CUDA available: True
CUDA_HOME: /usr/local/cuda
NVCC: Build cuda_11.1.TC455_06.29069683_0
GPU 0: GeForce RTX 2080 Ti
GCC: gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
PyTorch: 1.4.0
PyTorch compiling details: PyTorch built with:
  - GCC 7.3
  - Intel(R) Math Kernel Library Version 2019.0.4 Product Build 20190411 for Intel(R) 64 architecture applications
  - Intel(R) MKL-DNN v0.21.1 (Git Hash 7d2fd500bc78936d1d648ca713b901012f470dbc)
  - OpenMP 201511 (a.k.a. OpenMP 4.5)
  - NNPACK is enabled
  - CUDA Runtime 10.1
  - NVCC architecture flags: -gencode;arch=compute_37,code=sm_37;-gencode;arch=compute_50,code=sm_50;-gencode;arch=compute_60,code=sm_60;-gencode;arch=compute_61,code=sm_61;-gencode;arch=compute_70,code=sm_70;-gencode;arch=compute_75,code=sm_75;-gencode;arch=compute_37,code=compute_37
  - CuDNN 7.6.3
  - Magma 2.5.1
  - Build settings: BLAS=MKL, BUILD_NAMEDTENSOR=OFF, BUILD_TYPE=Release, CXX_FLAGS= -Wno-deprecated -fvisibility-inlines-hidden -fopenmp -DUSE_FBGEMM -DUSE_QNNPACK -DUSE_PYTORCH_QNNPACK -O2 -fPIC -Wno-narrowing -Wall -Wextra -Wno-missing-field-initializers -Wno-type-limits -Wno-array-bounds -Wno-unknown-pragmas -Wno-sign-compare -Wno-unused-parameter -Wno-unused-variable -Wno-unused-function -Wno-unused-result -Wno-strict-overflow -Wno-strict-aliasing -Wno-error=deprecated-declarations -Wno-stringop-overflow -Wno-error=pedantic -Wno-error=redundant-decls -Wno-error=old-style-cast -fdiagnostics-color=always -faligned-new -Wno-unused-but-set-variable -Wno-maybe-uninitialized -fno-math-errno -fno-trapping-math -Wno-stringop-overflow, DISABLE_NUMA=1, PERF_WITH_AVX=1, PERF_WITH_AVX2=1, PERF_WITH_AVX512=1, USE_CUDA=ON, USE_EXCEPTION_PTR=1, USE_GFLAGS=OFF, USE_GLOG=OFF, USE_MKL=ON, USE_MKLDNN=ON, USE_MPI=OFF, USE_NCCL=ON, USE_NNPACK=ON, USE_OPENMP=ON, USE_STATIC_DISPATCH=OFF, 

TorchVision: 0.5.0
OpenCV: 4.5.1
MMCV: 0.4.3
MMDetection: 1.1.0+612916b
MMDetection Compiler: GCC 7.5
MMDetection CUDA Compiler: 11.1

Error traceback

/veesion/DetectoRS/mmdet/ops/dcn/deform_conv.py:108: TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect. We can't record the data flow of Python values, so this 
value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!                                                                                         
  if not all(map(lambda s: s > 0, output_size)):                                                                                                                                                           
Traceback (most recent call last):                                                                                                                                                                         
  File "tools/pytorch2onnx.py", line 125, in <module>                                                                                                                                                      
    main()                                                                                                                                                                                                 
  File "tools/pytorch2onnx.py", line 117, in main                                                                                                                                                          
    onnx_model = export_onnx_model(model, (input_data, ), args.passes)                                                                                                                                     
  File "tools/pytorch2onnx.py", line 44, in export_onnx_model                                                                                                                                              
    operator_export_type=OperatorExportTypes.ONNX_ATEN_FALLBACK,                                                                                                                                           
  File "/usr/local/lib/python3.6/dist-packages/torch/onnx/__init__.py", line 148, in export                                                                                                                
    strip_doc_string, dynamic_axes, keep_initializers_as_inputs)                                                                                                                                           
  File "/usr/local/lib/python3.6/dist-packages/torch/onnx/utils.py", line 66, in export                                                                                                                    
    dynamic_axes=dynamic_axes, keep_initializers_as_inputs=keep_initializers_as_inputs)                                                                                                                    
  File "/usr/local/lib/python3.6/dist-packages/torch/onnx/utils.py", line 416, in _export                                                                                                                  
    fixed_batch_size=fixed_batch_size)                                                                                                                                                                     
  File "/usr/local/lib/python3.6/dist-packages/torch/onnx/utils.py", line 279, in _model_to_graph                                                                                                          
    graph, torch_out = _trace_and_get_graph_from_model(model, args, training)                                                                                                                              
  File "/usr/local/lib/python3.6/dist-packages/torch/onnx/utils.py", line 236, in _trace_and_get_graph_from_model                                                                                          
    trace_graph, torch_out, inputs_states = torch.jit._get_trace_graph(model, args, _force_outplace=True, _return_inputs_states=True)                                                             [31/1980]
  File "/usr/local/lib/python3.6/dist-packages/torch/jit/__init__.py", line 277, in _get_trace_graph
    outs = ONNXTracedModule(f, _force_outplace, return_inputs, _return_inputs_states)(*args, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 532, in __call__
    result = self.forward(*input, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/torch/jit/__init__.py", line 360, in forward
    self._force_outplace, 
  File "/usr/local/lib/python3.6/dist-packages/torch/jit/__init__.py", line 347, in wrapper
    outs.append(self.inner(*trace_inputs))
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 530, in __call__
    result = self._slow_forward(*input, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 516, in _slow_forward            
    result = self.forward(*input, **kwargs)                                     
  File "/veesion/DetectoRS/mmdet/models/detectors/htc.py", line 160, in forward_dummy
    x = self.extract_feat(img)
  File "/veesion/DetectoRS/mmdet/models/detectors/rfp.py", line 98, in extract_feat
    x = self.backbone(img)                                                                                                                                                                                   File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 530, in __call__
    result = self._slow_forward(*input, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 516, in _slow_forward
    result = self.forward(*input, **kwargs)                                                                                                                                                                  File "/veesion/DetectoRS/mmdet/models/backbones/resnet.py", line 590, in forward                                                                                                                             x = res_layer(x)                                                                                                                                                                                         File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 530, in __call__                                                                                                         
    result = self._slow_forward(*input, **kwargs)                                                                                                                          
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 516, in _slow_forward
    result = self.forward(*input, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/container.py", line 100, in forward
    input = module(input)
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 530, in __call__
    result = self._slow_forward(*input, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 516, in _slow_forward
    result = self.forward(*input, **kwargs)
  File "/veesion/DetectoRS/mmdet/models/backbones/resnet.py", line 263, in forward
    out = _inner_forward(x)
  File "/veesion/DetectoRS/mmdet/models/backbones/resnet.py", line 240, in _inner_forward
    out = self.conv2(out)
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 530, in __call__
    result = self._slow_forward(*input, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 516, in _slow_forward
    result = self.forward(*input, **kwargs)
  File "/veesion/DetectoRS/mmdet/ops/saconv.py", line 95, in forward
    1)
  File "/veesion/DetectoRS/mmdet/ops/dcn/deform_conv.py", line 47, in forward
    raise NotImplementedError
NotImplementedError

Seems like this model can't be exported to onnx ? Which model is compatible with the script you provide, please ?