Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 基于神经结构学习的fit_发生器问题_Python 3.x_Tensorflow_Keras_Conv Neural Network_Nsl - Fatal编程技术网

Python 3.x 基于神经结构学习的fit_发生器问题

Python 3.x 基于神经结构学习的fit_发生器问题,python-3.x,tensorflow,keras,conv-neural-network,nsl,Python 3.x,Tensorflow,Keras,Conv Neural Network,Nsl,我花了两天时间尝试使用神经结构语言来适应我的CNN模型我使用ImageDataGenerator和flow_从_目录使用Model.fit_generator时收到一条错误消息: 值错误: 当以数组形式传递输入数据时,不要指定 steps\u per\u epoch/steps参数。请改用batch\u size 我使用Keras2.3.1和TensorFlow 2.0作为后端 这是我的代码片段: num_classes = 4 img_rows, img_cols = 224, 224 bat

我花了两天时间尝试使用神经结构语言来适应我的CNN模型我使用ImageDataGenerator和flow_从_目录使用Model.fit_generator时收到一条错误消息: 值错误:

当以数组形式传递输入数据时,不要指定
steps\u per\u epoch
/
steps
参数。请改用
batch\u size

我使用Keras2.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)格式生成的数据改编成字典格式
我认为也有同样的错误。也许你应该考虑使用<代码>模型.FIT()/<代码>函数。在这种情况下,您应该定义
列车输入
列车标签和
批量大小
。为了找出
fit
fit\u generator
之间的区别,您可以这样做。

您是否尝试将您作为参数BATCH\u SIZE来替代?不幸的是,我不能使用model.fit,因为我有一个大数据集。您确定fit\u generator也需要这种类型的输入吗?你试过输入两个数组的列表吗?想一想你的回答神经结构学习假设它的输入批次是一个包含x和y的字典,而ImageDataGenerator生成(x,y)元组的输入,这就是为什么我使用convert_training_data_generator来解决这个问题,现在我得到了这个错误值error:Layer model_1是用一个不是符号张量的输入调用的。收到的类型:。完整输入:[{'feature':}]。层的所有输入都应该是张量。
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)