YOLO_v3_tutorial_from_scratch icon indicating copy to clipboard operation
YOLO_v3_tutorial_from_scratch copied to clipboard

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

Open SanftMonster opened this issue 5 years ago • 1 comments

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?

SanftMonster avatar Aug 07 '20 01:08 SanftMonster

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

bot66 avatar Aug 10 '20 01:08 bot66