0

我花了两天时间尝试使用神经结构化语言来适应我的 CNN 模型我使用 ImageDataGenerator 和 flow_from_directory 当我使用 model.fit_generator 我收到一条错误消息:ValueError:

将输入数据作为数组传递时,不要指定 steps_per_epoch/steps参数。请batch_size改用。

我使用 Keras 2.3.1 和 TensorFlow 2.0 作为后端

这是我的代码的片段:

num_classes = 4
img_rows, img_cols = 224, 224
batch_size = 16

train_datagen = ImageDataGenerator(
  rescale=1./255,
  rotation_range=30,
  width_shift_range=0.3,
  height_shift_range=0.3,
  horizontal_flip=True,
  fill_mode='nearest')

  validation_datagen = ImageDataGenerator(rescale=1./255)
  train_generator = train_datagen.flow_from_directory(
    train_data_dir,
    target_size=(img_rows, img_cols),
    batch_size=batch_size, shuffle=True,
    class_mode='categorical')

    validation_generator = validation_datagen.flow_from_directory(
    validation_data_dir,
    target_size=(img_rows, img_cols),
    batch_size=batch_size, shuffle=True,
    class_mode='categorical')

    def vgg():
      model1 = Sequential([ ])
      return model1

base_model = vgg()

我将从 (x,y) 格式生成的数据改编为字典格式

def convert_training_data_generator():
   for x ,y in train_generator:
    return {'feature': x, 'label':y}

def convert_testing_data_generator():
   for x ,y in validation_generator:
    return {'feature': x, 'label': y}

adv_config = nsl.configs.make_adv_reg_config(multiplier=0.2, adv_step_size=0.05)
model = nsl.keras.AdversarialRegularization(base_model, adv_config=adv_config)
train= convert_training_data_generator()
test= convert_testing_data_generator()

history = model.fit_generator(train,
   steps_per_epoch= nb_train_samples // batch_size,
    epochs = epochs,
    callbacks = callbacks,
    validation_data = test,
    validation_steps = nb_validation_samples // batch_size)
4

1 回答 1

0

我认为这里有同样的错误。也许您应该考虑使用替代model.fit()功能。在这种情况下,您应该定义train inputyourtrain labelsbatch_size. 为了弄清楚和之间的区别fitfit_generator您可以点击该链接

于 2019-12-07T17:25:35.717 回答