0
from keras.preprocessing.image import ImageDataGenerator, array_to_img, img_to_array, load_img

datagen = ImageDataGenerator(
        rotation_range=40,
        width_shift_range=0.2,
        height_shift_range=0.2,
        shear_range=0.2,
        zoom_range=0.2,
        horizontal_flip=True,
        fill_mode='nearest')

img = load_img('data/train/cats/cat.0.jpg')  # this is a PIL image
x = img_to_array(img)  # this is a Numpy array with shape (3, 150, 150)
x = x.reshape((1,) + x.shape)  # this is a Numpy array with shape (1, 3, 150, 150)

I don't know why we reshape and make its shape to (1, 3, 150, 150) as in line X = x.reshape((1,) + x.shape)and what 1 means here and what is the benefit of that. This example is from https://blog.keras.io/building-powerful-image-classification-models-using-very-little-data.html

4

1 回答 1

0

3 是通道数(R、G 和 B),150 是图像的宽度/高度,1 是批量的大小

通常,像神经网络这样的机器学习方法一次处理多个图像。如果您一次处理 n 个图像,则 n 是您的批量大小,并且您的张量将具有 ( n , 3, 150, 150) 的形状。

于 2020-08-27T13:00:31.207 回答