deepinsight / insightface

State-of-the-art 2D and 3D Face Analysis Project
https://insightface.ai
22.84k stars 5.35k forks source link

scrfd how to convert to onnx? #1573

Open fisakhan opened 3 years ago

fisakhan commented 3 years ago

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)

nttstar commented 3 years ago

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

fisakhan commented 3 years ago

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 commented 3 years ago

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

Sarthak-005 commented 3 years ago

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

schliffen commented 2 years ago

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'

fisakhan commented 2 years ago

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

chenscottus commented 2 years ago

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

chenscottus commented 2 years ago

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

rahulsharma11 commented 2 years ago

Hi, @chenscottus , Did above suggestion worked?

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

lprfacial247 commented 1 year ago

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 commented 1 year ago

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?

ZubairKhan001 commented 1 year ago

@fisakhan try input_size=(256,256)

quanqigu commented 1 year ago

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

nobody-cheng commented 1 year ago

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

image

thadanguyen commented 1 year ago

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'

alexemme commented 10 months ago

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.