【发布时间】:2017-11-23 18:25:08
【问题描述】:
我有兴趣通过随机图像转换来扩充我的数据集。我正在使用 Keras 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 的源代码。但是,我不确定如何调试运行时错误。以下是我的代码:
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时最后一行出现错误。
【问题讨论】:
标签: computer-vision deep-learning keras