TypeError:flow_from_directory()获得了意外的关键字参数'train_data_dir'

时间:2019-10-02 14:02:04

标签: python-3.x keras directory arguments keyword

我需要帮助。

我尝试运行此代码,但出现此错误:

  

TypeError:flow_from_directory()得到了意外的关键字参数'train_data_dir'

有人有这个问题并且有正确的解决方案吗?

谢谢

train_datagenerator = ImageDataGenerator(rescale=1./255,
    shear_range=0.2,
    zoom_range=0.2,
    horizontal_flip=True,
    validation_split=0.2)
train_generator = train_datagenerator.flow_from_directory(
    train_data_dir = '.\\Images\\data',
    target_size=(image_size, image_size), 
    batch_size=BATCH_SIZE_TRAINING,
    class_mode='categorical', subset='training') 
validation_generator = train_datagenerator.flow_from_directory(
    train_data_dir = '.\\Images\\data', 
    target_size=(image_size, image_size), 
    batch_size=BATCH_SIZE_TRAINING,
    class_mode='categorical', subset='validation')

1 个答案:

答案 0 :(得分:0)

flow_from_directory方法中没有train_data_dir参数。用目录替换train_data_dir,它应该可以工作。请参阅https://keras.io/api/preprocessing/image/

train_datagenerator = ImageDataGenerator(rescale=1./255,
    shear_range=0.2,
    zoom_range=0.2,
    horizontal_flip=True,
    validation_split=0.2)
train_generator = train_datagenerator.flow_from_directory(
    directory = '.\\Images\\data',
    target_size=(image_size, image_size), 
    batch_size=BATCH_SIZE_TRAINING,
    class_mode='categorical', subset='training')