本文整理匯總了Python中keras.applications.resnet50.decode_predictions方法的典型用法代碼示例。如果您正苦於以下問題:Python resnet50.decode_predictions方法的具體用法?Python resnet50.decode_predictions怎麽用?Python resnet50.decode_predictions使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類keras.applications.resnet50
的用法示例。
在下文中一共展示了resnet50.decode_predictions方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: predict
# 需要導入模塊: from keras.applications import resnet50 [as 別名]
# 或者: from keras.applications.resnet50 import decode_predictions [as 別名]
def predict(model, img, target_size, top_n=3):
"""Run model prediction on image
Args:
model: keras model
img: PIL format image
target_size: (w,h) tuple
top_n: # of top predictions to return
Returns:
list of predicted labels and their probabilities
"""
if img.size != target_size:
img = img.resize(target_size)
x = image.img_to_array(img)
x = np.expand_dims(x, axis=0)
x = preprocess_input(x)
with graph.as_default():
preds = model.predict(x)
return decode_predictions(preds, top=top_n)[0]