I'm trying to load an image, but I'm encountering the following error:
im = im[:, :, ::-1] # change to BGR IndexError: too many indices for array
I read the image file by :
....
....
im = np.asarray(Image.open(
osp.join(self.data_root, image_file_name)))
im = scipy.misc.imresize(im, self.im_shape) # resize
return self.transformer.preprocess(im)
And here is the function that yelds the error:
def preprocess(self, im):
im = np.float32(im)
im = im[:, :, ::-1] # change to BGR
im -= self.mean
im *= self.scale
im = im.transpose((2, 0, 1))
return im
I don't understand what's wrong. Any help would be appreciated.
im.shape
? – Andras Deak Mar 18 '17 at 15:27self.im_shape
. So what isself.im_shape
? I suspect it's a 2-element sequence. – Andras Deak Mar 18 '17 at 15:29im.shape
after callingimresize
on it. The result is probably a 2d array, in which case you should pass[227,227,3]
asself.im_shape
(although I'm guessing). Also, side note:im=im.astype(np.float32)
is probably more idiomatic. – Andras Deak Mar 18 '17 at 15:34