import numpy as np
import pandas as pd
import tensorflow as tf
import keras.preprocessing.image as process_im
from keras.applications import vgg19
from keras.models import Model
from tensorflow.python.keras import models
from tensorflow.python.keras import losses
from tensorflow.python.keras import layers
from tensorflow.python.keras import backend as k
from PIL import Image # Python Image Libraryimport matplotlib.pyplot as plt # 可视化库import functools # 用以为可调用对象(callable objects)定义高阶函数或操作import IPython.display # python的交互式shell
图像预处理
PIL中的image对象调用resize方法,此处将图像进行缩放为某高宽的高质量图像
img_to_array转换前后类型都是一样的,唯一区别是转换前元素类型是整型,转换后元素类型是浮点型(和keras等机器学习框架相适应的图像类型。Keras introduced a special function called img_to_array which accepts an input image and then orders the channels correctly based on the image_data_format setting)