使用Keras fit_generator的验证准确性为0

时间:2018-09-06 05:54:57

标签: python tensorflow keras keras-2

我最近升级到Keras 2.2.2。对于所有训练时期,验证准确性均为零。我的训练数据具有2个类别的数据样本,即train_data_dir有2个子文件夹。我的验证数据(即val_data_dir)仅具有1个类别的数据样本,但它包含2个子文件夹(每个类别一个),而在一个子文件夹中没有数据样本。我以前使用早期版本的Keras来获得有意义的非零值,以确保验证准确性。请帮助我找出问题所在的代码(如下)和Keras 2.2.2

下面是我的代码的一部分:

train_generator = train_datagen.flow_from_directory(
train_data_dir,
target_size = (img_height, img_width),
batch_size = batch_size, 
class_mode = "categorical")    

validation_generator = val_datagen.flow_from_directory(
val_data_dir,
target_size = (img_height, img_width),
batch_size = batch_size, 
class_mode = "categorical",
save_to_dir = 'home/dir')

nb_train_samples = train_generator.n
nb_validation_samples = validation_generator.n

sample_steps = int(nb_train_samples/batch_size)
validation_steps = int(nb_validation_samples/batch_size)


parallel_model.fit_generator(
train_generator,
steps_per_epoch = sample_steps,
epochs = 1,
validation_data = validation_generator,    
validation_steps = validation_steps,
callbacks=[early])

0 个答案:

没有答案