insightface icon indicating copy to clipboard operation
insightface copied to clipboard

scrfd how to convert to onnx?

Open fisakhan opened this issue 3 years ago • 16 comments

While using scrfd2onnx.py, what should be the values of build_model_from_cfg, generate_inputs_and_wrap_model, and preprocess_example_input in from mmdet.core import (build_model_from_cfg, generate_inputs_and_wrap_model, preprocess_example_input)

fisakhan avatar Jun 09 '21 15:06 fisakhan

Please follow the example from our readme. Default settings should work.

nttstar avatar Jun 10 '21 00:06 nttstar

I receive the following error

ImportError: cannot import name 'build_model_from_cfg'

Even though I can run the following example from mmdetection successfully

from mmdet.apis import init_detector, inference_detector, show_result_pyplot

config_file = 'configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py'
checkpoint_file = 'checkpoints/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth'
device = 'cuda:0'
model = init_detector(config_file, checkpoint_file, device=device)
device = 'cuda:0'
model = init_detector(config_file, checkpoint_file, device=device)
img = 'demo/demo.jpg'
result = inference_detector(model, img)
show_result_pyplot(model, img, result, score_thr=0.3)

fisakhan avatar Jun 10 '21 17:06 fisakhan

Changing version of mmcv-full to 1.3.3, pip install -v -e . and pip3 install onnx-simplifier solved the problem. But now using scrfdgen2.5g_0.onnx and bboxes, kpss = detector.detect(img, 0.5, input_size = (640, 640)) I get the following output. t1

fisakhan avatar Jun 10 '21 20:06 fisakhan

I am having the same issue, can someone help me to figure this out?

Sarthak-005 avatar Aug 18 '21 03:08 Sarthak-005

Could anyone could convert scrfd model to onnx. examples are not working:

Traceback (most recent call last): File "", line 2, in File "/opt/conda/lib/python3.7/site-packages/mmcv/utils/registry.py", line 212, in build return self.build_func(*args, **kwargs, registry=self) File "/opt/conda/lib/python3.7/site-packages/mmcv/cnn/builder.py", line 27, in build_model_from_cfg return build_from_cfg(cfg, registry, default_args) File "/opt/conda/lib/python3.7/site-packages/mmcv/utils/registry.py", line 45, in build_from_cfg f'{obj_type} is not in the {registry.name} registry') KeyError: 'SCRFD is not in the models registry'

schliffen avatar Nov 08 '21 09:11 schliffen

@schliffen please run https://github.com/deepinsight/insightface/blob/master/detection/scrfd/tools/scrfd2onnx.py to generate onnx model

fisakhan avatar Nov 08 '21 11:11 fisakhan

We are using https://github.com/deepinsight/insightface/blob/master/detection/scrfd/tools/scrfd2onnx.py and get the error!

chenscottus avatar Nov 30 '21 02:11 chenscottus

Change from mmdet.core import (build_model_from_cfg, generate_inputs_and_wrap_model, preprocess_example_input) ==>>>>> from mmdet.core.export import build_model_from_cfg, preprocess_example_input, generate_inputs_and_wrap_model

chenscottus avatar Nov 30 '21 02:11 chenscottus

Hi, @chenscottus , Did above suggestion worked?

I did the same but still same error of KeyError: 'SCRFD is not in the models registry'

rahulsharma11 avatar Aug 22 '22 09:08 rahulsharma11

I used "scrfd_2.5g_bnkps.py" as config file when converted the pth to onnx of 'scrfd_2.5g.pth'. Of course, the onnx file is generated. but when check the onnx file, the output is empty. what is issue?

lprfacial247 avatar Dec 06 '22 15:12 lprfacial247

scrfd_2.5g_bnkps.py and scrfd_2.5g.py are same. Only difference is "norm_cfg=dict(type='BN', requires_grad=True)" and "dict(type='GN', num_groups=16, requires_grad=True)". But, after converted pth into onnx with 'bnkps' config file, that onnx does not work. who can help me?

lprfacial247 avatar Dec 06 '22 15:12 lprfacial247

@fisakhan try input_size=(256,256)

ZubairKhan001 avatar Jul 18 '23 11:07 ZubairKhan001

new issue: ModuleNotFoundError: No module named 'mmdet.core'

quanqigu avatar Aug 14 '23 13:08 quanqigu

new issue: ModuleNotFoundError: No module named 'mmdet.core'

image

nobody-cheng avatar Aug 31 '23 07:08 nobody-cheng

Is this problem solved? I still cannot convert the pretrained scrfd_2.5 to onnx. It's still the error KeyError: 'SCRFD is not in the models registry'

thadanguyen avatar Sep 06 '23 14:09 thadanguyen

Is this problem solved? I still cannot convert the pretrained scrfd_2.5 to onnx. It's still the error KeyError: 'SCRFD is not in the models registry'

You need to run /insightface/detection/scrfd/setup.py, but make sure that mmdet is NOT installed yet. The script will install it and automatically set its location to /insightface/detection/scrfd/mmdet, which contains the SCRFD model script file.

alexemme avatar Oct 28 '23 18:10 alexemme