yolov5-face icon indicating copy to clipboard operation
yolov5-face copied to clipboard

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

Open wuxiaolianggit opened this issue 2 years ago • 7 comments

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

wuxiaolianggit avatar May 26 '22 09:05 wuxiaolianggit

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

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

bobo0810 avatar May 26 '22 09:05 bobo0810

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

wuxiaolianggit avatar May 26 '22 09:05 wuxiaolianggit

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, ), ) ~~~~~~~~~~~ <--- HERE _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): RuntimeError: shape '[3, 100, 100, 6]' is invalid for input of size 108000

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

wuxiaolianggit avatar May 26 '22 09:05 wuxiaolianggit

尝试debug排查原因吧

bobo0810 avatar May 26 '22 09:05 bobo0810

好的,多谢大佬 @bobo0810

wuxiaolianggit avatar May 26 '22 10:05 wuxiaolianggit

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

muhammad-tayyab avatar May 26 '22 11:05 muhammad-tayyab

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

wuxiaolianggit avatar May 27 '22 00:05 wuxiaolianggit