keras flow_from_dataframe图像调整大小错误

时间:2020-05-16 14:35:29

标签: python image-processing keras

我将keras flow_from_dataframe与ImageGenerator一起使用,如下所示:

from keras.preprocessing import image
train_data_gen=image.ImageDataGenerator(rescale=1.0/255,featurewise_center=True,
                                        featurewise_std_normalization=True, rotation_range=5,
                                        horizontal_flip=True, validation_split=0.2,brightness_range=[-0.2,0.2],
                                        preprocessing_function=image_affine_transform)
train_data_gen.flow_from_dataframe(dataframe=input_df, directory='<dir_location',
                                   x_col='ID', y_col=['x0','y0','x1','y1'], class_mode='raw',color_mode='rgb',
                                    target_size=(128,128), batch_size=1)

ID是image_id的地方。 preprocessing_function=image_affine_transform执行以下操作:

def image_affine_transform(img):
    return (image.apply_affine_transform(img_array,theta=2, tx=0, ty=0, shear=5,
                                         zx=1, zy=1, row_axis=0, col_axis=1, channel_axis=2, fill_mode='nearest', 
                                         cval=0.0, order=1))

我看到如下错误消息:

ValueError: could not broadcast input array from shape (308,1050,3) into shape (128,128,3)

我确实验证了输入图像为(308,1050,3),因此似乎无法使用(128,128,3)函数将图像调整为image_affine_transform。如果没有image_affine_transform函数,则生成器正在运行。不清楚我在使用image_affine_transform时会引入什么错误...谢谢!

0 个答案:

没有答案