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

Encoding error by ultralytics prediction #39

Closed
SamuelHafner opened this issue May 13, 2024 · 5 comments
Closed

Encoding error by ultralytics prediction #39

SamuelHafner opened this issue May 13, 2024 · 5 comments

Comments

@SamuelHafner
Copy link

Hi @mgonzs13,

thank you for your great work!!!

I have an error when when running the yolov8_node the self.yolo.predict cause an error (tried on 2 different cameras):

[yolov8_node-1] RuntimeError: Given groups=1, weight of size [48, 3, 3, 3], expected input[1, 4, 384, 640] to have 3 channels, but got 4 channels instead

I could fix this after i changed the desired encoding on the cv2_bridge:
from:

self.cv_bridge.imgmsg_to_cv2(msg)

to

self.cv_bridge.imgmsg_to_cv2(msg, desired_encoding='bgr8')

should we maybe add this permanent or is there some reason this encoding is empty?

@mgonzs13
Copy link
Owner

mgonzs13 commented May 14, 2024

Hey @SamuelHafner, thanks for the issue. A better solution could be as follows. Can you try it?

cv_image = self.cv_bridge.imgmsg_to_cv2(msg, desired_encoding=msg.encoding)

@SamuelHafner
Copy link
Author

SamuelHafner commented May 14, 2024

Hey @mgonzs13, thanks for your fast response.
It is also not working because in my case I have an image with the encoding bgra8 and therefore an cv_image shape of (360, 640, 4). It has the alpha value too.

If I change the desired encoding for the image to bgr8 it converts the cv_image with the shape (360, 480, 3). And therefore this works for the yolo package
And I think that the yolo package can only handle images without alpha

@mgonzs13
Copy link
Owner

If you don't want to modify yolov8_ros, you can try to add a node to remove the alpha channel and republish the image as bgr8.

@SamuelHafner
Copy link
Author

Yeah i could. But I added this desired_endcoding permanent now.
Would you like this change too? Should I do an merge request or just let it local.
Because normally you always would need an bgr8 encoding.

Btw. these recordings are from robocup@home 2023 right? We also were there. Which team? :)

@mgonzs13
Copy link
Owner

I'd rather create a new node to filter the alpha channel or modify the yolov8 node to remove it since there are cameras that do not use bgr8. Those bags were provided to me by the Gentlebots team.

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