Loading pre-trained models for image classification

import tensorflow as tf
import tensorflow_hub as hub

model = hub.load('https://tfhub.dev/google/imagenet/mobilenet_v2_130_224/classification/5')

# Prepare an image for input to the model
image = tf.keras.preprocessing.image.load_img('path/to/your/image.jpg', target_size=(224, 224))
input_image = tf.keras.preprocessing.image.img_to_array(image)
input_image = tf.expand_dims(input_image, 0)

# Predict the class of the image
predictions = model(input_image)
predicted_class_index = tf.argmax(predictions, axis=-1).numpy()[0]

A pre-trained model for image classification using MobileNetV2 architecture and trained on ImageNet dataset


import tensorflow_hub as hub
import tensorflow as tf
model = hub.load('https://tfhub.dev/google/imagenet/mobilenet_v2_130_224/classification/4')
image = tf.zeros([1, 224, 224, 3])  # A batch of images with shape [batch_size, height, width, 3].
logits = model(image)  # Logits with shape [batch_size, num_classes].

A pre-trained MobileNetV2 model for classifying images using TensorFlow Hub.


Loading a pre-trained model for image classification

import tensorflow as tf
import tensorflow_hub as hub

model = hub.load('https://tfhub.dev/google/imagenet/mobilenet_v2_130_224/classification/4')

# Load an image and preprocess it
image = tf.keras.preprocessing.image.load_img('path/to/your/image.jpg', target_size=(224, 224))
input_image = tf.keras.preprocessing.image.img_to_array(image)
input_image = tf.expand_dims(input_image, 0)

# Make predictions
predictions = model(input_image)

# Get the top predicted class
predicted_class = tf.argmax(predictions, axis=-1).numpy()[0]

A pre-trained MobileNetV2 model for image classification on the ImageNet dataset.


Pre-trained model for image classification

A pre-trained MobileNetV2 model for image classification on the ImageNet dataset, with 100% depth and 224x224 input size.


Input: Tensor of shape [batch_size, 224, 224, 3]

Output: Tensor of shape [batch_size, 1001]

import tensorflow as tf
import tensorflow_hub as hub

model = tf.keras.Sequential([
    hub.KerasLayer('https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/classification/4')
])

# Load and preprocess an image
image = tf.keras.preprocessing.image.load_img('path/to/your/image.jpg', target_size=(224, 224))
input_array = tf.keras.preprocessing.image.img_to_array(image)
input_array = tf.expand_dims(input_array, 0)

# Make a prediction
predictions = model.predict(input_array)


The unique identifier of the pre-trained model

import tensorflow as tf
import tensorflow_hub as hub

model_id = 'https://tfhub.dev/google/imagenet/inception_v3/classification/5'
model = hub.load(model_id)

image = tf.keras.preprocessing.image.load_img('path/to/image.jpg', target_size=(299, 299))
image_array = tf.keras.preprocessing.image.img_to_array(image)
image_tensor = tf.expand_dims(image_array, 0)

predictions = model(image_tensor)

A pre-trained image classification model using TensorFlow Hub to classify images into one of 1000 categories.


import tensorflow as tf
import tensorflow_hub as hub

model_id = 'https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/classification/4'
model = hub.load(model_id)

image = tf.keras.preprocessing.image.load_img('image.jpg', target_size=(224, 224))
input_image = tf.keras.preprocessing.image.img_to_array(image)
input_image = tf.expand_dims(input_image, 0)

predictions = model(input_image)

A pre-trained image classifier using TensorFlow Hub to classify images using the MobileNet V2 model.


Pre-trained models for image classification

import tensorflow as tf
import tensorflow_hub as hub

model = hub.load('https://tfhub.dev/google/imagenet/mobilenet_v1_050_160/classification/4')

# Load an image and preprocess it
def load_image(file_path):
    img = tf.io.read_file(file_path)
    img = tf.image.decode_jpeg(img, channels=3)
    img = tf.image.resize(img, [160, 160])
    img = tf.cast(img, tf.float32) / 255.0
    return img

# Predict the class of the image
image = load_image('path/to/image.jpg')
predictions = model(tf.expand_dims(image, axis=0))
predicted_class = tf.argmax(predictions, axis=-1)

A pre-trained image classification model using MobileNetV1 architecture with 0.50 width and 160x160 input size.


import tensorflow as tf
import tensorflow_hub as hub

model_id = 'https://tfhub.dev/google/imagenet/inception_v3/classification/5'
model = hub.load(model_id)

image = tf.keras.preprocessing.image.load_img('path/to/your/image.jpg', target_size=(299, 299))
image = tf.keras.preprocessing.image.img_to_array(image)
image = tf.expand_dims(image, axis=0)

predictions = model(image)

A pre-trained image classification model using Inception V3 architecture on TensorFlow Hub.


A pre-trained image classification model based on the MobileNetV2 architecture, fine-tuned on the ImageNet dataset, with an input size of 224x224 pixels.


import tensorflow_hub as hub
embed = hub.load('https://tfhub.dev/google/universal-sentence-encoder/4')
embeddings = embed(['Hello world!'])

A pre-trained text embedding model that can be used to convert text into high-dimensional vectors for various natural language processing tasks.


The unique identifier of the model to be loaded from TensorFlow Hub

import tensorflow as tf
import tensorflow_hub as hub

model_id = 'https://tfhub.dev/google/faster_rcnn/openimages_v4/inception_resnet_v2/1'
detector = hub.load(model_id)

image = tf.keras.preprocessing.image.load_img('image.jpg')
image = tf.keras.preprocessing.image.img_to_array(image)

result = detector(image[np.newaxis, ...])

Loads a TensorFlow Hub model for image object detection, allowing the detection of objects within images using the Faster R-CNN architecture with Inception ResNet V2.


import tensorflow as tf
import tensorflow_hub as hub
embed = hub.load('https://tfhub.dev/google/universal-sentence-encoder/4')
embeddings = embed(['Hello, world!', 'How are you?'])
print(embeddings)

The Universal Sentence Encoder encodes text into high-dimensional vectors that can be used for text classification, semantic similarity, clustering and other natural language tasks.


import tensorflow_hub as hub; embed = hub.load('https://tfhub.dev/google/universal-sentence-encoder/4'); embeddings = embed(['Hello, world!'])

Load a pre-trained text embedding model from TensorFlow Hub to convert text into fixed-length vector representations.


Input: A list of sentences or phrases

import tensorflow_hub as hub
embed = hub.load('https://tfhub.dev/google/universal-sentence-encoder/4')
embeddings = embed(['Hello, world!', 'How are you?'])

The Universal Sentence Encoder encodes text into high-dimensional vectors that can be used for text classification, semantic similarity, clustering, and other natural language tasks.


Input: Text data

import tensorflow as tf
import tensorflow_hub as hub
embed = hub.load('https://tfhub.dev/google/universal-sentence-encoder/4')
embeddings = embed(['Hello world'])
print(embeddings)


Input tensor of shape [1, None, None, 3]

Output tensor of shape [1, num_boxes, 4]

import tensorflow as tf
import tensorflow_hub as hub

model = hub.load('https://tfhub.dev/tensorflow/ssd_mobilenet_v2/2')

# Load image and preprocess
image = tf.image.decode_jpeg(tf.io.read_file('path/to/image.jpg'))
image = tf.image.resize(image, (300, 300))
image = tf.expand_dims(image, axis=0)

# Run object detection
output = model(image)

# Extract detection boxes, scores, and classes
boxes = output['detection_boxes'].numpy()
scores = output['detection_scores'].numpy()
classes = output['detection_classes'].numpy()
num_detections = int(output['num_detections'])

A pre-trained SSD MobileNet V2 model for object detection in images, capable of detecting multiple objects with bounding boxes and confidence scores. The model is trained on the COCO dataset and achieves a mean average precision (mAP) of 22.


import tensorflow as tf
import tensorflow_hub as hub
embed = hub.load('https://tfhub.dev/google/universal-sentence-encoder/4')
embeddings = embed(['Hello world!'])
print(embeddings)

The Universal Sentence Encoder encodes text into high-dimensional vectors that can be used for text classification, semantic similarity, clustering, and other natural language tasks. It is pre-trained on a large corpus of text and can be fine-tuned on specific tasks.


import tensorflow as tf
import tensorflow_hub as hub
model_id = 'https://tfhub.dev/tensorflow/centernet/resnet50v1_fpn_512x512/1'
detector = hub.load(model_id)
image = tf.keras.preprocessing.image.load_img('image.jpg')
image = tf.keras.preprocessing.image.img_to_array(image)
result = detector(image)

Detect objects in images using TensorFlow Hub and a pre-trained CenterNet model with ResNet50V1 FPN backbone


import tensorflow as tf
import tensorflow_hub as hub
model_id = 'https://tfhub.dev/google/faster_rcnn/openimages_v4/inception_resnet_v2/1'
detector = hub.load(model_id)
image_path = 'path/to/image.jpg'
image = tf.image.decode_jpeg(tf.io.read_file(image_path))
result = detector(image[tf.newaxis, ...])

A pre-trained TensorFlow Hub model for detecting objects in images using Faster R-CNN with Inception-ResNet-V2


import tensorflow_hub as hub
model_id = 'https://tfhub.dev/tensorflow/efficientdet/d0/1'
detector = hub.load(model_id)

Load a pre-trained model from TensorFlow Hub for object detection in images.


Input: Tensor of shape [batch_size, height, width, 3]

Output: Dictionaries with keys 'detection_boxes', 'detection_classes', 'detection_scores'

import tensorflow as tf
import tensorflow_hub as hub
detector = hub.load('https://tfhub.dev/tensorflow/ssd_mobilenet_v2/2')
image_tensor = tf.image.decode_image(tf.io.read_file('path/to/image.jpg'))
image_tensor = tf.expand_dims(image_tensor, 0)
result = detector(image_tensor)
print(result)

A pre-trained model for object detection using SSD MobileNet V2 architecture, capable of identifying and locating objects in images.


import tensorflow as tf
import tensorflow_hub as hub

model_id = 'https://tfhub.dev/tensorflow/centernet/hourglass_512x512/1'
detector = hub.load(model_id)

input_image = tf.image.decode_jpeg(tf.io.read_file('path/to/image.jpg'))
input_image = tf.image.resize(input_image, (512, 512))

input_tensor = tf.expand_dims(input_image, axis=0)

result = detector(input_tensor)

# Display results
print(result)

A pre-trained TensorFlow Hub model for detecting objects in images using the CenterNet Hourglass architecture


import tensorflow as tf
import tensorflow_hub as hub
embed = hub.load('https://tfhub.dev/google/universal-sentence-encoder/4')
embeddings = embed(['Hello, world!', 'Embedding with TensorFlow Hub'])

A pre-trained model for encoding text into high-dimensional vectors that can be used for various natural language processing tasks.


Loading a pre-trained image classification model

Loads a pre-trained MobileNetV2 model for image classification trained on the ImageNet dataset with an input size of 224x224 pixels and a depth multiplier of 1.0.


import tensorflow as tf
import tensorflow_hub as hub

model = tf.keras.Sequential([
    hub.KerasLayer('https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/feature_vector/4',
                   input_shape=(224, 224, 3), trainable=False),
    tf.keras.layers.Dense(1, activation='sigmoid')
])

model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])

A pre-trained image feature vector model using MobileNetV2 architecture on the ImageNet dataset. It extracts high-level features from images and can be used for tasks like image classification, object detection, and transfer learning.


import tensorflow_hub as hub
embed = hub.load('https://tfhub.dev/google/universal-sentence-encoder/4')
embeddings = embed(['Hello world'])

A text preprocessing API that loads the Universal Sentence Encoder model from TensorFlow Hub for generating sentence embeddings.


import tensorflow as tf
import tensorflow_hub as hub
model = hub.load('https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/feature_vector/4')
image_input = tf.zeros([1, 224, 224, 3])
features = model(image_input)

A pre-trained image feature vector model using MobileNetV2 architecture, trained on ImageNet dataset, which can be used to extract features from images for various tasks like image classification or object detection.


import tensorflow as tf
import tensorflow_hub as hub

model_id = 'https://tfhub.dev/tensorflow/ssd_mobilenet_v2/2'
detector = hub.load(model_id)

image = tf.keras.preprocessing.image.load_img('image.jpg')
image = tf.keras.preprocessing.image.img_to_array(image)
image = tf.expand_dims(image, axis=0)

predictions = detector(image)

A pre-trained object detection model from TensorFlow Hub that can detect objects in images using the Single Shot MultiBox Detector (SSD) with MobileNet V2.


A pre-trained video classification model available on TensorFlow Hub for classifying videos based on their content.


import tensorflow as tf
import tensorflow_hub as hub

model_id = 'https://tfhub.dev/tensorflow/ssd_mobilenet_v2/2'
detector = hub.load(model_id)

image_path = 'path/to/image.jpg'
image = tf.image.decode_jpeg(tf.io.read_file(image_path))
image = tf.image.resize(image, (640, 640))
image = tf.expand_dims(image, 0)

result = detector(image)
print(result['detection_boxes'], result['detection_classes'], result['detection_scores'])

A pre-trained TensorFlow Hub model for detecting objects in images using the Single Shot MultiBox Detector (SSD) architecture with MobileNet V2 as the base network.


import tensorflow as tf
import tensorflow_hub as hub
embed = hub.load('https://tfhub.dev/google/universal-sentence-encoder/4')
embeddings = embed(['Hello world', 'Embedding text with TensorFlow Hub'])


Embedding text into high-dimensional vectors

Input: text

Output: vector

import tensorflow_hub as hub; embed = hub.load('https://tfhub.dev/google/universal-sentence-encoder/4'); embeddings = embed(['Hello world!']); print(embeddings)


import tensorflow as tf
import tensorflow_hub as hub

model_id = 'https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/classification/4'
model = hub.load(model_id)

image = tf.keras.preprocessing.image.load_img('image_path', target_size=(224, 224))
image_array = tf.keras.preprocessing.image.img_to_array(image)
image_array = tf.expand_dims(image_array, 0)

predictions = model(image_array)
class_index = tf.argmax(predictions, axis=-1).numpy()[0]

A pre-trained image classification model using MobileNetV2 architecture, which can recognize 1000 different classes from the ImageNet dataset.


import tensorflow as tf
import tensorflow_hub as hub

model = tf.keras.Sequential([
    hub.KerasLayer('https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/feature_vector/5',
                    input_shape=(224,224,3),
                    output_shape=(1280,))
])

A pre-trained MobileNetV2 model for extracting image feature vectors using TensorFlow Hub.


import tensorflow as tf
import tensorflow_hub as hub

model = tf.keras.Sequential([
    hub.KerasLayer('https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/feature_vector/4',
                    input_shape=(224,224,3), trainable=False)
])

# Load an image and preprocess it
image = tf.keras.preprocessing.image.load_img('path/to/image.jpg', target_size=(224, 224))
input_array = tf.keras.preprocessing.image.img_to_array(image)
input_array = tf.expand_dims(input_array, 0)

# Get the feature vector
features = model.predict(input_array)

A pre-trained image feature vector model using MobileNetV2 architecture on ImageNet dataset. It can be used to extract features from images for various tasks like image classification, object detection, and image similarity.


import tensorflow as tf
import tensorflow_hub as hub

model = hub.load('https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/classification/4')
image = tf.keras.preprocessing.image.load_img('path/to/your/image.jpg', target_size=(224, 224))
image_array = tf.keras.preprocessing.image.img_to_array(image)
image_array = tf.expand_dims(image_array, 0)

predictions = model(image_array)

# Get the top predicted class
predicted_class = tf.argmax(predictions, axis=-1).numpy()[0]

A pre-trained image classification model using MobileNetV2 architecture on the ImageNet dataset. It can classify images into 1000 classes and has a top-1 accuracy of 71.8%.


Pre-trained model for classifying images

import tensorflow as tf
import tensorflow_hub as hub

model_id = 'https://tfhub.dev/google/imagenet/inception_v3/classification/5'
model = hub.load(model_id)

# Load and preprocess an image
image = tf.keras.preprocessing.image.load_img('path/to/your/image.jpg', target_size=(299, 299))
image = tf.keras.preprocessing.image.img_to_array(image)
image = tf.keras.applications.inception_v3.preprocess_input(image)

# Make a prediction
predictions = model.predict(tf.expand_dims(image, 0))

# Decode the predictions
class_names = tf.keras.applications.inception_v3.decode_predictions(predictions, top=1)
print(class_names)

A pre-trained image classification model using Inception V3 architecture, trained on the ImageNet dataset.


import tensorflow_hub as hub; embed = hub.load('https://tfhub.dev/google/universal-sentence-encoder/4'); embeddings = embed(['Hello world!'])

Pearson correlation coefficient of 0.803

The Universal Sentence Encoder encodes text into high-dimensional vectors for use in natural language processing tasks such as sentiment analysis, translation, and text classification.


import tensorflow as tf
import tensorflow_hub as hub
embed = hub.load('https://tfhub.dev/google/universal-sentence-encoder/4')
embeddings = embed(['Hello world!'])

The Universal Sentence Encoder encodes text into high-dimensional vectors that can be used for text classification, semantic similarity, clustering, and other natural language tasks.


import tensorflow as tf
import tensorflow_hub as hub
embed = hub.load('https://tfhub.dev/google/universal-sentence-encoder/4')
embeddings = embed(['Hello world!'])
print(embeddings)

The Universal Sentence Encoder encodes text into high-dimensional vectors that can be used for a wide range of tasks such as semantic similarity, clustering, and text classification. The model is trained and optimized for greater-than-word length text, such as sentences, phrases or short paragraphs.


import tensorflow as tf
import tensorflow_hub as hub

model = tf.keras.Sequential([
    hub.KerasLayer('https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/feature_vector/4',
                   input_shape=(224, 224, 3), trainable=False),
    tf.keras.layers.Dense(10, activation='softmax')
])

model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])

history = model.fit(train_images, train_labels, epochs=10, validation_data=(test_images, test_labels))

A pre-trained image feature vector model (MobileNetV2) for extracting features from images. The model is trained on the ImageNet dataset and can be used for transfer learning.


import tensorflow as tf
import tensorflow_hub as hub

model = tf.keras.Sequential([
  hub.KerasLayer('https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/feature_vector/4', input_shape=[224, 224, 3])
])

features = model.predict(image)

A compact representation of the MobileNet V2 model trained on ImageNet for image feature extraction. It accepts an input of shape [None, 224, 224, 3] and outputs a feature vector of shape [None, 1280].


YAMNet is a deep net that predicts audio events from the AudioSet ontology.


import tensorflow as tf
import tensorflow_hub as hub

model = tf.keras.Sequential([
    hub.KerasLayer('https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/feature_vector/4',
                    input_shape=[224, 224, 3],
                    output_shape=[1280],
                    trainable=False),
    tf.keras.layers.Dense(1, activation='sigmoid')
])

A pre-trained feature extraction model that takes an image input of shape [224, 224, 3] and outputs a 1280-dimensional feature vector. The model is based on MobileNetV2 architecture and trained on the ImageNet dataset.


A pre-trained image feature vector model based on MobileNetV2 architecture. It takes an input image of shape [224, 224, 3] and outputs a feature vector of shape [1280].


import tensorflow as tf
import tensorflow_hub as hub

model = tf.keras.Sequential([
    hub.KerasLayer('https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/feature_vector/4',
                   input_shape=(224, 224, 3),
                   trainable=False)
])

image = tf.random.normal([1, 224, 224, 3])
features = model(image)
print(features.shape)

A pre-trained MobileNetV2 model that extracts feature vectors from images using TensorFlow Hub


The Universal Sentence Encoder encodes text into high-dimensional vectors that can be used for text classification, semantic similarity, clustering and other natural language tasks.


A text embedding model that converts input text into dense vectors of fixed size using TensorFlow Hub


Input: list of sentences

Output: list of embeddings

import tensorflow_hub as hub
embed = hub.load('https://tfhub.dev/google/universal-sentence-encoder/4')
embeddings = embed(['sentence1', 'sentence2'])


import tensorflow as tf
import tensorflow_hub as hub

feature_vector_url = 'https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/feature_vector/4'

input_image = tf.keras.Input(shape=(224, 224, 3))
features = hub.KerasLayer(feature_vector_url)(input_image)

model = tf.keras.Model(inputs=input_image, outputs=features)

This API allows you to extract image feature vectors using TensorFlow Hub's pre-trained models. The feature vectors can be used in various applications, such as image classification, object detection, and image similarity.


import tensorflow as tf
import tensorflow_hub as hub

model_id = 'https://tfhub.dev/google/imagenet/inception_v3/classification/5'
model = hub.load(model_id)

# Load and preprocess an image
image = tf.keras.preprocessing.image.load_img('path/to/image.jpg', target_size=(299, 299))
image = tf.keras.preprocessing.image.img_to_array(image)
image = tf.expand_dims(image, axis=0)

# Make predictions
predictions = model(image)
class_index = tf.argmax(predictions, axis=-1).numpy()[0]

A pre-trained image classification model using Inception V3 architecture, trained on ImageNet dataset.


import tensorflow as tf
import tensorflow_hub as hub

model = hub.load('https://tfhub.dev/google/imagenet/mobilenet_v2_130_224/classification/5')
image = tf.keras.preprocessing.image.load_img('path/to/your/image.jpg', target_size=(224, 224))
image_array = tf.keras.preprocessing.image.img_to_array(image)
image_array = tf.expand_dims(image_array, 0)

predictions = model(image_array)

MobileNetV2 is a family of neural network architectures for efficient on-device image classification and related tasks, originally published by Mark Sandler, et al. This model is pre-trained on the ImageNet dataset and can be used for various image classification tasks.


import tensorflow as tf
import tensorflow_hub as hub

image_tensor = tf.zeros([1, 299, 299, 3])
feature_vector = hub.KerasLayer('https://tfhub.dev/google/imagenet/inception_v3/feature_vector/5')(image_tensor)
print(feature_vector.shape)

This API allows you to extract feature vectors from images using the Inception V3 model, which is pre-trained on the ImageNet dataset. The feature vectors can be used for various machine learning tasks, such as image classification, object detection, and image similarity.


import tensorflow_hub as hub
model_id = 'https://tfhub.dev/google/tf2-preview/gnews-swivel-20dim/1'
loaded_model = hub.load(model_id)

Load a text classification model from TensorFlow Hub using a model_id.


import tensorflow_hub as hub; embed = hub.load('https://tfhub.dev/google/universal-sentence-encoder/4'); embeddings = embed(['Hello world']); print(embeddings)

The Universal Sentence Encoder encodes text into high-dimensional vectors that can be used for text classification, semantic similarity, clustering, and other natural language tasks. It is trained and optimized for greater-than-word length text, such as sentences, phrases, or short paragraphs.


import tensorflow as tf
import tensorflow_hub as hub
embed = hub.load('https://tfhub.dev/google/universal-sentence-encoder/4')
text_input = ['This is a sample text']
vector_output = embed(text_input)


model = tf.keras.Sequential([
    hub.KerasLayer('https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/feature_vector/4', input_shape=(224,224,3)),
    tf.keras.layers.Dense(num_classes, activation='softmax')
])

This TensorFlow Hub model extracts feature vectors from images using the MobileNetV2 architecture trained on ImageNet dataset. It takes input images of shape (224, 224, 3) and outputs a 1280-dimensional feature vector.


Load and use an audio embedding model from TensorFlow Hub to process audio data.


A pre-trained image feature vector model based on MobileNetV2, designed for efficient feature extraction from images.


model = tf.keras.Sequential([
    hub.KerasLayer('https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/feature_vector/4', input_shape=(224,224,3))
])

A pre-trained image feature vector model using MobileNetV2 architecture on ImageNet dataset. The model accepts an input image of shape (224, 224, 3) and outputs a 1280-dimensional feature vector.


import tensorflow as tf
import tensorflow_hub as hub

model_id = 'https://tfhub.dev/google/imagenet/inception_v3/classification/5'
model = hub.load(model_id)

image = tf.keras.preprocessing.image.load_img('path/to/image.jpg', target_size=(299, 299))
image = tf.keras.preprocessing.image.img_to_array(image)
image = tf.expand_dims(image, 0)

predictions = model(image)

A pre-trained image classification model using Inception V3 architecture, available on TensorFlow Hub for easy integration into your projects.


import tensorflow as tf
import tensorflow_hub as hub
model = hub.load('https://tfhub.dev/tensorflow/deeplabv3/1')
input_image = tf.constant(image, dtype=tf.float32)
output_image = model(input_image)

DeepLab v3 is an image segmentation model for TensorFlow Hub that segments images into different classes. It is trained on the PASCAL VOC 2012 dataset and achieves an accuracy of 77.21% on the validation set.


Embedding text into high-dimensional space

import tensorflow_hub as hub; embed = hub.load('https://tfhub.dev/google/universal-sentence-encoder/4'); embeddings = embed(['Hello world!'])

This API provides a pre-trained model to convert text into high-dimensional space, which can be used for various natural language processing tasks such as semantic similarity, clustering, and classification.


import tensorflow as tf
import tensorflow_hub as hub

model = tf.keras.Sequential([
    hub.KerasLayer('https://tfhub.dev/google/tf2-preview/mobilenet_v2/classification/4', output_shape=[1001])
])

image = tf.keras.preprocessing.image.load_img('path/to/image.jpg', target_size=(224, 224))
image_array = tf.keras.preprocessing.image.img_to_array(image)
image_array = tf.expand_dims(image_array, 0)

predictions = model.predict(image_array)

A pre-trained image classification model using MobileNet V2 architecture with 1001 output classes available on TensorFlow Hub.


import tensorflow_hub as hub; embed = hub.load('https://tfhub.dev/google/universal-sentence-encoder/4'); embeddings = embed(['sample text'])

The Universal Sentence Encoder model encodes text into high-dimensional vectors that can be used for various natural language processing tasks.


Embedding text into a high-dimensional vector

import tensorflow as tf
import tensorflow_hub as hub
embed = hub.load('https://tfhub.dev/google/universal-sentence-encoder/4')
embeddings = embed(['Hello world!'])

The Universal Sentence Encoder encodes text into high-dimensional vectors that can be used for text classification, semantic similarity, clustering, and other natural language tasks.


import tensorflow as tf
import tensorflow_hub as hub

model_id = 'https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/classification/4'
model = hub.load(model_id)

image = tf.keras.preprocessing.image.load_img('path/to/image.jpg', target_size=(224, 224))
image_array = tf.keras.preprocessing.image.img_to_array(image)
image_batch = tf.expand_dims(image_array, 0)

predictions = model(image_batch)

Load and use a pre-trained model from TensorFlow Hub for image classification


Input: text

import tensorflow_hub as hub
embed = hub.load('https://tfhub.dev/google/universal-sentence-encoder/4')
embeddings = embed(['Hello world'])

A pre-trained model for generating text embeddings using the Universal Sentence Encoder.


import tensorflow as tf
import tensorflow_hub as hub

feature_extractor = hub.KerasLayer('https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/feature_vector/4')
image_input = tf.keras.Input(shape=(224, 224, 3), dtype=tf.float32, name='input_image')
features = feature_extractor(image_input)

A pre-trained image feature vector model based on MobileNetV2 architecture, trained on ImageNet dataset. It is designed for efficient on-device image classification and related tasks.


import tensorflow as tf
import tensorflow_hub as hub

model = tf.keras.Sequential([
  hub.KerasLayer('https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/feature_vector/4', input_shape=[224, 224, 3])
])

# Load an image and preprocess it
image = tf.keras.preprocessing.image.load_img('path/to/your/image.jpg', target_size=(224, 224))
image = tf.keras.preprocessing.image.img_to_array(image)
image = tf.expand_dims(image, 0)

# Extract features from the image
features = model.predict(image)

A pre-trained deep learning model that extracts features from images using the MobileNetV2 architecture.


import tensorflow as tf
import tensorflow_hub as hub

model = tf.keras.Sequential([
    hub.KerasLayer('https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/classification/4',
                   input_shape=(224, 224, 3),
                   trainable=False)
])

predictions = model.predict(images)

A pre-trained image classification model using MobileNet V2 architecture on the ImageNet dataset. The model is designed to classify images into one of 1000 categories. It is available on TensorFlow Hub and can be easily integrated into a Keras model.


import tensorflow as tf
import tensorflow_hub as hub

model = tf.keras.Sequential([
    hub.KerasLayer('https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/feature_vector/4', input_shape=(224, 224, 3), trainable=False),
    tf.keras.layers.Dense(1, activation='sigmoid')
])

A pre-trained feature extraction model using MobileNetV2 architecture that takes an image input of shape (224, 224, 3) and outputs a 1280-dimensional feature vector. The model is trained on the ImageNet dataset.


Embedding text into a continuous vector space

input_text: A string or list of strings to be embedded

import tensorflow as tf
import tensorflow_hub as hub

embed = hub.load('https://tfhub.dev/google/universal-sentence-encoder/4')
embeddings = embed(['Hello, world!', 'How are you?'])
print(embeddings)

A pre-trained model for embedding text into a 512-dimensional vector space that can be used for various natural language processing tasks such as text classification, semantic similarity, clustering, and other downstream tasks.


A pre-trained MobileNetV2 model for image classification on ImageNet dataset with 224x224 input size and 1001 output classes.


import tensorflow as tf
import tensorflow_hub as hub

model = tf.keras.Sequential([
    hub.KerasLayer('https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/feature_vector/4'),
    tf.keras.layers.Dense(num_classes, activation='softmax')
])

A pre-trained image feature vector model based on MobileNetV2 architecture, useful for extracting features from images. The model is trained on ImageNet dataset and has an accuracy of 71.9%.


import tensorflow as tf
import tensorflow_hub as hub
embed = hub.load('https://tfhub.dev/google/universal-sentence-encoder/4')
embeddings = embed(['Hello world'])

A pre-trained model that encodes text into 512-dimensional embeddings using a deep averaging network (DAN). Useful for a variety of natural language processing tasks.


import tensorflow as tf
import tensorflow_hub as hub

model_id = 'https://tfhub.dev/google/imagenet/inception_v3/classification/5'
model = hub.load(model_id)

Load a pre-trained image classification model from TensorFlow Hub using the model_id


import tensorflow as tf
import tensorflow_hub as hub
model_id = 'https://tfhub.dev/google/imagenet/inception_v3/classification/5'
model = hub.load(model_id)
image = tf.keras.preprocessing.image.load_img('path/to/image.jpg', target_size=(299, 299))
image = tf.keras.preprocessing.image.img_to_array(image)
image = tf.expand_dims(image, axis=0)
image = tf.keras.applications.inception_v3.preprocess_input(image)
predictions = model(image)

A pre-trained model for image classification using TensorFlow Hub and Inception V3 architecture.


The Universal Sentence Encoder encodes text into high-dimensional vectors that can be used for various natural language processing tasks.


A 4D tensor with shape [batch_size, height, width, 3]

Output: A 2D tensor with shape [batch_size, num_features]

import tensorflow as tf
import tensorflow_hub as hub

model = tf.keras.Sequential([
    hub.KerasLayer('https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/feature_vector/4',
                   input_shape=(224,224,3),
                   trainable=False)
])

# Load an example image and preprocess it
image = tf.keras.preprocessing.image.load_img('example_image.jpg', target_size=(224, 224))
input_array = tf.keras.preprocessing.image.img_to_array(image)
input_array = tf.expand_dims(input_array, 0)

# Extract the features
features = model.predict(input_array)

A pre-trained model that takes a 224x224 RGB image as input and outputs a 1280-dimensional feature vector. Useful for transfer learning and fine-tuning on new image classification tasks.


import tensorflow as tf
import tensorflow_hub as hub

model_id = 'https://tfhub.dev/google/imagenet/inception_v3/classification/5'
model = hub.load(model_id)

image = tf.keras.preprocessing.image.load_img('path/to/image.jpg', target_size=(299, 299))
image = tf.keras.preprocessing.image.img_to_array(image)
image = tf.expand_dims(image, 0)

predictions = model(image)
print(predictions)

Load a pre-trained image classification model from TensorFlow Hub and use it to predict the class of an input image.


import tensorflow as tf
import tensorflow_hub as hub

model_id = 'https://tfhub.dev/google/tf2-preview/mobilenet_v2/classification/4'
model = hub.load(model_id)

image = tf.keras.preprocessing.image.load_img('path/to/your/image.jpg', target_size=(224, 224))
input_array = tf.keras.preprocessing.image.img_to_array(image)
input_array = tf.expand_dims(input_array, 0)
input_array = tf.keras.applications.mobilenet_v2.preprocess_input(input_array)

predictions = model(input_array)

A pre-trained model for image classification using TensorFlow Hub


This module uses the MobileNet_v2_100_224 architecture to extract image features. It takes an input image of shape [224, 224, 3] and outputs a feature vector of shape [1280].


import tensorflow_hub as hub; embed = hub.load('https://tfhub.dev/google/universal-sentence-encoder/4'); embeddings = embed(['Hello, world!'])

The Universal Sentence Encoder (USE) is a pre-trained model that encodes text into high-dimensional vectors. It is useful for various natural language processing tasks, such as text classification, semantic similarity, and clustering.


import tensorflow as tf
import tensorflow_hub as hub

model = tf.keras.Sequential([
    hub.KerasLayer('https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/feature_vector/4', input_shape=(224, 224, 3), trainable=False)
])

image = tf.random.normal([1, 224, 224, 3])
features = model(image)

A pre-trained image feature vector model using MobileNetV2 architecture on the ImageNet dataset. The model is designed to extract features from images and can be used for various tasks such as image classification, object detection, and image similarity.


import tensorflow as tf
import tensorflow_hub as hub

model = tf.keras.Sequential([
    hub.KerasLayer('https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/feature_vector/4',
                   input_shape=(224, 224, 3))
])

features = model.predict(images)

A pre-trained image feature vector model using MobileNetV2 architecture on ImageNet dataset. The model takes an image input of shape (224, 224, 3) and outputs a 1280-dimensional feature vector.


Embedding text using a pre-trained model

input_text: List of text strings to be embedded

import tensorflow_hub as hub
embed = hub.load('https://tfhub.dev/google/universal-sentence-encoder/4')
embeddings = embed(['Hello world!', 'How are you?'])

The Universal Sentence Encoder encodes text into high-dimensional vectors that can be used for text classification, semantic similarity, clustering and other natural language tasks.


Load and use pre-trained models for image classification

import tensorflow as tf
import tensorflow_hub as hub

model_id = 'https://tfhub.dev/google/tf2-preview/mobilenet_v2/classification/4'
model = hub.load(model_id)
image = tf.keras.preprocessing.image.load_img('path/to/your/image.jpg', target_size=(224, 224))
image_array = tf.keras.preprocessing.image.img_to_array(image)
image_array = tf.expand_dims(image_array, 0)

predictions = model(image_array)
predicted_class = tf.argmax(predictions[0])

This API allows you to load and use pre-trained models for image classification using TensorFlow Hub. You can use different model ids to load different models and perform image classification tasks.


input: A string or a list of strings to be embedded

import tensorflow_hub as hub
embed = hub.load('https://tfhub.dev/google/universal-sentence-encoder/4')
embeddings = embed(['Hello, world!', 'Embeddings for text'])

The Universal Sentence Encoder encodes text into high-dimensional vectors that can be used for text classification, semantic similarity, clustering, and other natural language tasks.


import tensorflow as tf
import tensorflow_hub as hub

model_id = 'https://tfhub.dev/google/tf2-preview/mobilenet_v2/classification/4'
model = hub.load(model_id)
result = model(image_tensor)

Load and use an image classification model from TensorFlow Hub to classify images into one of 1000 categories.


import tensorflow as tf
import tensorflow_hub as hub
model = hub.load('https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/classification/4')
image = tf.keras.preprocessing.image.load_img('path/to/image.jpg', target_size=(224, 224))
image = tf.keras.preprocessing.image.img_to_array(image)
image = tf.expand_dims(image, 0)
predictions = model(image)

A pre-trained image classification model using MobileNetV2 architecture, trained on ImageNet dataset, with 100% depth and 224x224 input size.


Image classification using pre-trained models

The URL of the TensorFlow Hub model or the path to the model on disk

import tensorflow as tf
import tensorflow_hub as hub

model_id = 'https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/classification/5'
model = hub.load(model_id)

image = tf.keras.preprocessing.image.load_img('path/to/your/image.jpg', target_size=(224, 224))
image_array = tf.keras.preprocessing.image.img_to_array(image)
image_array = tf.expand_dims(image_array, 0)

predictions = model(image_array)

TensorFlow Hub provides a collection of pre-trained image classification models that can be easily loaded and used for various image classification tasks. These models are trained on the ImageNet dataset and can be fine-tuned for specific use cases.


import tensorflow as tf
import tensorflow_hub as hub

model_id = 'https://tfhub.dev/google/tf2-preview/mobilenet_v2/classification/4'
model = hub.load(model_id)

Load a pre-trained image classification model from TensorFlow Hub and use it to classify images.


import tensorflow as tf
import tensorflow_hub as hub

model = hub.load('https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/classification/4')

# Prepare an image
image = tf.keras.preprocessing.image.load_img('path/to/your/image.jpg', target_size=(224, 224))
image = tf.keras.preprocessing.image.img_to_array(image)
image = tf.expand_dims(image, axis=0)

# Make predictions
predictions = model(image)

# Decode predictions
labels_path = tf.keras.utils.get_file('ImageNetLabels.txt','https://storage.googleapis.com/download.tensorflow.org/data/ImageNetLabels.txt')
imagenet_labels = np.array(open(labels_path).read().splitlines())

predicted_label = imagenet_labels[np.argmax(predictions[0])]
print(predicted_label)

MobileNetV2 for image classification, pretrained on ImageNet.


import tensorflow as tf
import tensorflow_hub as hub

model_id = 'https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/classification/4'
model = hub.load(model_id)

A pre-trained image classification model available on TensorFlow Hub, capable of classifying images into a large number of categories.


The identifier of the pre-trained model

import tensorflow as tf
import tensorflow_hub as hub

model_id = 'https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/classification/4'
model = hub.load(model_id)

image = tf.keras.preprocessing.image.load_img('path/to/your/image.jpg', target_size=(224, 224))
input_image = tf.keras.preprocessing.image.img_to_array(image)
input_image = tf.expand_dims(input_image, 0)

predictions = model(input_image)


import tensorflow as tf
import tensorflow_hub as hub

model = tf.keras.Sequential([
    hub.KerasLayer('https://tfhub.dev/google/imagenet/mobilenet_v2_130_224/classification/4')
])

image = tf.keras.preprocessing.image.load_img('path/to/your/image.jpg', target_size=(224, 224))
input_arr = tf.keras.preprocessing.image.img_to_array(image)
input_arr = np.array([input_arr])
predictions = model.predict(input_arr)

A pre-trained image classification model using MobileNetV2 architecture on ImageNet dataset


import tensorflow_hub as hub; embed = hub.load('https://tfhub.dev/google/universal-sentence-encoder/4'); embeddings = embed(['Hello world']); print(embeddings)


A tensor of shape [1, height, width, 3] containing a single image

import tensorflow as tf
import tensorflow_hub as hub

model = hub.load('https://tfhub.dev/tensorflow/faster_rcnn/resnet50_v1_640x640/1')
image_tensor = tf.convert_to_tensor(image, dtype=tf.float32)
detections = model(image_tensor)

A pre-trained Faster R-CNN model with ResNet-50 backbone for object detection in images


import tensorflow as tf
import tensorflow_hub as hub

model = hub.KerasLayer('https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/classification/4')

# Load and preprocess an image
image = tf.keras.preprocessing.image.load_img('path/to/your/image.jpg', target_size=(224, 224))
input_array = tf.keras.preprocessing.image.img_to_array(image)
input_array = tf.expand_dims(input_array, 0)
input_array /= 255.0

# Make predictions
predictions = model(input_array)

# Decode predictions to class names
class_names = tf.keras.applications.mobilenet_v2.decode_predictions(predictions.numpy())

A pre-trained image classification model using MobileNetV2 architecture and trained on ImageNet dataset.


Input: text

import tensorflow as tf
import tensorflow_hub as hub
embed = hub.load('https://tfhub.dev/google/universal-sentence-encoder/4')
text = ['This is a sample text.']
embeddings = embed(text)
print(embeddings)


Embedding text into a vector representation

import tensorflow as tf
import tensorflow_hub as hub
embed = hub.load('https://tfhub.dev/google/universal-sentence-encoder/4')
embeddings = embed(['Hello, world!'])

The Universal Sentence Encoder encodes text into high-dimensional vectors that can be used for various natural language processing tasks.


Input: List of strings

import tensorflow as tf
import tensorflow_hub as hub
embed = hub.load('https://tfhub.dev/google/universal-sentence-encoder/4')
embeddings = embed(['Hello world!', 'My name is John Doe'])


import tensorflow_hub as hub; embed = hub.load('https://tfhub.dev/google/universal-sentence-encoder/4'); embeddings = embed(['Hello world!'])

The Universal Sentence Encoder encodes text into high-dimensional vectors that can be used for various natural language processing tasks, such as semantic similarity, text classification, and clustering.


A string, the handle of the Hub module to load

import tensorflow as tf
import tensorflow_hub as hub

model = tf.keras.Sequential([
    hub.KerasLayer(handle="https://tfhub.dev/google/nnlm-en-dim128/2")
])

Loads a TensorFlow Hub module as a Keras Layer, allowing users to incorporate pre-trained models into their own custom models.


import tensorflow as tf
import tensorflow_hub as hub

model_id = 'https://tfhub.dev/tensorflow/centernet/hourglass_1024x1024/1'
detector = hub.load(model_id)

# Load an image
image = tf.keras.preprocessing.image.load_img('path/to/image.jpg')

# Process the image
input_image = tf.keras.preprocessing.image.img_to_array(image)
input_image = tf.image.resize(input_image, (1024, 1024))
input_image = tf.expand_dims(input_image, axis=0) / 255.0

# Detect objects
results = detector(input_image)

# Print the results
print(results)

A pre-trained TensorFlow Hub model for detecting objects in images using the CenterNet architecture with an Hourglass backbone.


A unique identifier for the pre-trained model

import tensorflow as tf
import tensorflow_hub as hub

model_id = 'https://tfhub.dev/tensorflow/ssd_mobilenet_v2/2'
detector = hub.load(model_id)

image = tf.image.decode_jpeg(tf.io.read_file('path/to/image.jpg'))
image = tf.image.resize(image, (300, 300))
image = tf.expand_dims(image, 0)

results = detector(image)

print(results['detection_boxes'])
print(results['detection_classes'])
print(results['detection_scores'])

A pre-trained model for detecting objects in images using TensorFlow Hub


import tensorflow as tf
import tensorflow_hub as hub

detector = hub.load('https://tfhub.dev/tensorflow/faster_rcnn/resnet50_v1_640x640/1')
image_tensor = tf.image.decode_image(tf.io.read_file('path/to/image.jpg'))
result = detector(image_tensor[tf.newaxis, ...])

A pre-trained Faster R-CNN model with ResNet-50 as the backbone for object detection in images. The model is trained on the COCO dataset and can detect objects from 80 different classes.


The ID of the model to load from TensorFlow Hub

import tensorflow as tf
import tensorflow_hub as hub

model_id = 'https://tfhub.dev/tensorflow/ssd_mobilenet_v2/2'
detector = hub.load(model_id)

# Load an image, preprocess it, and run the detector
image = tf.keras.preprocessing.image.load_img('path/to/image.jpg')
input_image = tf.keras.preprocessing.image.img_to_array(image)
input_image = tf.image.resize(input_image, (300, 300))
input_image = tf.expand_dims(input_image, 0)

# Run the detector
output = detector(input_image)

# Process the output
for i in range(output['num_detections']):
    if output['detection_scores'][i] > 0.5:
        print('Detected object:', output['detection_class_entities'][i], 'with confidence:', output['detection_scores'][i])

A pre-trained object detection model that can detect objects in images using TensorFlow Hub


The Universal Sentence Encoder encodes text into high-dimensional vectors that can be used for various text-related tasks such as semantic similarity, clustering, and classification.


import tensorflow as tf
import tensorflow_hub as hub

model_id = 'https://tfhub.dev/google/tf2-preview/mobilenet_v2/classification/4'
model = hub.load(model_id)


import tensorflow as tf
import tensorflow_hub as hub

model = tf.keras.Sequential([
    hub.KerasLayer('https://tfhub.dev/google/imagenet/inception_v3/feature_vector/5', trainable=False),
    tf.keras.layers.Dense(1000, activation='softmax')
])

model.build([None, 299, 299, 3])
model.summary()

This API provides a compact representation of images using the Inception V3 model from TensorFlow Hub. It extracts feature vectors from images, which can be used for various machine learning tasks such as classification and clustering.


import tensorflow as tf
import tensorflow_hub as hub
embed = hub.load('https://tfhub.dev/google/universal-sentence-encoder/4')
embeddings = embed(['Hello world!'])
print(embeddings)

A pre-trained text embedding model that converts sentences into fixed-size vectors, suitable for various natural language processing tasks.


import tensorflow_hub as hub
import tensorflow as tf

model = tf.keras.Sequential([
    hub.KerasLayer('https://tfhub.dev/google/imagenet/mobilenet_v2_140_224/feature_vector/4', input_shape=[224, 224, 3], output_shape=[140])
])

image = tf.keras.Input(shape=(224, 224, 3))
features = model(image)

A pre-trained image feature vector model using MobileNetV2 architecture on ImageNet dataset. It can be used to extract features from images for various machine learning tasks.


list of tensors representing bounding boxes, classes, scores, and number of detections

import tensorflow as tf
import tensorflow_hub as hub

detector = hub.load('https://tfhub.dev/tensorflow/ssd_mobilenet_v2_fpnlite_640x640/1')
image_tensor = tf.convert_to_tensor(image, dtype=tf.uint8)
input_tensor = tf.expand_dims(image_tensor, axis=0)
output_dict = detector(input_tensor)

A pre-trained object detection model that detects objects in images using the Single Shot MultiBox Detector (SSD) architecture with MobileNet V2 FPN-Lite feature extractor.


import tensorflow as tf
import tensorflow_hub as hub
model_id = 'https://tfhub.dev/google/universal-sentence-encoder/4'
embed = hub.load(model_id)
embeddings = embed(['Hello, world!'])

This API allows you to embed text using a pre-trained model from TensorFlow Hub. It can be used for various natural language processing tasks, such as text classification, semantic similarity, and clustering.


import tensorflow as tf
import tensorflow_hub as hub

model_id = 'https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/classification/4'
model = hub.load(model_id)

Load a pre-trained image classification model from TensorFlow Hub using the provided model_id.


import tensorflow as tf
import tensorflow_hub as hub

model = tf.keras.Sequential([
    hub.KerasLayer('https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/feature_vector/4',
                    input_shape=(224,224,3),
                    output_shape=(1280,))
])

image = tf.random.uniform((1, 224, 224, 3))
features = model(image)

A pre-trained model that extracts a 1280-dimensional feature vector from images using MobileNetV2 architecture.


import tensorflow as tf
import tensorflow_hub as hub

model = tf.keras.Sequential([
    hub.KerasLayer('https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/feature_vector/4',
                   input_shape=(224, 224, 3),
                   trainable=False),
    tf.keras.layers.Dense(num_classes, activation='softmax')
])

model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])

history = model.fit(train_batches, epochs=10, validation_data=validation_batches)

This module uses MobileNet v2 architecture for image feature vector extraction. It takes an input image of shape (224, 224, 3) and outputs a 1280-dimensional feature vector.


import tensorflow_hub as hub
model = hub.KerasLayer('https://tfhub.dev/google/tf2-preview/mobilenet_v2/classification/4')


Loading pre-trained image classification models

import tensorflow as tf
import tensorflow_hub as hub

model_id = 'https://tfhub.dev/google/imagenet/mobilenet_v2_130_224/classification/5'
model = hub.KerasLayer(model_id)

image = tf.keras.preprocessing.image.load_img('image.jpg', target_size=(224, 224))
image_array = tf.keras.preprocessing.image.img_to_array(image)
image_array = tf.expand_dims(image_array, 0)

predictions = model(image_array)
print(predictions)

This API allows users to load pre-trained image classification models from TensorFlow Hub and make predictions on images.


A pre-trained image feature vector model using MobileNetV2 architecture on ImageNet dataset.


import tensorflow as tf
import tensorflow_hub as hub
embed = hub.load('https://tfhub.dev/google/universal-sentence-encoder/4')
embeddings = embed(['Hello, world!'])
print(embeddings)

The Universal Sentence Encoder encodes text into high-dimensional vectors that can be used for text classification, semantic similarity, clustering, and other natural language tasks.


import tensorflow as tf
import tensorflow_hub as hub
model_id = 'https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/classification/4'
model = hub.load(model_id)
image = tf.keras.preprocessing.image.load_img('path/to/image.jpg', target_size=(224, 224))
image_array = tf.keras.preprocessing.image.img_to_array(image)
image_array = tf.expand_dims(image_array, 0)
image_array = tf.keras.applications.mobilenet_v2.preprocess_input(image_array)
predictions = model(image_array)

A pre-trained image classification model using MobileNetV2 architecture on ImageNet dataset.


import tensorflow_hub as hub
embed = hub.load('https://tfhub.dev/google/universal-sentence-encoder/4')
embeddings = embed(['Hello world', 'Embedding with TensorFlow Hub'])

The Universal Sentence Encoder generates embeddings for input text that can be used for tasks like semantic similarity, classification, and clustering.


import tensorflow as tf
import tensorflow_hub as hub
embed = hub.load('https://tfhub.dev/google/universal-sentence-encoder/4')
embeddings = embed(['Hello, world!', 'Embedding with Universal Sentence Encoder'])

A pre-trained model that converts text into high-dimensional vectors for downstream tasks such as sentiment analysis, translation, and classification.


Input: image tensor

Output: feature vector

import tensorflow as tf
import tensorflow_hub as hub

model = tf.keras.Sequential([
    hub.KerasLayer('https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/feature_vector/4',
                   input_shape=(224, 224, 3),
                   trainable=False)
])

image = tf.zeros([1, 224, 224, 3])
feature_vector = model(image)

A pre-trained model that generates feature vectors from images using MobileNetV2 architecture on ImageNet dataset.


import tensorflow as tf
import tensorflow_hub as hub

model_id = 'https://tfhub.dev/google/imagenet/inception_v3/feature_vector/1'
model = hub.load(model_id)
image = tf.random.normal([1, 299, 299, 3])
features = model(image)

Load a pre-trained image feature vector model from TensorFlow Hub and use it to extract features from an image.


import tensorflow as tf
import tensorflow_hub as hub
model = tf.keras.Sequential([
    hub.KerasLayer('https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/feature_vector/4',
                   input_shape=(224, 224, 3),
                   trainable=False)
])

# Load image
image = tf.keras.preprocessing.image.load_img('path/to/image.jpg', target_size=(224, 224))
image_array = tf.keras.preprocessing.image.img_to_array(image)
image_array = tf.expand_dims(image_array, 0)

# Generate feature vector
features = model.predict(image_array)

This API provides a pre-trained MobileNetV2 model for generating feature vectors from images. The feature vectors can be used for various machine learning tasks, such as image classification, clustering, or similarity search.


import tensorflow_hub as hub
import tensorflow as tf

model = tf.keras.Sequential([
    hub.KerasLayer('https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/feature_vector/4', input_shape=(224, 224, 3), trainable=False),
    tf.keras.layers.Dense(1000, activation='softmax')
])

A pre-trained image feature vector model based on MobileNetV2 architecture, trained on ImageNet dataset. The model takes an image of size 224x224x3 as input and outputs a 1280-dimensional feature vector. It can be used for various image classification tasks.


Embeds text inputs into high-dimensional vectors

Input: A list of strings

import tensorflow as tf
import tensorflow_hub as hub
embed = hub.load('https://tfhub.dev/google/universal-sentence-encoder/4')
embeddings = embed(['Hello world!', 'How are you?'])
print(embeddings)

The Universal Sentence Encoder encodes text into high-dimensional vectors that can be used for text classification, semantic similarity, clustering, and other natural language tasks. The model is trained and optimized for greater-than-word length text, such as sentences, phrases, or short paragraphs.


Embed text data for machine learning models

A string representing the URL or path to the TensorFlow Hub model

import tensorflow as tf
import tensorflow_hub as hub

model_id = 'https://tfhub.dev/google/tf2-preview/nnlm-en-dim50/1'
embed = hub.load(model_id)
embeddings = embed(['Hello, world!'])
print(embeddings)

Load a pre-trained text embedding model from TensorFlow Hub, and use it to convert text data into fixed-size vectors that can be used as input for machine learning models.


import tensorflow as tf
import tensorflow_hub as hub
model_id = 'https://tfhub.dev/google/imagenet/mobilenet_v2_130_224/classification/4'
model = hub.load(model_id)

A pre-trained image classification model available on TensorFlow Hub for classifying images into one of 1000 categories.


import tensorflow as tf
import tensorflow_hub as hub

model = tf.keras.Sequential([
    hub.KerasLayer('https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/feature_vector/4',
                   input_shape=(224, 224, 3),
                   output_shape=(1280,))
])

A pre-trained image feature vector model based on MobileNet V2 with 100% depth and 224x224 input size. Useful for extracting features from images.


import tensorflow as tf
import tensorflow_hub as hub

model = hub.load('https://tfhub.dev/google/model_id/1')
embeddings = model(samples)

A pre-trained audio embedding model for extracting features from audio data using TensorFlow Hub.


import tensorflow as tf
import tensorflow_hub as hub
model = tf.keras.Sequential([
    hub.KerasLayer('https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/classification/4')
])

A pre-trained image classification model using MobileNetV2 architecture with 100% depth and 224x224 input size, trained on ImageNet dataset.


A pre-trained image feature vector model using MobileNet V2 with 100% depth_multiplier and 224x224 input image size.


Embed text data for machine learning tasks

import tensorflow as tf
import tensorflow_hub as hub
embed = hub.load('https://tfhub.dev/google/universal-sentence-encoder/4')
text_input = ['This is a sample text.']
embeddings = embed(text_input)


import tensorflow_hub as hub; embed = hub.load('https://tfhub.dev/google/universal-sentence-encoder/4'); embeddings = embed(['Hello, world!'])

STS (Semantic Textual Similarity) Benchmark

The Universal Sentence Encoder encodes text into high-dimensional vectors that can be used for text classification, semantic similarity, clustering, and other natural language tasks. It is trained and optimized for greater-than-word length text, such as sentences, phrases, or short paragraphs.


import tensorflow as tf
import tensorflow_hub as hub
segmentation = hub.load('https://tfhub.dev/tensorflow/deeplabv3/1')
input_tensor = tf.random.uniform(shape=[1, 1024, 1024, 3], dtype=tf.float32)
output = segmentation(input_tensor)

DeepLabv3 is a state-of-the-art semantic segmentation model that uses atrous convolution and fully connected conditional random fields for dense prediction. It can be used for various image segmentation tasks, such as object segmentation, scene parsing, and person segmentation.


import tensorflow as tf
import tensorflow_hub as hub

model = tf.keras.Sequential([
    hub.KerasLayer('https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/feature_vector/4',
                   input_shape=(224, 224, 3),
                   trainable=False),
    tf.keras.layers.Dense(1, activation='sigmoid')
])

model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])

# Train and evaluate the model
# model.fit(train_data, train_labels, epochs=5)
# model.evaluate(test_data, test_labels)

A pre-trained image feature vector model based on MobileNetV2 architecture, which is optimized for low-latency and small size, while maintaining competitive accuracy on the ImageNet dataset.


A pre-trained image classification model using MobileNetV2 architecture trained on ImageNet dataset.


import tensorflow as tf
import tensorflow_hub as hub

model = tf.keras.Sequential([
    hub.KerasLayer('https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/feature_vector/4', input_shape=(224, 224, 3))
])

image = tf.zeros([1, 224, 224, 3])  # A batch of one 224x224x3 image
features = model(image)  # Features with shape [batch_size, 1280]

A pre-trained image feature vector model based on MobileNetV2 architecture for image classification tasks.


Load and use a pre-trained image feature vector model

import tensorflow as tf
import tensorflow_hub as hub

model = hub.load('https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/feature_vector/4')

image = tf.zeros([1, 224, 224, 3])
features = model(image)

This module uses the MobileNet v2 architecture to generate image feature vectors. The model has been pre-trained on the ImageNet dataset and can be used for various image classification tasks.


embeddings = embed(['Hello world', 'Embedding with TensorFlow Hub'])

The Universal Sentence Encoder encodes text into high-dimensional vectors that can be used for text classification, semantic similarity, clustering, and other natural language tasks.


import tensorflow_hub as hub; embed = hub.load('https://tfhub.dev/google/universal-sentence-encoder/4'); embeddings = embed(['Hello world!'])


Input: Text input

import tensorflow_hub as hub
embed = hub.load('https://tfhub.dev/google/universal-sentence-encoder/4')
embeddings = embed(['Hello world!'])

A pre-trained model for generating text embeddings using TensorFlow Hub.


import tensorflow as tf
import tensorflow_hub as hub

model = tf.keras.Sequential([
    hub.KerasLayer('https://tfhub.dev/google/imagenet/mobilenet_v2_130_224/classification/4')
])

image = tf.keras.preprocessing.image.load_img('path/to/image.jpg', target_size=(224, 224))
input_arr = tf.keras.preprocessing.image.img_to_array(image)
input_arr = np.array([input_arr])

predictions = model.predict(input_arr)

A pre-trained image classification model using MobileNetV2 architecture with 130 depth multiplier and 224x224 input size. The model has been trained on the ImageNet dataset and can be used for classifying images into 1000 different categories.


import tensorflow as tf
import tensorflow_hub as hub

model = tf.keras.Sequential([
    hub.KerasLayer('https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/feature_vector/4', input_shape=[224, 224, 3], output_shape=[1280])
])

image = tf.keras.preprocessing.image.load_img('path/to/your/image.jpg', target_size=(224, 224))
image_array = tf.keras.preprocessing.image.img_to_array(image)
image_array = tf.expand_dims(image_array, 0)

features = model.predict(image_array)

A pre-trained model that extracts 1280-dimensional feature vectors from 224x224 RGB images using MobileNetV2 architecture.


import tensorflow as tf
import tensorflow_hub as hub
embed = hub.load('https://tfhub.dev/google/universal-sentence-encoder/4')
embeddings = embed(['Hello world', 'Embedding with TensorFlow Hub'])
print(embeddings)

This API allows you to embed text data using the Universal Sentence Encoder model from TensorFlow Hub.


import tensorflow as tf
import tensorflow_hub as hub

model_id = 'https://tfhub.dev/google/imagenet/inception_v3/classification/5'
model = hub.load(model_id)

Load pre-trained image classification models from TensorFlow Hub for easy integration and usage.


Loading a pre-trained model for image classification

import tensorflow as tf
import tensorflow_hub as hub

model = hub.KerasLayer('https://tfhub.dev/google/tf2-preview/mobilenet_v2/classification/2', input_shape=(224, 224, 3))

# Load an image and preprocess it
image = tf.keras.preprocessing.image.load_img('path/to/image.jpg', target_size=(224, 224))
input_image = tf.keras.preprocessing.image.img_to_array(image)
input_image = tf.expand_dims(input_image, 0)

# Make predictions
predictions = model(input_image)

# Decode predictions
decoded_predictions = tf.keras.applications.mobilenet_v2.decode_predictions(predictions.numpy())

print(decoded_predictions)

A pre-trained image classification model using MobileNetV2 architecture, with 224x224 input size, and 100% depth multiplier. The model is trained on the ImageNet dataset and can be used for various image classification tasks.


Pre-trained model for image classification

import tensorflow as tf
import tensorflow_hub as hub

model = tf.keras.Sequential([
    hub.KerasLayer('https://tfhub.dev/google/imagenet/mobilenet_v2_130_224/classification/4')
])

image = tf.keras.preprocessing.image.load_img('path/to/your/image.jpg', target_size=(224, 224))
image_array = tf.keras.preprocessing.image.img_to_array(image)
image_array = tf.expand_dims(image_array, 0)

predictions = model(image_array)

print(predictions)

A pre-trained image classification model using MobileNetV2 architecture with 130 depth multiplier and input size of 224x224 pixels.


import tensorflow as tf
import tensorflow_hub as hub

model = tf.keras.Sequential([
    hub.KerasLayer('https://tfhub.dev/google/imagenet/resnet_v2_50/feature_vector/5',
                   input_shape=(224, 224, 3),
                   dtype=tf.float32,
                   trainable=True)
])

image = tf.zeros([1, 224, 224, 3])
features = model(image)

Top-1 Accuracy: 76.3%, Top-5 Accuracy: 93.0%

This module uses the ResNet-50 v2 architecture to extract high-level features from images. It is pre-trained on the ImageNet dataset and can be used for various computer vision tasks.


import tensorflow as tf
import tensorflow_hub as hub
embed = hub.load('https://tfhub.dev/google/universal-sentence-encoder/4')
embeddings = embed(['Hello world'])
print(embeddings)

Pearson correlation coefficient of 0.803521

This API provides a method to convert text into a high-dimensional vector using the Universal Sentence Encoder from TensorFlow Hub. It can be used for tasks such as semantic similarity and clustering.


import tensorflow as tf
import tensorflow_hub as hub

model = tf.keras.Sequential([
    hub.KerasLayer('https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/feature_vector/4',
                   input_shape=(224, 224, 3),
                   trainable=False)
])

# Example input: a batch of images with shape [batch_size, 224, 224, 3].
images = tf.random.uniform((4, 224, 224, 3))

# Extract features for the batch of images.
features = model(images)

A pre-trained image feature vector model using MobileNet V2 architecture on ImageNet dataset, with 100% depth multiplier and 224x224 input image resolution. Useful for extracting features from images.


Loading pre-trained models for image classification

import tensorflow as tf
import tensorflow_hub as hub
model_id = 'https://tfhub.dev/google/imagenet/mobilenet_v2_130_224/classification/5'
model = hub.load(model_id)

Load a pre-trained image classification model from TensorFlow Hub using the specified model_id.


model = tf.keras.Sequential([
    hub.KerasLayer('https://tfhub.dev/google/imagenet/mobilenet_v1_100_224/feature_vector/4', input_shape=[224, 224, 3], trainable=False),
    tf.keras.layers.Dense(10, activation='softmax')
])

A compact representation of the API for extracting image feature vectors using MobileNetV1 on TensorFlow Hub.


import tensorflow as tf
import tensorflow_hub as hub
data_root = tf.keras.utils.get_file('flower_photos','https://storage.googleapis.com/download.tensorflow.org/example_images/flower_photos.tgz', untar=True)
image_generator = tf.keras.preprocessing.image.ImageDataGenerator(rescale=1/255)
image_data = image_generator.flow_from_directory(str(data_root), target_size=IMAGE_SHAPE)
feature_extractor_url = 'https://tfhub.dev/google/imagenet/inception_v3/classification/5'
feature_extractor_layer = hub.KerasLayer(feature_extractor_url, input_shape=(299,299,3))
feature_extractor_layer.trainable = False
model = tf.keras.Sequential([
  feature_extractor_layer,
  tf.keras.layers.Dense(image_data.num_classes, activation='softmax')
])
model.compile(optimizer=tf.keras.optimizers.Adam(), loss='categorical_crossentropy', metrics=['acc'])
steps_per_epoch = np.ceil(image_data.samples/image_data.batch_size)
hist = model.fit(image_data, epochs=6, steps_per_epoch=steps_per_epoch)

Inception V3 model for image classification, pretrained on ImageNet dataset.


Load a pre-trained image classification model from TensorFlow Hub using the model_id.


Embedding text into high-dimensional vectors

Input: Text input

import tensorflow_hub as hub
embed = hub.load('https://tfhub.dev/google/universal-sentence-encoder/4')
embeddings = embed(['Hello world'])


Input: List of strings (sentences)

import tensorflow_hub as hub
embed = hub.load('https://tfhub.dev/google/universal-sentence-encoder/4')
embeddings = embed(['Hello world!', 'Embedding with TensorFlow Hub'])

The Universal Sentence Encoder (USE) is a pre-trained model that encodes text into high-dimensional vectors, which can be used for various natural language processing tasks.


import tensorflow_hub as hub
model = hub.load('https://tfhub.dev/google/imagenet/inception_v3/classification/5')


import tensorflow as tf
import tensorflow_hub as hub

model = hub.load('https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/classification/4')

def predict(image):
    logits = model(image)
    return logits

A pre-trained MobileNetV2 model for image classification on the ImageNet dataset, with a 224x224 input size and 100% depth multiplier. This model is optimized for low-latency and small size, making it suitable for mobile and edge devices.


The Universal Sentence Encoder encodes text into high-dimensional vectors that can be used for text classification, semantic similarity, clustering, and other natural language tasks.


import tensorflow_hub as hub
import tensorflow as tf

model = tf.keras.Sequential([
    hub.KerasLayer('https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/feature_vector/4',
                   input_shape=(224,224,3),
                   trainable=False)
])

image = tf.keras.Input(shape=(224, 224, 3))
features = model(image)

A pre-trained image feature extraction model using MobileNet V2 architecture on ImageNet dataset. It can be used to extract high-level features from images for various applications like image classification, object detection, and image similarity.


import tensorflow_hub as hub; embed = hub.load('https://tfhub.dev/google/universal-sentence-encoder/4'); embeddings = embed(['Hello world'])

The Universal Sentence Encoder encodes text into high-dimensional vectors that can be used for text classification, semantic similarity, clustering and other natural language tasks. The model is trained and optimized for greater-than-word length text, such as sentences, phrases or short paragraphs.


Load a pre-trained image classification model from TensorFlow Hub using the provided model_id.


import tensorflow as tf
import tensorflow_hub as hub

model = hub.load('https://tfhub.dev/google/imagenet/mobilenet_v2_130_224/classification/4')
image = tf.keras.preprocessing.image.load_img('path_to_your_image.jpg', target_size=(224, 224))
image_array = tf.keras.preprocessing.image.img_to_array(image)
image_array = tf.expand_dims(image_array, 0)

predictions = model(image_array)
print(predictions)

A pre-trained image classification model using MobileNetV2 architecture with 130 depth multiplier and 224x224 input size


import tensorflow as tf
import tensorflow_hub as hub

model_id = 'https://tfhub.dev/google/imagenet/inception_v3/classification/5'
model = hub.load(model_id)

image = tf.keras.preprocessing.image.load_img('path/to/image.jpg', target_size=(299, 299))
input_image = tf.keras.preprocessing.image.img_to_array(image)
input_image = tf.expand_dims(input_image, 0)

predictions = model(input_image)

A pre-trained image classification model using TensorFlow Hub that can classify images into 1000 different categories. The model used is Inception V3 trained on the ImageNet dataset.


import tensorflow as tf, tensorflow_hub as hub
model = hub.load('https://tfhub.dev/google/imagenet/mobilenet_v2_130_224/classification/4')
input_image = tf.zeros([1, 224, 224, 3])
output = model(input_image)

A pre-trained model for image classification using MobileNetV2 architecture, trained on ImageNet dataset. The model is optimized for low-latency and small model size, suitable for mobile and edge devices.


import tensorflow as tf
import tensorflow_hub as hub

model = hub.load('https://tfhub.dev/google/imagenet/mobilenet_v2_130_224/classification/4')

# Load and preprocess an image
image = tf.keras.preprocessing.image.load_img('path/to/your/image.jpg', target_size=(224, 224))
image = tf.keras.preprocessing.image.img_to_array(image)
image = tf.expand_dims(image, 0)

# Run the model
predictions = model(image)

# Decode the predictions
class_names = tf.keras.applications.mobilenet_v2.decode_predictions(predictions, top=1)
print(class_names)

A pre-trained image classification model using MobileNetV2 architecture on the ImageNet dataset.


import tensorflow as tf
import tensorflow_hub as hub

model_id = 'https://tfhub.dev/google/imagenet/inception_v3/classification/5'
model = tf.keras.Sequential([hub.KerasLayer(model_id)])

image = tf.keras.preprocessing.image.load_img('path/to/image.jpg', target_size=(299, 299))
image = tf.keras.preprocessing.image.img_to_array(image)
image = tf.keras.applications.inception_v3.preprocess_input(image)
image = tf.expand_dims(image, axis=0)

predictions = model.predict(image)

Load a pre-trained Inception V3 model from TensorFlow Hub for image classification.


import tensorflow as tf
import tensorflow_hub as hub
model_id = 'https://tfhub.dev/google/imagenet/inception_v3/classification/5'
model = hub.load(model_id)


import tensorflow as tf
import tensorflow_hub as hub

model_id = 'https://tfhub.dev/google/imagenet/inception_v3/classification/5'
model = hub.load(model_id)

# Load and preprocess an image
image = tf.keras.preprocessing.image.load_img('path/to/image.jpg', target_size=(299, 299))
image_array = tf.keras.preprocessing.image.img_to_array(image)
image_array = tf.expand_dims(image_array, 0)

# Make a prediction
predictions = model(image_array)

# Decode the predictions
class_names = tf.keras.applications.inception_v3.decode_predictions(predictions.numpy())

This API allows you to load pre-trained models for image classification using TensorFlow Hub. The example provided demonstrates how to load the Inception V3 model, preprocess an image, make a prediction, and decode the predictions into class names.


import tensorflow as tf
import tensorflow_hub as hub

model_id = 'https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/classification/4'
model = hub.load(model_id)
image = tf.zeros([1, 224, 224, 3])
output = model(image)
print(output)

This API allows users to load a pre-trained image classification model from TensorFlow Hub and use it to classify images. The example provided demonstrates how to load the MobileNetV2 model, create a sample image input, and obtain the classification output.


import tensorflow as tf
import tensorflow_hub as hub
model = hub.load('https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/classification/4')
image = tf.zeros([1, 224, 224, 3])  # A batch of images with shape [batch_size, height, width, 3].
logits = model(image)  # Logits with shape [batch_size, 1001].

A pre-trained image classification model using MobileNetV2 architecture on ImageNet dataset.


import tensorflow as tf
import tensorflow_hub as hub

model_id = 'https://tfhub.dev/tensorflow/ssd_mobilenet_v2/2'
detector = hub.load(model_id)

# Load an image
image = tf.keras.preprocessing.image.load_img('path/to/image.jpg')

# Convert the image to a tensor
input_tensor = tf.keras.preprocessing.image.img_to_array(image)

# Run the object detection
results = detector(input_tensor)

A pre-trained TensorFlow Hub model for detecting objects in images using the Single Shot MultiBox Detector (SSD) with MobileNet V2.


import tensorflow as tf
import tensorflow_hub as hub

model_id = 'https://tfhub.dev/tensorflow/ssd_mobilenet_v2/2'
detector = hub.load(model_id)
image_tensor = tf.image.decode_jpeg(tf.io.read_file('image.jpg'))
input_tensor = tf.expand_dims(image_tensor, 0)
detections = detector(input_tensor)

The API allows users to detect objects in images using a pre-trained model from TensorFlow Hub.


input: A tensor of strings containing the text to embed

import tensorflow as tf; import tensorflow_hub as hub; embed = hub.load('https://tfhub.dev/google/universal-sentence-encoder/4'); embeddings = embed(['Hello world!']); print(embeddings)

A pre-trained model that converts text into high-dimensional vectors for various NLP tasks


import tensorflow as tf
import tensorflow_hub as hub

model_id = 'https://tfhub.dev/tensorflow/ssd_mobilenet_v2/2'
detector = hub.load(model_id)

image = tf.image.decode_image(tf.io.read_file('path/to/image.jpg'))
result = detector(image[tf.newaxis, ...])

A pre-trained TensorFlow Hub model for detecting objects in images using the SSD Mobilenet V2 architecture.


The model ID of the TensorFlow Hub object detection model

import tensorflow as tf
import tensorflow_hub as hub

model_id = 'https://tfhub.dev/tensorflow/ssd_mobilenet_v2/2'
detector = hub.load(model_id)

image = tf.keras.preprocessing.image.load_img('path/to/image.jpg')
image_array = tf.keras.preprocessing.image.img_to_array(image)
input_tensor = tf.convert_to_tensor(image_array)
input_tensor = input_tensor[tf.newaxis, ...]

detections = detector(input_tensor)

A pre-trained TensorFlow Hub object detection model that can detect multiple objects in an image, based on the SSD MobileNet V2 architecture.


import tensorflow as tf
import tensorflow_hub as hub

model_id = 'https://tfhub.dev/google/imagenet/inception_v3/classification/5'
model = hub.load(model_id)

# Load image and preprocess
image = tf.keras.preprocessing.image.load_img('path/to/image.jpg', target_size=(299, 299))
image = tf.keras.preprocessing.image.img_to_array(image)
image = tf.keras.applications.inception_v3.preprocess_input(image)

# Make prediction
predictions = model(tf.expand_dims(image, 0))

# Decode predictions
class_names = tf.keras.applications.inception_v3.decode_predictions(predictions.numpy(), top=5)
for class_name in class_names[0]:
    print(class_name)

This API allows you to load a pre-trained Inception V3 model from TensorFlow Hub for image classification tasks. The model is trained on the ImageNet dataset and achieves an accuracy of 77.9%.


import tensorflow as tf
import tensorflow_hub as hub
embed = hub.load('https://tfhub.dev/google/universal-sentence-encoder/4')
embeddings = embed(['Hello world!'])

The Universal Sentence Encoder encodes text into high-dimensional vectors that can be used for various natural language processing tasks.


Input: List of sentences

import tensorflow_hub as hub
embed = hub.load('https://tfhub.dev/google/universal-sentence-encoder/4')
sentences = ['Hello, world!', 'Embeddings are fun!']
embeddings = embed(sentences).numpy()

The Universal Sentence Encoder encodes text into high-dimensional vectors that can be used for text classification, semantic similarity, clustering and other natural language tasks.


import tensorflow as tf
import tensorflow_hub as hub
embed = hub.load('https://tfhub.dev/google/universal-sentence-encoder/4')
embeddings = embed(['Hello world!'])
print(embeddings)

The Universal Sentence Encoder encodes text into high-dimensional vectors that can be used for text classification, semantic similarity, clustering, and other natural language tasks.


Input: List of sentences

import tensorflow_hub as hub; embed = hub.load('https://tfhub.dev/google/universal-sentence-encoder/4'); embeddings = embed(['sample sentence'])


import tensorflow_hub as hub; embed = hub.load('https://tfhub.dev/google/universal-sentence-encoder/4'); embeddings = embed(['Hello, world!'])

The Universal Sentence Encoder encodes text into high-dimensional vectors that can be used for text classification, semantic similarity, clustering, and other natural language tasks. The model is trained and optimized for greater-than-word length text, such as sentences, phrases, or short paragraphs.


import tensorflow as tf
import tensorflow_hub as hub

model_id = 'https://tfhub.dev/tensorflow/ssd_mobilenet_v2/2'
detector = hub.load(model_id)

image = tf.keras.preprocessing.image.load_img('path/to/image.jpg')
image = tf.keras.preprocessing.image.img_to_array(image)
image = tf.expand_dims(image, axis=0)

result = detector(image)

This API allows for object detection in images using a pre-trained model from TensorFlow Hub. The model used in this example is the SSD MobileNet V2, which has been trained on the COCO dataset.


import tensorflow as tf
import tensorflow_hub as hub

model_id = 'https://tfhub.dev/tensorflow/ssd_mobilenet_v2/2'
detector = hub.load(model_id)

image = tf.image.decode_jpeg(tf.io.read_file('path/to/image.jpg'))
image = tf.image.resize(image, (300, 300))
image = tf.expand_dims(image, axis=0)

result = detector(image)
print(result['detection_boxes'], result['detection_scores'], result['detection_classes'])

A TensorFlow Hub model for detecting objects in images using the SSD Mobilenet V2 architecture


import tensorflow as tf
import tensorflow_hub as hub

model_id = 'https://tfhub.dev/google/faster_rcnn/openimages_v4/inception_resnet_v2/1'
detector = hub.load(model_id)
image = tf.image.decode_jpeg(tf.io.read_file('path/to/image.jpg'))
converted_image = tf.image.convert_image_dtype(image, tf.float32)[tf.newaxis, ...]
result = detector(converted_image)

A pre-trained image object detection model that detects objects in images using the Faster R-CNN architecture with Inception-ResNet V2 as the feature extractor.


import tensorflow_hub as hub; embed = hub.load('https://tfhub.dev/google/universal-sentence-encoder/4'); embeddings = embed(['Hello world!'])


model = tf.keras.Sequential([
    hub.KerasLayer('https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/feature_vector/4', input_shape=(224, 224, 3), trainable=False),
    tf.keras.layers.Dense(10, activation='softmax')
])

A pre-trained image feature vector model using MobileNet V2 architecture on ImageNet dataset with input size of 224x224 pixels and output size of 1280 features.


import tensorflow as tf
import tensorflow_hub as hub

model_id = 'https://tfhub.dev/tensorflow/efficientdet/lite0/detection/1'
loaded_model = hub.load(model_id)

image = tf.keras.preprocessing.image.load_img('image_path')
image = tf.keras.preprocessing.image.img_to_array(image)
image = image / 255.0
image = tf.expand_dims(image, 0)

output = loaded_model(image)

Load a pre-trained TensorFlow Hub model for image object detection and use it to detect objects in an input image.


This module uses the Universal Sentence Encoder model to preprocess text by converting it into embeddings.


import tensorflow as tf
import tensorflow_hub as hub
model_id = 'https://tfhub.dev/google/imagenet/inception_v3/classification/4'
model = hub.load(model_id)
image = tf.keras.preprocessing.image.load_img('path/to/your/image.jpg', target_size=(299, 299))
input_image = tf.keras.preprocessing.image.img_to_array(image)
input_image = tf.expand_dims(input_image, 0)
predictions = model(input_image)
predicted_class = tf.argmax(predictions[0]).numpy()

This example demonstrates how to load a pre-trained Inception V3 model from TensorFlow Hub and use it to classify an image. The model has been trained on the ImageNet dataset and achieves 78.1% accuracy.


embeddings = embed(['Hello world', 'Embedding with TensorFlow Hub'])

A pre-trained model that converts text into high-dimensional vectors that can be used for text classification, semantic similarity, clustering, and other natural language tasks.


import tensorflow as tf
import tensorflow_hub as hub

model = tf.keras.Sequential([
    hub.KerasLayer('https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/feature_vector/4',
                   input_shape=(224, 224, 3),
                   output_shape=(1280,))
])

image = tf.keras.Input(shape=(224, 224, 3))
features = model(image)

A pre-trained image feature vector model using MobileNet V2 architecture on ImageNet dataset with 100% width and 224x224 input size.


import tensorflow_hub as hub; embed = hub.load('https://tfhub.dev/google/universal-sentence-encoder/4'); embeddings = embed(['Hello world'])

A pre-trained model that encodes text into high-dimensional vectors that can be used for text classification, semantic similarity, clustering, and other natural language tasks


import tensorflow as tf
import tensorflow_hub as hub

model = tf.keras.Sequential([
    hub.KerasLayer('https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/feature_vector/4', input_shape=[224, 224, 3])
])

image = tf.keras.preprocessing.image.load_img('path/to/image.jpg', target_size=(224, 224))
image_array = tf.keras.preprocessing.image.img_to_array(image)
image_array = tf.expand_dims(image_array, 0)

features = model.predict(image_array)

This API extracts feature vectors from images using the MobileNetV2 model pretrained on the ImageNet dataset. It can be used for tasks like image classification, object detection, and image similarity.


model = tf.keras.Sequential([hub.KerasLayer('https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/feature_vector/4', input_shape=(224, 224, 3), trainable=False), tf.keras.layers.Dense(1)])

A pre-trained image feature vector model using MobileNetV2 architecture for extracting features from images. The model is trained on ImageNet dataset and can be used for various computer vision tasks.


model = tf.keras.Sequential([
  hub.KerasLayer('https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/feature_vector/4', input_shape=[224, 224, 3], output_shape=[1280]),
  tf.keras.layers.Dense(num_classes, activation='softmax')
])

This model extracts feature vectors from images using the MobileNetV2 architecture trained on the ImageNet dataset. The input images should have a shape of [224, 224, 3] and the output feature vectors have a shape of [1280].


Input: tensor

import tensorflow_hub as hub
model = hub.load('https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/feature_vector/4')
features = model(image_tensor)

A pre-trained image feature vector model using MobilenetV2 architecture on ImageNet dataset.


import tensorflow as tf
import tensorflow_hub as hub

model = tf.keras.Sequential([
    hub.KerasLayer('https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/classification/4')
])

image = tf.keras.preprocessing.image.load_img('path/to/image.jpg', target_size=(224, 224))
image_array = tf.keras.preprocessing.image.img_to_array(image)
image_array = tf.expand_dims(image_array, 0)

predictions = model(image_array)

A pre-trained image classification model using MobileNetV2 architecture trained on ImageNet dataset. The model can be used to classify images into 1000 different categories.


import tensorflow as tf
import tensorflow_hub as hub
model_id = 'https://tfhub.dev/google/tf2-preview/mobilenet_v2/classification/2'
model = hub.load(model_id)

Load pre-trained image classification models from TensorFlow Hub for transfer learning and fine-tuning.


import tensorflow as tf
import tensorflow_hub as hub

model = tf.keras.Sequential([
    hub.KerasLayer('https://tfhub.dev/google/tf2-preview/mobilenet_v2/classification/4', input_shape=(224,224,3))
])

image = tf.keras.preprocessing.image.load_img('path/to/your/image.jpg', target_size=(224, 224))
image_array = tf.keras.preprocessing.image.img_to_array(image)
image_array = tf.expand_dims(image_array, 0)

predictions = model.predict(image_array)

A pre-trained image classification model using MobileNetV2 architecture with input size of 224x224 pixels.


import tensorflow as tf
import tensorflow_hub as hub

model = tf.keras.Sequential([
    hub.KerasLayer('https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/feature_vector/4',
                   input_shape=(224, 224, 3),
                   trainable=False)
])

image = tf.keras.Input(shape=(224, 224, 3))
features = model(image)

A pre-trained image feature vector model that uses MobileNetV2 architecture to extract feature vectors from images. It is trained on the ImageNet dataset and can be used for various computer vision tasks, such as image classification, object detection, and image similarity.


import tensorflow as tf
import tensorflow_hub as hub

model = tf.keras.Sequential([
    hub.KerasLayer('https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/feature_vector/4', input_shape=(224,224,3), trainable=False),
    tf.keras.layers.Dense(1, activation='sigmoid')
])

model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])

# Train the model with your data
model.fit(x_train, y_train, epochs=5, batch_size=32)

A pre-trained image feature vector model based on MobileNetV2 architecture, trained on ImageNet dataset. It can be used for image classification, object detection, and other computer vision tasks.


import tensorflow as tf
import tensorflow_hub as hub

model_id = 'https://tfhub.dev/google/tf2-preview/mobilenet_v2/classification/4'
model = hub.load(model_id)

image = tf.keras.preprocessing.image.load_img('image.jpg', target_size=(224, 224))
input_array = tf.keras.preprocessing.image.img_to_array(image)
input_array = tf.expand_dims(input_array, 0)

predictions = model(input_array)

Load a pre-trained model for image classification from TensorFlow Hub and use it to classify images.


import tensorflow as tf
import tensorflow_hub as hub

model_id = 'https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/classification/4'
loaded_model = hub.load(model_id)

image = tf.keras.preprocessing.image.load_img('path/to/your/image.jpg', target_size=(224, 224))
image_array = tf.keras.preprocessing.image.img_to_array(image)
image_array = tf.expand_dims(image_array, 0)

predictions = loaded_model(image_array)

Top-1 accuracy: 71.0%, Top-5 accuracy: 90.0%

This API allows you to load a pre-trained image classification model from TensorFlow Hub and use it to classify images. The example provided uses the MobileNet V2 model trained on the ImageNet dataset.


import tensorflow as tf
import tensorflow_hub as hub

model = tf.keras.Sequential([
    hub.KerasLayer('https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/feature_vector/4',
                   input_shape=(224, 224, 3),
                   output_shape=(1280,))
])

image = tf.keras.preprocessing.image.load_img('path/to/image.jpg', target_size=(224, 224))
input_image = tf.keras.preprocessing.image.img_to_array(image)
input_image = tf.expand_dims(input_image, axis=0)

features = model.predict(input_image)

This API provides a pre-trained MobileNetV2 model for extracting image feature vectors using TensorFlow Hub. The model is trained on the ImageNet dataset and has an accuracy of 71.9%.


A pre-trained image classification model using MobileNetV2 architecture on ImageNet dataset with 100% depth and 224x224 input size.


import tensorflow as tf
import tensorflow_hub as hub

model_id = 'https://tfhub.dev/google/imagenet/inception_v3/classification/5'
model = hub.load(model_id)

image = tf.keras.preprocessing.image.load_img('path/to/your/image.jpg', target_size=(299, 299))
image = tf.keras.preprocessing.image.img_to_array(image)
image = tf.expand_dims(image, axis=0)

predictions = model(image)

A pre-trained image classification model available on TensorFlow Hub that can be used to classify images into various categories. The example provided demonstrates how to load the Inception V3 model and make predictions on a given image.


Input: Image tensor

Output: Feature vector tensor

import tensorflow as tf
import tensorflow_hub as hub

model = hub.load('https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/feature_vector/4')
image = tf.zeros([1, 224, 224, 3])
features = model(image)

This module uses MobileNet v2 architecture for image feature extraction. It takes an image tensor as input and returns a feature vector tensor.


import tensorflow_hub as hub; embed = hub.load('https://tfhub.dev/google/universal-sentence-encoder/4'); embeddings = embed(['Hello world']); print(embeddings)

A pre-trained text embedding model that converts sentences into fixed-size vectors, suitable for various NLP tasks.


import tensorflow_hub as hub; embed = hub.load('https://tfhub.dev/google/universal-sentence-encoder/4'); embeddings = embed(['Hello world!'])

The Universal Sentence Encoder encodes text into high-dimensional vectors that can be used for text classification, semantic similarity, clustering, and other natural language tasks.


Convert text into a dense vector representation

import tensorflow_hub as hub
embed = hub.load('https://tfhub.dev/google/universal-sentence-encoder/4')
embeddings = embed(['Hello world!'])

The Universal Sentence Encoder encodes text into high-dimensional vectors that can be used for text classification, semantic similarity, clustering, and other natural language tasks


import tensorflow as tf
import tensorflow_hub as hub

model_id = 'https://tfhub.dev/google/imagenet/mobilenet_v2_130_224/classification/5'
model = hub.load(model_id)
image = tf.random.uniform((1, 224, 224, 3))
prediction = model(image)

Load pre-trained image classification models from TensorFlow Hub for various tasks such as object recognition, fine-grained classification, and more.


import tensorflow as tf
import tensorflow_hub as hub

model = tf.keras.Sequential([
    hub.KerasLayer('https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/feature_vector/4',
                    input_shape=(224,224,3),
                    trainable=False),
    tf.keras.layers.Dense(5, activation='softmax')
])

model.compile(optimizer='adam',
              loss='categorical_crossentropy',
              metrics=['accuracy'])

A pre-trained image feature vector model using MobileNet V2 architecture on ImageNet dataset, suitable for extracting features from images.


import tensorflow as tf
import tensorflow_hub as hub

model = hub.load('https://tfhub.dev/google/model_id/1')
embeddings = model(samples, sample_rate)

This API allows you to extract audio features from audio samples using a pre-trained model from TensorFlow Hub.


import tensorflow_hub as hub
import tensorflow as tf
model = hub.load('https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/feature_vector/4')
img = tf.constant([input_image])
features = model(img)

This API provides a pre-trained model to extract feature vectors from 224x224 images using MobileNetV2 architecture.


import tensorflow as tf
import tensorflow_hub as hub

model = tf.keras.Sequential([
    hub.KerasLayer('https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/feature_vector/4',
                   input_shape=(224, 224, 3),
                   trainable=False),
    tf.keras.layers.Dense(10, activation='softmax')
])

model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])

A pre-trained image feature vector model, MobileNetV2, for TensorFlow Hub that extracts features from images. The input images should be 224x224 pixels with 3 channels (RGB). The output is a 1280-dimensional feature vector. The model is trained on the ImageNet dataset.


Loading and using a pre-trained image feature vector model

import tensorflow as tf
import tensorflow_hub as hub

model = tf.keras.Sequential([
    hub.KerasLayer('https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/feature_vector/4',
                   trainable=False),
    tf.keras.layers.Dense(1)])

model.build([None, 224, 224, 3])
model.summary()

A pre-trained image feature vector model using MobileNet V2 architecture with 100% depth and 224x224 input size. This model can be used for transfer learning to extract meaningful features from images and fine-tune on a specific classification task.


import tensorflow as tf
import tensorflow_hub as hub

model = tf.keras.Sequential([
    hub.KerasLayer('https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/feature_vector/4',
                   input_shape=(224, 224, 3))
])

image_tensor = tf.random.uniform(shape=[1, 224, 224, 3])
feature_vector = model(image_tensor)
print(feature_vector.shape)

This API generates a feature vector for an input image using the MobileNetV2 model trained on the ImageNet dataset.


import tensorflow as tf
import tensorflow_hub as hub
embed = hub.load('https://tfhub.dev/google/universal-sentence-encoder/4')
embeddings = embed(['Hello, world!', 'How are you?'])
print(embeddings)

A model that encodes text into 512-dimensional vectors that can be used for text classification, semantic similarity, clustering, and other natural language tasks


import tensorflow_hub as hub
model = tf.keras.Sequential([
  hub.KerasLayer('https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/feature_vector/4',
  input_shape=(224,224,3),
  trainable=False),
  tf.keras.layers.Dense(num_classes, activation='softmax')
])

A pre-trained image feature vector model that extracts meaningful features from images using MobileNetV2 architecture with 224x224 input size.


Image classification using a pre-trained model

model_id: The ID of the pre-trained model to be used for image classification

import tensorflow as tf
import tensorflow_hub as hub

model_id = 'https://tfhub.dev/google/imagenet/inception_v3/classification/5'
model = hub.load(model_id)

# Load an image and preprocess it
image = tf.keras.preprocessing.image.load_img('path/to/image.jpg', target_size=(299, 299))
image = tf.keras.preprocessing.image.img_to_array(image)
image = tf.keras.applications.inception_v3.preprocess_input(image)

# Make a prediction
predictions = model(tf.expand_dims(image, 0))

This API allows users to perform image classification using a pre-trained TensorFlow Hub model. The model can be loaded using the model_id, and the API provides functionality for loading and preprocessing images, as well as making predictions.


Load and use a pre-trained image classification model

import tensorflow as tf
import tensorflow_hub as hub

model = hub.load('https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/classification/4')

def classify_image(image_path):
  image = tf.keras.preprocessing.image.load_img(image_path, target_size=(224, 224))
  image_array = tf.keras.preprocessing.image.img_to_array(image)
  image_array = tf.expand_dims(image_array, 0)
  predictions = model(image_array)
  return predictions.numpy()

A pre-trained image classification model using MobileNetV2 architecture with 100% depth multiplier, trained on ImageNet dataset.


import tensorflow as tf
import tensorflow_hub as hub

model = tf.keras.Sequential([
    hub.KerasLayer(
        'https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/feature_vector/4',
        input_shape=(224, 224, 3)
    )
])

image_tensor = tf.zeros(shape=(1, 224, 224, 3))
feature_vector = model(image_tensor)

A pre-trained MobileNetV2 model that takes an image tensor as input and returns a 1280-dimensional feature vector.


import tensorflow as tf
import tensorflow_hub as hub
embed = hub.load('https://tfhub.dev/google/universal-sentence-encoder/4')
embeddings = embed(['Hello world!'])
print(embeddings)

The Universal Sentence Encoder encodes text into high-dimensional vectors that can be used for text classification, semantic similarity, clustering, and other natural language tasks. The model is trained and optimized for greater-than-word length text, such as sentences, phrases, or short paragraphs.