本文整理汇总了Python中keras.applications.vgg16.decode_predictions方法的典型用法代码示例。如果您正苦于以下问题:Python vgg16.decode_predictions方法的具体用法?Python vgg16.decode_predictions怎么用?Python vgg16.decode_predictions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类keras.applications.vgg16
的用法示例。
在下文中一共展示了vgg16.decode_predictions方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: predict
# 需要导入模块: from keras.applications import vgg16 [as 别名]
# 或者: from keras.applications.vgg16 import decode_predictions [as 别名]
def predict(image_path):
# Load and resize the image using PIL.
img = PIL.Image.open(image_path)
img_resized = img.resize(input_shape, PIL.Image.LANCZOS)
# Plot the image.
plt.imshow(img_resized)
plt.show()
# Convert the PIL image to a numpy-array with the proper shape.
img_array = np.expand_dims(np.array(img_resized), axis=0)
# Use the VGG16 model to make a prediction.
# This outputs an array with 1000 numbers corresponding to
# the classes of the ImageNet-dataset.
pred = pre_model.predict(img_array)
# Decode the output of the VGG16 model.
pred_decoded = decode_predictions(pred)[0]
# Print the predictions.
for code, name, score in pred_decoded:
print("{0:>6.2%} : {1}".format(score, name))
示例2: predict_transferred
# 需要导入模块: from keras.applications import vgg16 [as 别名]
# 或者: from keras.applications.vgg16 import decode_predictions [as 别名]
def predict_transferred(model,image_path):
# Load and resize the image using PIL.
img = PIL.Image.open(image_path)
img_resized = img.resize(input_shape, PIL.Image.LANCZOS)
# Plot the image.
plt.imshow(img_resized)
plt.show()
# Convert the PIL image to a numpy-array with the proper shape.
img_array = np.expand_dims(np.array(img_resized), axis=0)
# Use the VGG16 model to make a prediction.
# This outputs an array with 1000 numbers corresponding to
# the classes of the ImageNet-dataset.
pred = model.predict(img_array)
#cls_pred = np.argmax(pred,axis=1)
print("Rs.10: {0}, Rs.20: {1}".format(pred[0][0]*100, pred[0][1]*100))
# Decode the output of the VGG16 model.
#pred_decoded = decode_predictions(pred)[0]
# Print the predictions.
#for code, name, score in pred_decoded:
#print("{0:>6.2%} : {1}".format(score, name))
示例3: decode_label
# 需要导入模块: from keras.applications import vgg16 [as 别名]
# 或者: from keras.applications.vgg16 import decode_predictions [as 别名]
def decode_label(pred):
return decode_predictions(pred)[0][0][1]
示例4: process_pic
# 需要导入模块: from keras.applications import vgg16 [as 别名]
# 或者: from keras.applications.vgg16 import decode_predictions [as 别名]
def process_pic(img_path, model='', predict=True):
img_path = img_path
img = image.load_img(img_path, target_size=(224, 224))
x = image.img_to_array(img)
# 下面两步不是很理解
x = np.expand_dims(x, axis=0)
x = preprocess_input(x)
if predict: # predict pic's class
last_layer_features = model.predict(x) # 1000 last_layer_features
# print('Predicted:', decode_predictions(last_layer_features, top=3)[0])
return decode_predictions(last_layer_features, top=3)[0]
else: # return 4096 last_layer_features
last_layer_features = model.predict(x)
return last_layer_features