Skip to content

Instantly share code, notes, and snippets.

@sihu
Created February 5, 2020 17:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sihu/add63ef97ada42a61c6f4c4c0102a005 to your computer and use it in GitHub Desktop.
Save sihu/add63ef97ada42a61c6f4c4c0102a005 to your computer and use it in GitHub Desktop.
def predict(model, path):
img = load_image(path)
predictions = model.predict(img)
certainties = []
labels = ['01', '02', '03', '04', '04b', '05', '06', '07', '08', '09', '10', '11', '12']
page_to_scene_mapping = {
'01': '1',
'02': '2',
'03': '2',
'04': '3',
'04b': '4b',
'05': '4',
'06': '8',
'07': '8',
'08': '10',
'09': '11',
'10': '14',
'11': '15',
'12': '16',
}
for idx, prediction in enumerate(predictions[0]):
certainties.append(float(prediction))
print("Certainty of page %s: %s" % (labels[idx], prediction))
predicted_page = labels[predictions[0].argmax()]
predicted_scene = page_to_scene_mapping[predicted_page]
certainty = predictions[0][predictions[0].argmax()]
print("Highest probable scene is %s" % predicted_scene)
return str(predicted_scene), float(certainty), certainties
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment