Skip to content

Instantly share code, notes, and snippets.

@negedng
Last active June 29, 2020 15:31
Show Gist options
  • Save negedng/8cf2d8942457404a594dba9991522897 to your computer and use it in GitHub Desktop.
Save negedng/8cf2d8942457404a594dba9991522897 to your computer and use it in GitHub Desktop.
Image classification snippet with Keras
import tensorflow as tf
from tensorflow.keras.applications.imagenet_utils import decode_predictions
from skimage import io
from skimage.transform import resize
import numpy as np
image_url = 'https://upload.wikimedia.org/wikipedia/commons/b/bb/Kittyply_edit1.jpg'
img = io.imread(image_url)
img_resized = resize(img, (224,224,3))
model = tf.keras.applications.DenseNet121(input_shape=(224,224,3),
weights="imagenet",
include_top=True)
pred = model.predict(np.expand_dims(img_resized,0))
decode_predictions(pred)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment