def load_image(self, idx):
"""
Load input image and preprocess for Caffe:
- resize image
- cast to float
- switch channels RGB -> BGR
- subtract mean
- transpose to channel x height x width order
"""
idx=idx.split()[0]
try:
im = Image.open('{}/{}'.format(self.data_dir, idx))
except:
from skimage import io
im = io.imread('{}/{}'.format(self.data_dir, idx))
im = Image.fromarray(im)
im=im.resize((self.width, self.height), Image.ANTIALIAS) # resize image
im = np.array(im, dtype=np.float32) # cast to float
im = im[:,:,::-1] # RGB -> BGR
im -= self.mean # mean subtraction
# bring colour to the innermost dimension
im = im.transpose((2,0,1))
return im
评论列表
文章目录