有同样的错误:
File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py", line 1110, in fit
raise ValueError('Expect x to be a non-empty array or dataset.')
ValueError: Expect x to be a non-empty array or dataset.
首先尝试减少批量大小。如果批量大小大于训练数据集,则不创建输入数据集,因此保持为空。但我的情况并非如此。
然后我试图查看我的数据集在哪里变空。我的第一个时代运行良好,但不是另一个。似乎我的数据集在批处理过程中得到了转换。
classes = len(y.unique())
model = Sequential()
model.add(Dense(10, activation='relu',
activity_regularizer=tf.keras.regularizers.l1(0.00001)))
model.add(Dense(classes, activation='softmax', name='y_pred'))
opt = Adam(lr=0.0005, beta_1=0.9, beta_2=0.999)
BATCH_SIZE = 12
train_dataset, validation_dataset =set_batch_size(BATCH_SIZE,train_dataset,validation_dataset)
model.compile(loss='categorical_crossentropy', optimizer=opt, metrics['accuracy'])
model.fit(_train_dataset, epochs=10,validation_data=_validation_dataset,verbose=2, callbacks=callbacks)
这种情况的解决方案:
更新训练和验证数据集的冗余更新,同时通过提供不同的名称将其分批。
前:
train_dataset, validation_dataset = set_batch_size(BATCH_SIZE, train_dataset, validation_dataset)
后:
_train_dataset, _validation_dataset = set_batch_size(BATCH_SIZE, train_dataset, validation_dataset)
classes = len(y.unique())
model = Sequential()
model.add(Dense(10, activation='relu',activity_regularizer=tf.keras.regularizers.l1(0.00001)))
model.add(Dense(classes, activation='softmax', name='y_pred'))
选择 = 亚当(lr=0.0005,beta_1=0.9,beta_2=0.999)
BATCH_SIZE = 12
_train_dataset, _validation_dataset = set_batch_size(BATCH_SIZE, train_dataset, validation_dataset) model.compile(loss='categorical_crossentropy', optimizer=opt, metrics=['accuracy'])
model.fit(_train_dataset, epochs=10, validation_data=_validation_dataset, verbose= 2、回调=回调)
有用链接:https ://code.ihub.org.cn/projects/124/repository/commit_diff?changeset=1fb8f4988d69237879aac4d9e3f268f837dc0221