Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
AbdulSamadMalik opened this issue May 16, 2023 · 2 comments

Comments

@AbdulSamadMalik
Copy link

AbdulSamadMalik commented May 16, 2023

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,)
@hpc203
Copy link
Owner

hpc203 commented May 16, 2023

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

@AbdulSamadMalik
Copy link
Author

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

@AbdulSamadMalik AbdulSamadMalik changed the title Please explain why this error is occurring when I'm running the main.py after cloning this repo, thanks. Please explain why this error: ValueError operands could not be broadcast together with shapes (6400,) (1600,) May 16, 2023
@AbdulSamadMalik AbdulSamadMalik changed the title Please explain why this error: ValueError operands could not be broadcast together with shapes (6400,) (1600,) Please explain this error: ValueError operands could not be broadcast together with shapes (6400,) (1600,) May 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants