def preproc_img(img, mean, imageSz): img = img.astype(np.float32, copy=False) img = image_io.resize_image(img, (imageSz, imageSz)) img = img.transpose((2, 0, 1)) img = img[(2, 1, 0), :, :] img *= 255 # input image is in range(0,1) if mean.ndim == 1: mean = mean[:, np.newaxis, np.newaxis] img -= mean img = img[(2, 1, 0), :, :] img = img[np.newaxis, :] return img
def preproc_img(img, mean, imageSz, crop_size): img = img.astype(np.float32, copy=False) img = image_io.resize_image(img, imageSz) h_off = (imageSz[0] - crop_size) / 2 w_off = (imageSz[1] - crop_size) / 2 img = img[h_off:h_off + crop_size, w_off:w_off + crop_size, :] img = img.transpose((2, 0, 1)) img = img[(2, 1, 0), :, :] img *= 255 # input image is in range(0,1) if mean.ndim == 1: mean = mean[:, np.newaxis, np.newaxis] img -= mean return img