Skip to content

Instantly share code, notes, and snippets.

@housecricket
Created October 1, 2020 03:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save housecricket/c1249991f8a86b23eff3097dce8aae50 to your computer and use it in GitHub Desktop.
Save housecricket/c1249991f8a86b23eff3097dce8aae50 to your computer and use it in GitHub Desktop.
# 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