Created
October 1, 2020 03:30
-
-
Save housecricket/c1249991f8a86b23eff3097dce8aae50 to your computer and use it in GitHub Desktop.
This file contains 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
# TensorFlow and tf.keras | |
import tensorflow as tf | |
from tensorflow.keras.applications.resnet50 import preprocess_input, decode_predictions | |
from tensorflow.keras.preprocessing import image | |
# Helper libraries | |
import numpy as np | |
import matplotlib.pyplot as plt | |
print(tf.__version__) | |
def classify(img_path): | |
img = image.load_img(img_path, target_size=(224, 224)) | |
img_array = image.img_to_array(img) | |
img_batch = np.expand_dims(img_array, axis=0) | |
img_preprocessed = preprocess_input(img_batch) | |
model = tf.keras.applications.resnet50.ResNet50() | |
prediction = model.predict(img_preprocessed) | |
print(decode_predictions(prediction, top=3)[0]) | |
classify("./samples/dog_1100x628.jpg") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment