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

RGB inputs or BGR inputs for model.predict(img)? #39

Closed
BryanGuillaume opened this issue Feb 24, 2023 · 4 comments
Closed

RGB inputs or BGR inputs for model.predict(img)? #39

BryanGuillaume opened this issue Feb 24, 2023 · 4 comments

Comments

@BryanGuillaume
Copy link

First, thanks for this great work and for sharing your code.

In the running example,

img = cv2.imread('/path/to/image.jpg')
pitch, yaw, roll = model.predict(img)

the image is loaded as a BGR numpy array, as it is the default mode of OpenCV. However, I think the model training has been done using RGB numpy arrays as the images were opened using PIL.Image.Open. Thus, I am wondering if we should convert the BGR arrays into RGB arrays before using them as input for the model.

Would you mind clarifying this?

@thohemp
Copy link
Owner

thohemp commented Feb 27, 2023

Hello,

the predict method converts the image into RGB. So it's okay, to pass a BGR array.
https://github.com/thohemp/6DRepNet/blob/master/sixdrepnet/regressor.py#L67

@BryanGuillaume
Copy link
Author

Hello,

Thanks for your reply. I have already seen that in the code. The problem is the line above (https://github.com/thohemp/6DRepNet/blob/master/sixdrepnet/regressor.py#L66):

img = Image.fromarray(img)

that, I think, by default, converts an array with three channels into an RGB PIL image as it does not now which channel is what color. Thus img is already an RGB PIL image but with its R and B channels inverted. Convertimg it to an RGB PIL image should not invert its channels. Though I might be wrong. If I have some time today, I will add some print function around the code to check if I am correct or not

@thohemp
Copy link
Owner

thohemp commented Feb 27, 2023

You are correct, I just tested it. Swapping channels before using PIL should fix this:

img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)

Thanks!

@BryanGuillaume
Copy link
Author

Thanks for checking this and happy that helped fix a bug at the end!

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