deepcam-cn / yolov5-face

YOLO5Face: Why Reinventing a Face Detector (https://arxiv.org/abs/2105.12931) ECCV Workshops 2022)
GNU General Public License v3.0
2.04k stars 495 forks source link

您好,大佬,如何把人脸检测的模型转成torchscript模型啊 #169

Open wuxiaolianggit opened 2 years ago

wuxiaolianggit commented 2 years ago

您好,大佬,如何把人脸检测的模型转成torchscript模型啊 @djmmoss @muhammad-tayyab @hylrh2008 @bobo0810 @wjtan99

bobo0810 commented 2 years ago

您好,大佬,如何把人脸检测的模型转成torchscript模型啊 @djmmoss @muhammad-tayyab @hylrh2008 @bobo0810 @wjtan99

参考https://github.com/bobo0810/Classification/blob/main/Models/Backend/torchscript.py image

wuxiaolianggit commented 2 years ago

@好的,大佬,多谢啊,我试一下啊 ,大佬我好像有你的微信。@ @bobo0810

wuxiaolianggit commented 2 years ago

Traceback (most recent call last): File "D:/python_code/yolov5-face-master/detect_face_jit.py", line 152, in detect_one(model, opt.image, device) File "D:/python_code/yolov5-face-master/detect_face_jit.py", line 108, in detect_one pred = model(img)[0] File "E:\python_code\pytorch-image-classification\venv\lib\site-packages\torch\nn\modules\module.py", line 727, in _call_impl result = self.forward(*input, **kwargs) RuntimeError: The following operation failed in the TorchScript interpreter. Traceback of TorchScript, serialized code (most recent call last): File "code/torch/models/yolo.py", line 44, in forward _34 = (_4).forward(_33, ) _35 = (_2).forward((_3).forward(_34, ), _28, ) _36 = (_0).forward(_32, _34, (_1).forward(_35, ), )


    _37, _38, _39, _40, = _36
    return (_40, [_37, _38, _39])
  File "code/__torch__/models/yolo.py", line 76, in forward
    _53 = torch.sigmoid(torch.index(_49, _52))
    _54 = torch.to(CONSTANTS.c0, torch.device("cuda"), 4, False, False, None)
    _55 = torch.view(_53, [3, 100, 100, 6])
          ~~~~~~~~~~ <--- HERE
    _56 = torch.to(_54, dtype=4, layout=0, device=torch.device("cuda:0"), pin_memory=None, non_blocking=False, copy=False, memory_format=None)
    _57 = annotate(List[Optional[Tensor]], [None, None, None, None, _56])

Traceback of TorchScript, original code (most recent call last):
D:\python_code\yolov5-face-master\models\yolo.py(88): forward
E:\python_code\pytorch-image-classification\venv\lib\site-packages\torch\nn\modules\module.py(709): _slow_forward
E:\python_code\pytorch-image-classification\venv\lib\site-packages\torch\nn\modules\module.py(725): _call_impl
D:\python_code\yolov5-face-master\models\yolo.py(196): forward_once
D:\python_code\yolov5-face-master\models\yolo.py(180): forward
E:\python_code\pytorch-image-classification\venv\lib\site-packages\torch\nn\modules\module.py(709): _slow_forward
E:\python_code\pytorch-image-classification\venv\lib\site-packages\torch\nn\modules\module.py(725): _call_impl
E:\python_code\pytorch-image-classification\venv\lib\site-packages\torch\jit\_trace.py(934): trace_module
E:\python_code\pytorch-image-classification\venv\lib\site-packages\torch\jit\_trace.py(733): trace
D:/python_code/yolov5-face-master/export2.py(89): <module>
RuntimeError: shape '[3, 100, 100, 6]' is invalid for input of size 108000

转换成功,但是推理的时候会报错,这个怎么解决啊,大佬@ @bobo0810 
bobo0810 commented 2 years ago

尝试debug排查原因吧

wuxiaolianggit commented 2 years ago

好的,多谢大佬 @bobo0810

muhammad-tayyab commented 2 years ago

The model will generate face feature points (16 size vector) in addition to bounding box and non-max-suppression is a bit different than standard Yolov5. So if you plan to use torchscript model in another app, you need to add that functionality too, otherwise you will not be able to get good quality detections

wuxiaolianggit commented 2 years ago

Thank you for your reply. I understand. @muhammad-tayyab