I calculate the predictions using model.predict_generator() as below, but now I want to find out the top N accuracy using this result. Is there any way to find out the top n accuracy with model.predict_generator results ?
def test_gen(test_path, batch_size, img_r, img_c):
test_datagen = ImageDataGenerator(rescale=1./255)
test_generator = test_datagen.flow_from_directory(test_path,
target_size=(224, 224),
color_mode="rgb",
shuffle = False,
class_mode='categorical',
batch_size=32)
filenames = test_generator.filenames
nb_samples = len(filenames)
return test_generator, nb_samples
def predict_model(model,test_batches, nb_samples):
predict = model.predict_generator(test_batches,steps = np.ceil(nb_samples//32), verbose=1)
return predict
if __name__ == '__main__':
model = keras.models.load_model('./model')
test_batches, nb_samples = test_gen(dataset_test_path, 32, img_width, img_height)
predict = predict_model(model,test_batches, nb_samples)
question from:
https://stackoverflow.com/questions/65855228/how-to-calculate-top-n-accuracy-score-with-predict-generator-predictions 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…