您的输入数据用完了;中断训练。确保您的数据集或生成器至少可以生成`steps_per_epoch

时间:2020-10-12 11:33:16

标签: python tensorflow machine-learning keras

当我训练自动驾驶汽车模型时,在第一个时期给了我错误。虽然当我减少batch_size时,它工作正常。但这并没有给我我想要的准确性。

我正在Google Collab中训练我的模型。

tensorflow版本2.3.1

错误:

error

WARNING:tensorflow:Your input ran out of data; interrupting training. Make sure that your dataset or generator can generate at least `steps_per_epoch * epochs` batches (in this case, 20000 batches). You may need to use the repeat() function when building your dataset.

我的代码:

def modified_model():
  model = Sequential()
  model.add(Conv2D(60, (5, 5), input_shape=(32, 32, 1), activation='relu'))
  model.add(Conv2D(60, (5, 5), activation='relu'))
  model.add(MaxPooling2D(pool_size=(2, 2)))
  
  model.add(Conv2D(30, (3, 3), activation='relu'))
  model.add(Conv2D(30, (3, 3), activation='relu'))
  model.add(MaxPooling2D(pool_size=(2, 2)))
  
  model.add(Flatten())
  model.add(Dense(500, activation='relu'))
  model.add(Dropout(0.5))
  model.add(Dense(43, activation='softmax'))
  
  model.compile(Adam(lr = 0.001), loss='categorical_crossentropy', metrics=['accuracy'])
  return model
model = modified_model()
print(model.summary())

history = model.fit_generator(datagen.flow(X_train, y_train, batch_size=50),
                            steps_per_epoch=2000,
                            epochs=10,
                            validation_data=(X_val, y_val), shuffle = 1)

1 个答案:

答案 0 :(得分:1)

在使用生成器时,让模型找出实际上要涵盖一个纪元的步骤数,否则必须计算steps_per_epoch=(data_samples/batch_size)。尝试在没有step_per_epoch参数的情况下运行

相关问题