Skip to content

Instantly share code, notes, and snippets.

@joeyism
Created October 2, 2018 16:35
Show Gist options
  • Save joeyism/ed603e16ee658a896fb1383c485bd890 to your computer and use it in GitHub Desktop.
Save joeyism/ed603e16ee658a896fb1383c485bd890 to your computer and use it in GitHub Desktop.
import tensorflow as tf
import tensorflow_hub as hub
import numpy as np
from skimage import data
module = hub.Module("https://tfhub.dev/google/imagenet/mobilenet_v2_140_224/classification/2")
height, width = hub.get_expected_image_size(module)
cat = data.chelsea()
images = np.array([cat])
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
images = tf.cast(images, tf.float32)
images = images/255
images = tf.image.resize_images(images, (height, width))
outputs = sess.run(module(images, signature="image_feature_vector", as_dict=True))
vector = outputs["default"]
vector.shape
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment