Skip to content

yolov4 export onnx get wrong #1169

@zys1994

Description

@zys1994

when i train yolov4 ,i replace mish with leaky. when i convert the model to onnx,it get wrong like that.
my environment is pytorch1.5,onnx-1.7

Namespace(agnostic_nms=False, augment=False, cfg='pre_model/yolov4-facemask-leakly.cfg', classes=None, conf_thres=0.3, device='', fourcc='mp4v', half=False, img_size=416, iou_thres=0.6, names='pre_model/obj.name', output='output', save_txt=False, source='data/samples', view_img=False, weights='pre_model/yolov4-facemask-leakly_best.weights')
Using CPU

Fusing layers...
/home/bill.zeng/dl_base/object-det/yolov3-pytorch/utils/layers.py:60: 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 nx == na:  # same shape
Traceback (most recent call last):
  File "detect.py", line 187, in <module>
    detect()
  File "detect.py", line 48, in detect
    input_names=['images'], output_names=['classes', 'boxes'])
  File "/home/bill.zeng/softmare/anaconda3/lib/python3.6/site-packages/torch/onnx/__init__.py", line 168, in export
    custom_opsets, enable_onnx_checker, use_external_data_format)
  File "/home/bill.zeng/softmare/anaconda3/lib/python3.6/site-packages/torch/onnx/utils.py", line 69, in export
    use_external_data_format=use_external_data_format)
  File "/home/bill.zeng/softmare/anaconda3/lib/python3.6/site-packages/torch/onnx/utils.py", line 488, in _export
    fixed_batch_size=fixed_batch_size)
  File "/home/bill.zeng/softmare/anaconda3/lib/python3.6/site-packages/torch/onnx/utils.py", line 334, in _model_to_graph
    graph, torch_out = _trace_and_get_graph_from_model(model, args, training)
  File "/home/bill.zeng/softmare/anaconda3/lib/python3.6/site-packages/torch/onnx/utils.py", line 291, in _trace_and_get_graph_from_model
    torch.jit._get_trace_graph(model, args, _force_outplace=False, _return_inputs_states=True)
  File "/home/bill.zeng/softmare/anaconda3/lib/python3.6/site-packages/torch/jit/__init__.py", line 278, in _get_trace_graph
    outs = ONNXTracedModule(f, _force_outplace, return_inputs, _return_inputs_states)(*args, **kwargs)
  File "/home/bill.zeng/softmare/anaconda3/lib/python3.6/site-packages/torch/nn/modules/module.py", line 550, in __call__
    result = self.forward(*input, **kwargs)
  File "/home/bill.zeng/softmare/anaconda3/lib/python3.6/site-packages/torch/jit/__init__.py", line 361, in forward
    self._force_outplace,
  File "/home/bill.zeng/softmare/anaconda3/lib/python3.6/site-packages/torch/jit/__init__.py", line 348, in wrapper
    outs.append(self.inner(*trace_inputs))
  File "/home/bill.zeng/softmare/anaconda3/lib/python3.6/site-packages/torch/nn/modules/module.py", line 548, in __call__
    result = self._slow_forward(*input, **kwargs)
  File "/home/bill.zeng/softmare/anaconda3/lib/python3.6/site-packages/torch/nn/modules/module.py", line 534, in _slow_forward
    result = self.forward(*input, **kwargs)
  File "/home/bill.zeng/dl_base/object-det/yolov3-pytorch/models.py", line 238, in forward
    return self.forward_once(x)
  File "/home/bill.zeng/dl_base/object-det/yolov3-pytorch/models.py", line 292, in forward_once
    x = module(x)
  File "/home/bill.zeng/softmare/anaconda3/lib/python3.6/site-packages/torch/nn/modules/module.py", line 548, in __call__
    result = self._slow_forward(*input, **kwargs)
  File "/home/bill.zeng/softmare/anaconda3/lib/python3.6/site-packages/torch/nn/modules/module.py", line 534, in _slow_forward
    result = self.forward(*input, **kwargs)
  File "/home/bill.zeng/softmare/anaconda3/lib/python3.6/site-packages/torch/nn/modules/upsampling.py", line 131, in forward
    return F.interpolate(input, self.size, self.scale_factor, self.mode, self.align_corners)
  File "/home/bill.zeng/softmare/anaconda3/lib/python3.6/site-packages/torch/nn/functional.py", line 2991, in interpolate
    scale_factor_list[0], scale_factor_list[1])
RuntimeError: Input and output sizes should be greater than 0, but got input (H: 10, W: 6) output (H: 0, W: 0)

Metadata

Metadata

Assignees

No one assigned

    Labels

    StaleStale and schedule for closing soon

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions