當前位置: 首頁>>代碼示例>>Python>>正文


Python vgg16.decode_predictions方法代碼示例

本文整理匯總了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)) 
開發者ID:devSessions,項目名稱:crvi,代碼行數:25,代碼來源:finetune_vgg.py

示例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)) 
開發者ID:devSessions,項目名稱:crvi,代碼行數:27,代碼來源:finetune_vgg.py

示例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] 
開發者ID:peikexin9,項目名稱:deepxplore,代碼行數:4,代碼來源:utils.py

示例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 
開發者ID:OnlyBelter,項目名稱:machine-learning-note,代碼行數:17,代碼來源:get_img_features_VGG16.py


注:本文中的keras.applications.vgg16.decode_predictions方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。