我有兴趣通过随机图像转换来增强我的数据集。我正在使用 Keras图像数据生成器 https://keras.io/preprocessing/image/#imagedatagenerator,并且我在尝试申请时收到以下错误random_transform
到单个图像:
--> x = apply_transform(x, transform matrix, img_channel_axis, fill_mode, cval)
>>> RuntimeError: affine matrix has wrong number of rows.
我找到了 ImageDataGenerator 的源代码here https://github.com/fchollet/keras/blob/master/keras/preprocessing/image.py。但是,我不确定如何调试运行时错误。下面是我的代码:
from keras.preprocessing.image import img_to_array, load_img
from keras.preprocessing.image import ImageDataGenerator
from keras.applications.inception_v3 import preprocess_input
image_path = './figures/zebra.jpg'
#data augmentation
train_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')
print "\nloading image..."
image = load_img(image_path, target_size=(299, 299))
image = img_to_array(image)
image = np.expand_dims(image, axis=0) # 1 x input_shape
image = preprocess_input(image)
train_datagen.fit(image)
image = train_datagen.random_transform(image)
调用时出现最后一行错误random_transform
.