Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.6k views
in Technique[技术] by (71.8m points)

python - How to calculate Top N Accuracy Score with predict generator predictions

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)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...