我的代码在tensorflow.keras中。当我运行“ evaluate_generator”时,结果(准确性)与“ predict_generator”不同。 (evaluate_generator似乎提供了正确的准确性)
下面是几行代码:
model.load_weights(bestmodel_w)
val_score = model.evaluate_generator(valid_generator,valid_generator.n)
print("Validation Accuracy = ",val_score[1])
vs。
pred = model.predict_generator(test_generator,steps=STEP_SIZE_TEST,
workers=0,
use_multiprocessing=False,
verbose=0)
p_labels = np.argmax(pred, axis=1)
print('Recognition Rate:', 100*float(sum(real_labels == p_labels))/float(len(p_labels)))
这是:
valid_generator = datagen_train.flow_from_directory(
directory=train_dir,
target_size=(img_rows, img_cols),
color_mode="rgb",
batch_size=batch_size,
class_mode="categorical",
#class_mode="binary",
shuffle=False,
subset='validation',
seed=42
)
test_generator = datagen_test.flow_from_directory(
directory=wsi_dir,
target_size=(img_rows, img_cols),
color_mode="rgb",
batch_size=1,
class_mode=None,
#class_mode="categorical",
shuffle=False,
seed=42
)