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

Why do we reverse the final dim of the image in "prep_image"? #66

Open
AsakusaRinne opened this issue Aug 7, 2020 · 1 comment
Open

Comments

@AsakusaRinne
Copy link

In this tutorial, there is a function preparing the image as below:
`def prep_image(img, inp_dim):
"""
Prepare image for inputting to the neural network.

Returns a Variable 
"""

img = cv2.resize(img, (inp_dim, inp_dim))
img = img[:,:,::-1].transpose((2,0,1)).copy()
img = torch.from_numpy(img).float().div(255.0).unsqueeze(0)
return img`

We use this line to reverse the final dim of img and transpose it:
img = img[:,:,::-1].transpose((2,0,1)).copy()
I know that we transpose it because we want the channels in order of RGB. But why should we reverse it first?

@bot66
Copy link

bot66 commented Aug 10, 2020

opencv read in image format is BGR, so reverse the final dim convert to RGB format.

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