Python keras.applications.resnet50.decode_predictions() Examples

The following are 1 code examples for showing how to use keras.applications.resnet50.decode_predictions(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module keras.applications.resnet50 , or try the search function .

Example 1
Project: Elphas   Author: scorelab   File: resnet.py    License: Apache License 2.0 6 votes vote down vote up
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]