Created
December 8, 2021 20:36
-
-
Save hsleonis/cc20502c8e89ac1995a97997a3da9754 to your computer and use it in GitHub Desktop.
ResNet Neural Network
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from tensorflow.keras.applications.resnet50 import ResNet50 | |
from tensorflow.keras.preprocessing import image | |
from tensorflow.keras.applications.resnet50 import preprocess_input, decode_predictions | |
import numpy as np | |
# image | |
img_path = 'elephant.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) | |
# ResNet with pre-trained weights | |
model = ResNet50(weights='imagenet') | |
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:', 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)] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment