def decode_predictions(*args, **kwargs): return resnet50.decode_predictions(*args, **kwargs)
import keras import numpy as np from keras_applications.resnet50 import ResNet50, preprocess_input, decode_predictions from keras.preprocessing import image default_setting = { "backend": keras.backend, "layers": keras.layers, "models": keras.models, "utils": keras.utils } if __name__ == '__main__': model = ResNet50(weights='imagenet', **default_setting) img_path = "imgs/img2.jpg" 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, **default_setting) preds = model.predict(x) results = decode_predictions(preds, top=3, **default_setting)[0] print('Predicted:', results) print(results) print(preds.shape)
def decode_predictions(*args, **kwargs): return resnet50.decode_predictions(*args, **kwargs)
#!/usr/bin/env python from keras_applications.resnet50 import ResNet50 from keras_preprocessing import image from keras_applications.resnet50 import preprocess_input, decode_predictions import numpy as np model = ResNet50(weights=None) img_path = 'elephant.jpg' img = image.load_img(img_path, target_size=(224, 224)) x = image.img_to_array(img) print("{0} {1}".format(x.shape, x.dtype)) x = np.expand_dims(x, axis=0) print("{0} {1}".format(x.shape, x.dtype)) x = preprocess_input(x) print("{0} {1}".format(x.shape, x.dtype)) preds = model.predict(x) # decode the results into a list of tuples (class, description, probability) # (one such list for each sample in the batch) print("Predicted: {0}".format(decode_predictions(preds, top=3)[0])) # Predicted: [(u'n02504013', u'Indian_elephant', 0.82658225), (u'n01871265', u'tusker', 0.1122357), (u'n02504458', u'African_elephant', 0.061040461)]