hpc203 / yolov8-face-landmarks-opencv-dnn

使用OpenCV部署yolov8检测人脸和关键点以及人脸质量评价,包含C++和Python两个版本的程序,只依赖opencv库就可以运行,彻底摆脱对任何深度学习框架的依赖。

Repository from Github https://github.comhpc203/yolov8-face-landmarks-opencv-dnnRepository from Github https://github.comhpc203/yolov8-face-landmarks-opencv-dnn

Please explain this error: ValueError operands could not be broadcast together with shapes (6400,) (1600,)

AbdulSamadMalik opened this issue · comments

I'm running main.py and getting this error.

yolov8-face-landmarks-opencv-dnn on main via 🐍 v3.8.10
❯ py main.py
Traceback (most recent call last):
  File "main.py", line 171, in <module>
    boxes, scores, classids, kpts = YOLOv8_face_detector.detect(srcimg)
  File "main.py", line 75, in detect
    det_bboxes, det_conf, det_classid, landmarks = self.post_process(outputs, scale_h, scale_w, padh, padw)
  File "main.py", line 92, in post_process
    bbox = self.distance2bbox(anchors, bbox_pred, max_shape=(self.input_height, self.input_width)) * stride
  File "main.py", line 134, in distance2bbox
    x1 = points[:, 0] - distance[:, 0]
ValueError: operands could not be broadcast together with shapes (6400,) (1600,)
yolov8-face-landmarks-opencv-dnn on main via 🐍 v3.8.10
❯ py main.py
Traceback (most recent call last):
  File "main.py", line 171, in <module>
    boxes, scores, classids, kpts = YOLOv8_face_detector.detect(srcimg)
  File "main.py", line 75, in detect
    det_bboxes, det_conf, det_classid, landmarks = self.post_process(outputs, scale_h, scale_w, padh, padw)
  File "main.py", line 92, in post_process
    bbox = self.distance2bbox(anchors, bbox_pred, max_shape=(self.input_height, self.input_width)) * stride
  File "main.py", line 134, in distance2bbox
    x1 = points[:, 0] - distance[:, 0]
ValueError: operands could not be broadcast together with shapes (6400,) (1600,)

6400=80x80,1600=40x40,说明特征图的尺寸跟grid_anchor的尺寸不一致,原因是在python版本的opencv4.7.0里,forward函数输出特征图的尺寸,分别是40x40,20x20,80x80,我在main.py的注释里有说明这一点的。不过我已经更新了main.py,在初始化函数里生成的anchors是一个字典,字典的key是下采样尺度stride,这样在后处理函数里,根据特征图的尺寸跟输入分辨率计算出当前特征图的下采样尺度stride,根据当前的stride从anchors里提取到当前anchor,然后decode

非常感谢,它解决了错误。