输入数据耗尽错误,但数据确实存在

大家好,我在学习CNN时,运行下面的代码时遇到一个问题。

from tensorflow.keras.layers import Flattenfrom tensorflow.keras.models import Sequentialfrom tensorflow.keras.layers import Densefrom tensorflow.keras.layers import Convolution2Dfrom tensorflow.keras.layers import MaxPooling2Dimport pandas as pdimport numpy as npimport matplotlib.pyplot%matplotlib inlinemodel = Sequential()model.add(Convolution2D(32, 3, 3, input_shape=(64, 64, 3), activation='relu')model.add(MaxPooling2D(pool_size=(2,2)))model.add(Convolution2D(32, 3, 3, activation='relu'))model.add(MaxPooling2D(pool_size=(2,2)))model.add(Flatten())model.add(Dense(units = 128, activation = 'relu'))model.add(Dense(units = 1, activation = 'sigmoid'))model.compile(optimizer = 'rmsprop', loss='mse', metrics=['accuracy'])from tensorflow.keras.preprocessing.image import ImageDataGenerator    train_datagen = ImageDataGenerator(    rescale = 1./255,    shear_range=0.2,    zoom_range=0.2,    horizontal_flip=True)test_datagen = ImageDataGenerator(rescale=1./255)training_set = train_datagen.flow_from_directory(    r'C:\Users\Raj Mulati\Downloads\Dev\Machine Learning A-Z New\Part 8 - Deep Learning\Section 40 - Convolutional Neural Networks (CNN)\dataset\training_set',    target_size=(64, 64),    batch_size=32,    class_mode='binary')test_set = test_datagen.flow_from_directory(        r'C:\\Users\Raj Mulati\\Downloads\\Dev\\Machine Learning A-Z New\Part 8 - Deep Learning\\Section 40 - Convolutional Neural Networks (CNN)\\dataset\\test_set',    target_size=(64, 64),    batch_size=32,    class_mode='binary')model.fit_generator(    training_set,    steps_per_epoch=8000,    epochs=25,    validation_data=test_set,    validation_steps=2000 )

我得到的错误是:

Found 8000 images belonging to 2 classes.Found 2000 images belonging to 2 classes.WARNING:tensorflow:sample_weight modes were coerced from  ...    to    ['...']WARNING:tensorflow:sample_weight modes were coerced from  ...    to    ['...']Train for 8000 steps, validate for 2000 stepsEpoch 1/25 250/8000 [..............................] - ETA: 14:37 - loss: 0.2485 - accuracy: 0.5340WARNING: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, 200000 batches). You may need to use the repeat() function when building your dataset.<tensorflow.python.keras.callbacks.History at 0x234d9fec3c8>

回答:

每一步会处理一整批图像,即如果你的batch_size是32,那么在250步后(250 * 32 = 8000)数据就会用完。请这样设置你的steps_per_epochvalidation_steps

model.fit_generator(    training_set,    steps_per_epoch=8000//32,    epochs=25,    validation_data=test_set,    validation_steps=2000//32 )

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注