Media-Smart / vedadet

A single stage object detection toolbox based on PyTorch
Apache License 2.0
498 stars 128 forks source link

Failed to convert TinaFace into ONNX format #22

Closed univerone closed 3 years ago

univerone commented 3 years ago

environment

My script

The config file tinaface.py hasn't been modified

    cfg = Config.fromfile("configs/trainval/tinaface/tinaface.py")
    device = 'cpu'
    model = build_detector(cfg.model)
    load_weights(model,"tinaface_r50_fpn_widerface.pth")
    model.to(device)
    model.forward = model.forward_impl
    shape = [3, 800, 1344]
    dummy_input = torch.randn(1, *shape)
    torch2onnx(model, dummy_input, "test.onnx", dynamic_shape=False,
               opset_version=9,
               do_constant_folding=False,
               verbose=False)

Error Log

~/miniconda3/envs/modelci/bin/python ~/github/ML-Model-CI/example/notebook/repo/test2.py
Traceback (most recent call last):
  File "~/github/ML-Model-CI/example/notebook/repo/test2.py", line 33, in <module>
    main()
  File "~/github/ML-Model-CI/example/notebook/repo/test2.py", line 28, in main
    verbose=False)
  File "~/miniconda3/envs/modelci/lib/python3.7/site-packages/volksdep/converters/torch2onnx.py", line 40, in torch2onnx
    output = model(dummy_input)
  File "~/miniconda3/envs/modelci/lib/python3.7/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
    result = self.forward(*input, **kwargs)
  File "~/github/ML-Model-CI/example/notebook/repo/vedadet/models/detectors/single_stage_detector.py", line 35, in forward_impl
    feats = self.backbone(x)
  File "~/miniconda3/envs/modelci/lib/python3.7/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
    result = self.forward(*input, **kwargs)
  File "~/github/ML-Model-CI/example/notebook/repo/vedadet/models/backbones/resnet.py", line 630, in forward
    x = res_layer(x)
  File "~/miniconda3/envs/modelci/lib/python3.7/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
    result = self.forward(*input, **kwargs)
  File "~/miniconda3/envs/modelci/lib/python3.7/site-packages/torch/nn/modules/container.py", line 117, in forward
    input = module(input)
  File "~/miniconda3/envs/modelci/lib/python3.7/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
    result = self.forward(*input, **kwargs)
  File "~/github/ML-Model-CI/example/notebook/repo/vedadet/models/backbones/resnet.py", line 297, in forward
    out = _inner_forward(x)
  File "~/github/ML-Model-CI/example/notebook/repo/vedadet/models/backbones/resnet.py", line 274, in _inner_forward
    out = self.conv2(out)
  File "~/miniconda3/envs/modelci/lib/python3.7/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
    result = self.forward(*input, **kwargs)
  File "~repo/vedadet/ops/dcn/deform_conv.py", line 302, in forward
    self.dilation, self.groups, self.deformable_groups)
  File "~/repo/vedadet/ops/dcn/deform_conv.py", line 46, in forward
    raise NotImplementedError
NotImplementedError

Process finished with exit code 1
univerone commented 3 years ago

I have noticed that in the README

Here are some unsupported operations for model conversion.

  • GN
  • Deformable Conv

This maybe the case

hxcai commented 3 years ago

@univerone Tinaface can not be converted to onnx because of the dcn and gn operation.

univerone commented 3 years ago

@univerone Tinaface can not be converted to onnx because of the dcn and gn operation.

Thanks for your reply