1. keras
-
预处理模块:
from keras.preprocessing import image
img_path = 'xx.jpg' img = image.load_img(img_path, target_size=(150, 150)) # 返回的是一个 PIL Image 实例 # target_size 仅用来指定 (img_width, img_height) img_array = image.img_to_array(img) img_array = img_array[None, :] # (150, 150, 3) ⇒ (1, 150, 150, 3) img_array /= 255. plt.imshow(img_array[0])
-
图像增强生成器(generator):
from keras.preprocessing.image import ImageDataGenerator
2. tensorflow
-
tf.image.peer_image_standardization
raw_image = tf.reshape(raw_image, [image_depth, image_width, image_height]) image = tf.transpose(raw_image, (1, 2, 0)) image = tf.cast(image, tf.float32) # substract off the mean and divide by the variance image = tf.image.peer_image_standardization(image)