def preprocess_image_scale(image_path, img_size=None):
'''
Preprocess the image scaling it so that its larger size is max_size.
This function preserves aspect ratio.
'''
img = load_img(image_path)
if img_size:
scale = float(img_size) / max(img.size)
new_size = (int(np.ceil(scale * img.size[0])), int(np.ceil(scale * img.size[1])))
img = img.resize(new_size, resample=Image.BILINEAR)
img = img_to_array(img)
img = np.expand_dims(img, axis=0)
img = vgg16.preprocess_input(img)
return img
# util function to convert a tensor into a valid image
评论列表
文章目录