当我开始训练数据集时弹出输入用完数据错误
Posted
技术标签:
【中文标题】当我开始训练数据集时弹出输入用完数据错误【英文标题】:input ran out of data error popping up when i start training the dataset 【发布时间】:2020-09-07 01:22:00 【问题描述】:我正在寻找运行我的训练集,但是当我尝试运行模型时它不断给出错误它会弹出这个错误“您的输入数据用完了;中断训练。确保您的数据集或生成器可以生成至少steps_per_epoch * epochs
批次(在本例中为 12000 批次)。构建数据集时可能需要使用 repeat() 函数。
在此处输入代码
# 卷积神经网络
# Importing the libraries
import tensorflow as tf
from keras.preprocessing.image import ImageDataGenerator
tf.__version__
# Part 1 - Data Preprocessing
# Generating images for the Training set
train_datagen = ImageDataGenerator(rescale = 1./255,
shear_range = 0.2,
zoom_range = 0.2,
horizontal_flip = True)
# Generating images for the Test set
test_datagen = ImageDataGenerator(rescale = 1./255)
# Creating the Training set
training_set = train_datagen.flow_from_directory('dataset/train',
target_size = (64, 64),
batch_size = 32,
class_mode = 'binary')
# Creating the Test set
test_set = test_datagen.flow_from_directory('dataset/test',
target_size = (64, 64),
batch_size = 32,
class_mode = 'binary')
# Part 2 - Building the CNN
# Initialising the CNN
cnn = tf.keras.models.Sequential()
# Step 1 - Convolution
cnn.add(tf.keras.layers.Conv2D(filters=32, kernel_size=3, padding="same", activation="relu", input_shape=[64, 64, 3]))
# Step 2 - Pooling
cnn.add(tf.keras.layers.MaxPool2D(pool_size=2, strides=2, padding='valid'))
# Adding a second convolutional layer
cnn.add(tf.keras.layers.Conv2D(filters=32, kernel_size=3, padding="same", activation="relu"))
cnn.add(tf.keras.layers.MaxPool2D(pool_size=2, strides=2, padding='valid'))
# Step 3 - Flattening
cnn.add(tf.keras.layers.Flatten())
# Step 4 - Full Connection
cnn.add(tf.keras.layers.Dense(units=128, activation='relu'))
# Step 5 - Output Layer
cnn.add(tf.keras.layers.Dense(units=1, activation='sigmoid'))
# Part 3 - Training the CNN
# Compiling the CNN
cnn.compile(optimizer = 'adam', loss = 'binary_crossentropy', metrics = ['accuracy'])
# Training the CNN on the Training set and evaluating it on the Test set
cnn.fit_generator(training_set,
steps_per_epoch = 4000,
epochs = 3,
validation_data = test_set,
validation_steps = 2000)
【问题讨论】:
【参考方案1】:steps_per_epochs
记录了每个时期的 批次 数量,因此实际上您需要验证您的数据集中至少有 steps_per_ecpoh * batch_size
图像(而不是您所写的 steps_per_ecpoh * epochs
)。对于茶和验证数据集都是如此。
一种常见的方法是设置steps_per_ecpoh=floor(len(dataset)/batch_size)
。 ImageDataGenerator
类的默认 batch_size
为 32,您可以通过传递相关参数来更改它。
【讨论】:
以上是关于当我开始训练数据集时弹出输入用完数据错误的主要内容,如果未能解决你的问题,请参考以下文章