Embedding text into a high-dimensional vector

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

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

Loads a pre-trained image feature vector model from TensorFlow Hub, allowing users to extract features from images.


Pre-trained model 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)

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)

predictions = model(image)

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


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

A compact, pre-trained image feature vector model, using MobileNetV3 architecture, trained on ImageNet dataset.


Input: A 3-channel image tensor

Output: A tensor with semantic labels

import tensorflow as tf
import tensorflow_hub as hub

image = tf.keras.Input(shape=(None, None, 3), dtype=tf.uint8, name='image_input')
segmentation = hub.KerasLayer('https://tfhub.dev/tensorflow/deeplabv3/1', output_key='SemanticPredictions')(image)
model = tf.keras.Model(inputs=image, outputs=segmentation)

82.1% mean intersection-over-union (mIOU)

DeepLabv3 is an image segmentation model for TensorFlow Hub that assigns semantic labels to every pixel of an input image. It is based on the DeepLabv3 architecture and trained on the PASCAL VOC 2012 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)

Pearson correlation coefficient of 0.803

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!'])

A pretrained text embedding model that maps text to high-dimensional vectors.


Loading a 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/tf2-preview/mobilenet_v2/classification/4',
        output_shape=[1001]
    )
])

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


input: A tensor of strings, output: A tensor of shape (num_examples, 512)

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

A pre-trained model for encoding text into a 512-dimensional vector. Useful for various NLP tasks like semantic similarity, sentiment analysis, and text classification.


Load and use pre-trained models for image classification

import tensorflow as tf
import tensorflow_hub as hub

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

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

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

This API allows you to load and use pre-trained models for image classification from TensorFlow Hub. It provides a simple way to integrate state-of-the-art image classification models into your applications.


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 that converts images into a 1280-dimensional feature vector using MobileNetV2 architecture trained 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!', 'How are you?'])


URL or local path to the pre-trained model

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 for use in TensorFlow 2.x.


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

Loads a pre-trained image feature vector model from TensorFlow Hub using the specified model_id.


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)

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

predictions = model(input_batch)
print(predictions)

A pre-trained model for image classification using TensorFlow Hub. This example demonstrates the use of the MobileNet V2 model to classify images.


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. The model is trained and optimized for greater-than-word length text, such as sentences, phrases or short paragraphs.


Loading and using 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)

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)

This API allows users to load pre-trained models from TensorFlow Hub for image classification tasks. It provides access to a variety of models, such as MobileNet, Inception, and ResNet, which have been trained on large datasets like ImageNet. Users can easily load a model using its model_id and perform image classification on their own images.


import tensorflow as tf
import tensorflow_hub as hub

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

# Train the model
model.compile(optimizer="adam", loss="sparse_categorical_crossentropy", metrics=["accuracy"])
model.fit(x_train, y_train, epochs=10, validation_data=(x_test, y_test))

This module takes an input image of size 224x224 and returns a feature vector representing the image using the MobileNetV3Small model pretrained on the ImageNet dataset.


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_tensor = tf.zeros([1, 224, 224, 3])
feature_vector = model(image_tensor)

This API extracts a feature vector from images using the MobileNetV2 model trained on the ImageNet dataset. It is useful for transfer learning and other tasks that require image embeddings.


Converts text into high-dimensional vectors

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 encodes text into high-dimensional vectors for various natural language processing tasks


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=tf.keras.optimizers.Adam(),
              loss=tf.keras.losses.CategoricalCrossentropy(from_logits=True),
              metrics=['accuracy'])

A pre-trained model that takes an image input and outputs a 1280-dimensional feature vector representing the image, which can be used for various tasks such as classification, clustering, and similarity search.


import tensorflow as tf
import tensorflow_hub as hub

model = hub.load('https://tfhub.dev/google/imagenet/mobilenet_v2_100_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))
image_array = tf.keras.preprocessing.image.img_to_array(image)
image_array = tf.expand_dims(image_array, 0)

# Make predictions
predictions = model(image_array)

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

A pre-trained image classification model based on the MobileNetV2 architecture. It is trained on the ImageNet dataset and can classify images into 1000 different classes. The model is optimized for mobile and edge devices with a small memory footprint and fast inference time.


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_tensor = tf.image.resize(image, (224, 224))
predictions = model(image_tensor)

Top-1 Accuracy: 71.0%, Top-5 Accuracy: 90.1%

A pre-trained image classification model using TensorFlow Hub that can classify images into 1000 different categories. The model is based on the MobileNetV2 architecture and has been trained on the ImageNet dataset.


The Universal Sentence Encoder encodes text into high-dimensional vectors that can be used for various NLP 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!'])

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.


Loading pre-trained models for image classification

Load MobileNetV2 model pre-trained on ImageNet dataset 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')
def classify(image_url):
    image = tf.keras.utils.get_file('image.jpg', image_url)
    image = tf.keras.preprocessing.image.load_img(image, target_size=(224, 224))
    image = tf.keras.preprocessing.image.img_to_array(image)
    image = tf.expand_dims(image, axis=0)
    image = tf.keras.applications.mobilenet_v2.preprocess_input(image)
    predictions = model(image)
    return predictions

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


import tensorflow as tf
import tensorflow_hub as hub

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

This module uses the MobileNet v2 architecture for image classification, pre-trained on the ImageNet dataset. The model accepts image input of size 224x224 pixels and outputs a 1001-element vector of logits.


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)

predictions = model(image_array)

This API allows users to load and use pre-trained image classification models from TensorFlow Hub. The models can be used to classify images into various categories.


Input: 224x224 RGB image

Output: 1001 element vector of logits

import tensorflow as tf
import tensorflow_hub as hub

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

# Preprocess image
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)

# Make prediction
predictions = model(input_image)

# Get class label
predicted_class = tf.argmax(predictions, axis=-1)

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


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))
input_array = tf.keras.preprocessing.image.img_to_array(image)
input_array = tf.expand_dims(input_array, 0)
input_array = input_array / 255.0

# Make predictions
predictions = model(input_array)

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

Top-1 accuracy of 80.1% and Top-5 accuracy of 95.1%

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


import tensorflow as tf
import tensorflow_hub as hub

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

# Load 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.keras.applications.mobilenet_v2.preprocess_input(image)
image = tf.expand_dims(image, 0)

# Make predictions
predictions = model(image)

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

for i, (imagenet_id, label, score) in enumerate(decoded_predictions[0]):
    print('{}. {}: {:.2f}%'.format(i + 1, label, score * 100))

MobileNetV2 is a lightweight deep learning model for image classification. It is pre-trained on the ImageNet dataset and can be loaded using TensorFlow Hub.


import tensorflow as tf
import tensorflow_hub as hub

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

Load an image classification model from TensorFlow Hub by providing the model_id. This example demonstrates how to load the Inception V3 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/classification/4')
])

image = tf.keras.utils.get_file('image.jpg','https://example.com/image.jpg')
img = tf.keras.preprocessing.image.load_img(image, target_size=(224, 224))
img_array = tf.keras.preprocessing.image.img_to_array(img)
img_array = tf.expand_dims(img_array, 0)

predictions = model.predict(img_array)

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


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_url):
  image = tf.keras.utils.get_file('image.jpg', image_url)
  image = tf.keras.preprocessing.image.load_img(image, target_size=(224, 224))
  image = tf.keras.preprocessing.image.img_to_array(image)
  image = tf.expand_dims(image, 0)
  return model(image)

result = classify_image('https://example.com/image.jpg')

This API provides a pre-trained image classification model based on MobileNetV2 architecture, which can classify images into 1000 different categories. The model is trained on ImageNet dataset and can be used for various image classification tasks.


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])
])

# 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)

# Make predictions
predictions = model.predict(input_array)

A pre-trained MobileNetV2 model for image classification using TensorFlow Hub.


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)
result = model(image_tensor)

TensorFlow Hub provides a variety of pre-trained image classification models that can be easily loaded and used for various image classification tasks. The models are trained on the ImageNet dataset and their performance varies depending on the specific model chosen.


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

Load a TensorFlow Hub model for text preprocessing and generate embeddings for input text.


import tensorflow as tf
import tensorflow_hub as hub

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

image_tensor = tf.convert_to_tensor(image, dtype=tf.uint8)
input_tensor = tf.expand_dims(image_tensor, 0)
detections = loaded_model(input_tensor)

A pre-trained TensorFlow Hub model for object detection in images using the SSD MobileNet V2 architecture.


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/image.jpg', target_size=(224, 224))
image_array = tf.keras.preprocessing.image.img_to_array(image)
image_array = tf.expand_dims(image_array, 0)

# Make predictions
predictions = model(image_array)

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

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


Input: List of 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 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.


A string representing the TensorFlow Hub model URL

import tensorflow as tf
import tensorflow_hub as hub

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

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

# Detect objects in the image
result = model(image)

# Print detected objects
for obj in result['detection_boxes']:
    print(obj)

A pre-trained TensorFlow Hub model for detecting objects in images using the Single Shot MultiBox Detector (SSD) with MobileNetV2 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 = tf.image.decode_jpeg(tf.io.read_file('image.jpg'))
result = detector(image[np.newaxis, ...])

Detect objects in an image using TensorFlow Hub and the Faster R-CNN model with Inception ResNet V2


Embedding text into high-dimensional vectors

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.


Loading 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')

# Prepare an image
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)

# Make predictions
predictions = model(image_array)

# Decode predictions
predicted_class = tf.keras.applications.mobilenet_v2.decode_predictions(predictions.numpy(), top=1)[0][0][1]

A pre-trained image classification model using MobileNetV2 architecture and trained on ImageNet dataset. The model is available on TensorFlow Hub and can be used for classifying images into one of 1000 classes.


import tensorflow as tf
import tensorflow_hub as hub

detector = hub.load('https://tfhub.dev/tensorflow/ssd_mobilenet_v2/fpnlite_640x640/1')

# Preprocess image
input_image = tf.image.resize(image, (640, 640))
input_image = tf.expand_dims(input_image, axis=0)

# Run detector
output = detector(input_image)

# Extract results
num_detections = output['num_detections'].numpy()
detection_boxes = output['detection_boxes'].numpy()
detection_classes = output['detection_classes'].numpy()
detection_scores = output['detection_scores'].numpy()

A pre-trained object detection model based on the SSD Mobilenet V2 architecture, capable of detecting multiple objects in an image. The model is trained on the COCO dataset and achieves a mean Average Precision (mAP) of 0.32.


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', 'This is a test'])


Mean Squared Error (MSE) of 0.30 on the development set

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/universal-sentence-encoder/4'
embed = hub.load(model_id)
text = ['This is an example sentence.']
embeddings = embed(text).numpy()

This API generates text embeddings using TensorFlow Hub, which can be used for various natural language processing tasks such as semantic similarity, clustering, and classification.


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'
loaded_model = hub.load(model_id)

image = tf.io.read_file('image.jpg')
decoded_image = tf.image.decode_jpeg(image)
resized_image = tf.image.resize(decoded_image, [640, 480])
input_image = tf.expand_dims(resized_image, 0)

result = loaded_model(input_image)

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


A tensor of shape [batch_size, height, width, 3] containing the input images.

import tensorflow as tf
import tensorflow_hub as hub

model = hub.load('https://tfhub.dev/google/faster_rcnn/inception_resnet_v2/atrous/oid_v4/1')
image_tensor = tf.zeros([1, 640, 640, 3])
output = model(image_tensor)

A pre-trained Faster R-CNN model with Inception-ResNet-v2 feature extractor for object detection on the Open Images Dataset v4.


import tensorflow as tf
import tensorflow_hub as hub

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

image = tf.io.read_file('path/to/image.jpg')
image = tf.image.decode_jpeg(image, channels=3)
image = tf.image.convert_image_dtype(image, tf.float32)
image = tf.image.resize(image, (512, 512))

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

A pre-trained model for object detection in images using TensorFlow Hub and the CenterNet Hourglass 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)
])

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)

Extracts feature vectors from images using the MobileNet V2 model pretrained on the ImageNet dataset.


Image classification using pre-trained models

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)
input_image = tf.keras.preprocessing.image.load_img('path/to/image.jpg', target_size=(224, 224))
input_array = tf.keras.preprocessing.image.img_to_array(input_image)
input_batch = tf.expand_dims(input_array, 0)
predictions = model(input_batch)

A pre-trained image classification model using TensorFlow Hub that can classify images into one of 1000 classes. The example code demonstrates how to load the model, preprocess an input image, and obtain predictions.


Transforms text into high-dimensional vectors

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 (USE) is a pre-trained model that encodes text into 512-dimensional vectors. 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/faster_rcnn/openimages_v4/inception_resnet_v2/1'
detector = hub.load(model_id)
image = tf.keras.preprocessing.image.load_img('path/to/image.jpg')
image_np = tf.keras.preprocessing.image.img_to_array(image)
input_tensor = tf.convert_to_tensor(image_np)
input_tensor = input_tensor[tf.newaxis, ...]

output_dict = detector(input_tensor)

for i in range(output_dict['detection_scores'][0].shape[0]):
    if output_dict['detection_scores'][0][i] > 0.5:
        print(output_dict['detection_class_entities'][0][i].numpy().decode('utf-8'), ':', output_dict['detection_scores'][0][i].numpy())

A pre-trained Faster R-CNN model with Inception-ResNet-v2 feature extractor on OpenImages V4 dataset for object detection.


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


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 using MobileNetV2 architecture with 100% depth and 224x224 input size. The model is trained on the ImageNet dataset and can be used for feature extraction, fine-tuning, or as a component in a larger model.


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')
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 = tf.keras.Sequential([
    hub.KerasLayer('https://tfhub.dev/google/imagenet/inception_v3/feature_vector/5')
])

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)

features = model.predict(image)
print(features)

This API provides a pre-trained Inception V3 model for extracting feature vectors from images. It is built on TensorFlow Hub and requires TensorFlow and TensorFlow Hub packages. The example code demonstrates how to load an image, preprocess it, and extract features using the API.


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_array = tf.keras.preprocessing.image.img_to_array(image)
image_array = tf.expand_dims(image_array, 0)

# Extract the feature vector
feature_vector = model.predict(image_array)

This API allows you to extract feature vectors from images using the MobileNetV2 model trained on the ImageNet dataset. The feature vectors can be used for various machine learning tasks, such as image classification, image retrieval, or transfer learning.


import tensorflow as tf
import tensorflow_hub as hub

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

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

# Train the model with your data
# model.fit(x_train, y_train, epochs=10, validation_data=(x_test, y_test))

This module is an image feature vector module that takes an input image of size 224x224x3 and outputs a feature vector of size 1024. It uses the MobileNetV3-small model architecture with a width multiplier of 1.0, pretrained 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 = 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)

This API provides pre-trained image classification models using TensorFlow Hub for various architectures like Inception V3, MobileNet, and others. These models are trained on the ImageNet dataset and can be used for transfer learning or fine-tuning on custom datasets.


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")
])

# Prepare 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)

A pre-trained image classification model using MobileNetV2 architecture on ImageNet dataset. It 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),
                   trainable=False),
    tf.keras.layers.Dense(num_classes, activation='softmax')
])

model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])
model.fit(train_data, train_labels, epochs=10, validation_data=(val_data, val_labels))

A pre-trained MobileNetV2 model for extracting image feature vectors. The model takes an image of size 224x224 and returns a 1280-dimensional 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.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)

features = model.predict(image_batch)

Extracts a 1280-dimensional feature vector from images using the MobileNetV2 architecture trained 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 = hub.load(model_id)
image = tf.keras.preprocessing.image.load_img('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)

This API allows users to perform image classification using pre-trained models from TensorFlow Hub. Users can load a model using its model_id and then use it to classify images.


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))
image = tf.keras.preprocessing.image.img_to_array(image)
image = tf.keras.applications.mobilenet_v2.preprocess_input(image)

# Extract feature vector
feature_vector = model.predict(image[np.newaxis, ...])

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


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

Load a pre-trained image classification model from TensorFlow Hub, providing a model_id for the desired model.


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 Keras layer that wraps a pre-trained MobileNetV2 model for feature extraction. It takes an input image of size 224x224x3 and outputs a 1280-dimensional feature vector.


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 an image and preprocess it
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)

# Make a prediction
prediction = model(image_array)

# Decode the prediction
decoded_prediction = tf.keras.applications.mobilenet_v2.decode_predictions(prediction.numpy())

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


A pre-trained feature vector model that can be used for image classification and other computer vision tasks.


A pre-trained image classification model using Inception V3 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 = tf.keras.Sequential([
    hub.KerasLayer("https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/classification/4")
])

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


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 = 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'])

This module uses the MobileNet v2 architecture to extract feature vectors from images. It has been pre-trained on the ImageNet dataset and can be fine-tuned for various 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))
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 model for image classification using Inception V3 architecture, available on TensorFlow Hub. The model has been trained on the ImageNet dataset and can be used to classify images into 1000 different classes.


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

A text embedding model that converts sentences into fixed-length vectors, useful for various natural language processing 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), trainable=False)
])

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)

feature_vector = model.predict(image_array)

Top-1 Accuracy: 71.9%, Top-5 Accuracy: 91.0%

A pre-trained image feature vector model that extracts feature vectors from images using MobileNetV2 architecture. It is trained on the ImageNet dataset and can be used for various image classification 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],
                   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 with 100% depth and 224x224 input image size. It can be used for transfer learning to extract features from images and fine-tune for specific classification tasks.


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: 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', 'Embedding with TensorFlow Hub'])
print(embeddings)


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(10, activation='softmax')
])

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

A pre-trained MobileNetV2 model that takes an input image of shape (224, 224, 3) and outputs a 1280-dimensional feature vector. Useful for image classification, object detection, and other computer vision tasks.


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])])
model.build([None, 224, 224, 3])

A pre-trained image classification model using MobileNetV2 architecture on TensorFlow Hub. It can be used to classify images into 1000 different categories with high accuracy.


This model is trained on the ImageNet dataset and can be used to extract feature vectors from images using the ResNet-50 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))
])

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

feature_vector = model(image)

A pre-trained model that generates feature vectors from images using MobileNetV2 architecture with 100% depth and 224x224 input size. The model is trained on the ImageNet dataset and achieves 71.9% top-1 accuracy.


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


import tensorflow as tf
import tensorflow_hub as hub

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

# Preprocess image, run the model, and postprocess the result
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)
image_array = tf.keras.applications.mobilenet_v2.preprocess_input(image_array)

predictions = model(image_array)

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

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


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

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

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

Pretrained Mobilenet V2 model for extracting image feature vectors using TensorFlow Hub.


Input: tensor

Output: tensor

import tensorflow as tf
import tensorflow_hub as hub
model = hub.load('https://tfhub.dev/tensorflow/deeplabv3/1')
input_image = tf.constant(input_data)
segmentation_output = model(input_image)

A pre-trained DeepLabV3 model for image segmentation using TensorFlow Hub.


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. It can be used for transfer learning to extract features from images.


import tensorflow as tf
import tensorflow_hub as hub

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

# Load a wav file
filename = 'path/to/your/audio/file.wav'
wav_data = tf.io.read_file(filename)

# Extract features
scores, embeddings, log_mel_spectrogram = model(wav_data)

YAMNet is a pre-trained deep learning model that can extract audio features. It is trained on the AudioSet dataset and can be used for various audio classification tasks.


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

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


Load and use pre-trained image segmentation models

import tensorflow_hub as hub
model = hub.load('https://tfhub.dev/tensorflow/lite-model/deeplabv3/1/default/1')
segmentation = model(image_tensor)

TensorFlow Hub provides pre-trained image segmentation models that can be loaded and used for various tasks such as semantic segmentation. The example code demonstrates how to load a DeepLabV3 model and perform segmentation on an input image tensor.


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_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)

# Extract feature vector from the image
feature_vector = model.predict(image_array)

This API allows you to extract feature vectors from images using the MobileNetV2 model trained on ImageNet dataset. The feature vectors can be used for various machine learning tasks such as image classification, object detection, and more.


Input: List of strings

A deep averaging network (DAN) encoder that maps text inputs to 512-dimensional embeddings. Useful for various NLP tasks such as sentiment analysis, semantic similarity, and document clustering.


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 on a variety of data sources and a variety of tasks with the aim of dynamically accommodating a wide variety of natural language understanding 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!', 'I am learning about embeddings.'])
print(embeddings)

Pre-trained model to embed input 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/classification/4')
])

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)

predictions = model.predict(input_array)

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


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)

This API allows you to load a pre-trained image classification model from TensorFlow Hub for use in your applications.


Optional: Set to True if you want to fine-tune the model

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

A pre-trained image feature vector model based on MobileNetV2 architecture, trained on ImageNet dataset, for extracting features from images.


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 embedding text into high-dimensional vectors that can be used for a wide range of tasks such as sentiment analysis, semantic similarity, and classification.


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)

# Example image
image = tf.keras.utils.get_file('image.jpg','https://storage.googleapis.com/download.tensorflow.org/example_images/grace_hopper.jpg')

# Preprocess image
image = tf.keras.preprocessing.image.load_img(image, target_size=(224, 224))
image = tf.keras.preprocessing.image.img_to_array(image)
image = tf.keras.applications.mobilenet_v2.preprocess_input(image)
image_batch = tf.expand_dims(image, 0)

# Make predictions
predictions = loaded_model(image_batch)

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


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

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


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 can be used to extract features from images. The model is based on the MobileNetV2 architecture and is 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],
                   trainable=False),
    tf.keras.layers.Dense(1, activation='sigmoid')
])

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

This API provides a pre-trained model to extract feature vectors from images using the MobileNetV2 architecture trained on the ImageNet dataset. It can be used for various image classification tasks and transfer learning.


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 for generating text embeddings using the Universal Sentence Encoder. It can be used for various NLP tasks like semantic similarity, text classification, 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/classification/4'),
])

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)

predictions = model.predict(input_array)

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 based on MobileNetV2 architecture, trained on ImageNet dataset. It can be used for feature extraction from images.


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 converts text into high-dimensional vectors that can be used for various NLP tasks.


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)

Load a pre-trained image classification model from TensorFlow Hub using the specified 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.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, axis=0)

features = model.predict(image_batch)

A pre-trained image feature vector model based on MobileNetV2 architecture. It can be used to extract features from images, which can be used for various machine learning tasks like image classification, object detection, and more.


Embed text into a high-dimensional vector

Input: List of strings

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

The Universal Sentence Encoder (USE) 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.


Input: A 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!', 'Embedding with universal-sentence-encoder'])

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.


Load 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')
input_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(input_image) / 255.0
input_tensor = tf.expand_dims(input_array, 0)
predictions = model(input_tensor)
class_index = tf.argmax(predictions, axis=-1).numpy()[0]

Top-1 accuracy: 75.6%, Top-5 accuracy: 92.8%

A pre-trained MobileNetV2 model for image classification on the ImageNet dataset. The model is designed to be small and efficient while maintaining high accuracy. It can be used for various image classification tasks.


import tensorflow as tf
import tensorflow_hub as hub

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

Load pre-trained models for image classification from TensorFlow Hub using the 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/classification/4', input_shape=[224, 224, 3])
])

predictions = model.predict(image_batch)

A pre-trained image classification model using MobileNetV2 architecture with 100% depth and 224x224 input size. The model is trained on ImageNet dataset and can classify 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/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.predict(image_array)

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


Input: An image tensor of shape [batch_size, height, width, 3]

Output: A tensor of shape [batch_size, 1001] representing class probabilities

import tensorflow as tf
import tensorflow_hub as hub

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

# Preprocess your image to the required format
image = tf.keras.preprocessing.image.load_img('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)

Top-1 Accuracy: 83.5%, Top-5 Accuracy: 96.5%

A pre-trained image classification model using MobileNetV2 architecture, trained on ImageNet dataset. The model accepts an image tensor of shape [batch_size, height, width, 3] and outputs class probabilities for each of the 1001 classes.


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.random.normal([1, 224, 224, 3])
predictions = model(image)

A collection of pre-trained image classification models available on TensorFlow Hub, which can be used to classify images into various 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/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.predict(image_array)

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/google/imagenet/inception_v3/classification/5'
model = hub.load(model_id)
image = tf.keras.preprocessing.image.load_img('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)

This API is used to load and use pre-trained image classification models from TensorFlow Hub for tasks like object recognition and scene understanding.


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 pre-trained models for image classification from TensorFlow Hub using a model_id. The models are trained on the ImageNet dataset.


Loads a pre-trained image classification model from TensorFlow Hub and uses it for inference.


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, axis=0)

predictions = model(image_array)

A pre-trained image classification model from TensorFlow Hub that can classify images into 1000 different categories using the MobileNetV2 architecture.


Load and run 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')

# Run the model on a sample image
sample_image = tf.zeros([1, 224, 224, 3])
logits = model(sample_image)
predicted_class = tf.argmax(logits, axis=-1)
print(predicted_class)

This API allows you to load and run a pre-trained MobileNetV2 image classification model from TensorFlow Hub. The model is trained on the ImageNet dataset and can classify images into 1000 different categories with an accuracy of 71.9%.


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's ID.


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')
input_image = tf.keras.preprocessing.image.img_to_array(image)
input_image = tf.expand_dims(input_image, 0)
detections = detector(input_image)

A pre-trained object detection model that can detect multiple objects in an image using TensorFlow Hub.


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, classification, clustering, and sentiment analysis.


Embedding text into a high-dimensional vector

Input: List of strings

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.


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.


Embedding text data for machine learning models

Input: 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', 'Embedding sentences 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. The model is trained and optimized for greater-than-word length text, such as sentences, phrases or short paragraphs. It is trained on a variety of data sources and a variety of tasks with the aim of dynamically accommodating a wide variety of natural language understanding tasks.


Embedding text for machine learning models

import tensorflow as tf
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

A pre-trained text encoder that converts text into a 512-dimensional vector. Useful for a wide range of natural language processing tasks.


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('image.jpg'))
result = detector([image])

This API allows you to detect objects in an image using TensorFlow Hub and a 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_image(tf.io.read_file('path/to/image.jpg'))
result = detector(image[tf.newaxis, ...])

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


Embed text for various natural language processing 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!', 'Embedding with Universal Sentence Encoder.'])

A text embedding model that converts text into high-dimensional vectors for use in natural language processing tasks. The Universal Sentence Encoder is trained on a variety of data sources and can be fine-tuned for specific 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), trainable=False)
])

features = model(images)

This API provides a pre-trained MobileNetV2 model for extracting image features. It takes an input image of shape (batch_size, 224, 224, 3) and returns a feature vector of shape (batch_size, 1280). The model is trained on the ImageNet dataset and achieves 71.8% accuracy.


import tensorflow as tf
import tensorflow_hub as hub

A pre-trained deep learning model for generating image feature vectors using MobileNetV2 architecture with 100% depth and 224x224 input size.


import tensorflow as tf
import tensorflow_hub as hub

input = tf.keras.layers.Input(shape=(224, 224, 3))
features = hub.KerasLayer('https://tfhub.dev/google/imagenet/feature_vector/1', trainable=False)(input)
model = tf.keras.Model(inputs=input, outputs=features)

This API provides a pre-trained image feature vector model for extracting features from images using TensorFlow Hub. The model is based on the ImageNet dataset and can be used for various image-related tasks such as classification, detection, and segmentation.


Input: text

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 a fixed-size embedding vector. It is trained on a variety of data sources and can be used for multiple NLP 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/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)

TensorFlow Hub provides pre-trained models for image classification tasks. This example demonstrates how to load a pre-trained Inception V3 model from TensorFlow Hub and use it to classify an image.


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(num_classes, activation='softmax')
])

This is a feature vector obtained from the MobileNetV2 model trained on the ImageNet dataset. It can be used for transfer learning and fine-tuning on new datasets.


Load 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_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, axis=0)
image = tf.keras.applications.mobilenet_v2.preprocess_input(image)

predictions = model(image)

predicted_class_index = tf.argmax(predictions, axis=-1).numpy()[0]

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


import tensorflow as tf
import tensorflow_hub as hub

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

Load an image feature vector model from TensorFlow Hub and use it to create feature vectors for images.


The Universal Sentence Encoder encodes text into high-dimensional vectors that can be used for various natural language processing 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/5',
                   input_shape=(224, 224, 3),
                   trainable=False),
    tf.keras.layers.Dense(10, activation='softmax')
])

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

model.fit(x_train, y_train, epochs=5)

A pre-trained image feature vector model using MobileNetV2 architecture on ImageNet dataset. It can be used for various image classification tasks by adding a classification head on top of the feature vector.


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 specified model_id.


import tensorflow as tf
import tensorflow_hub as hub

model_id = 'https://tfhub.dev/google/imagenet/inception_v3/feature_vector/4'
inputs = tf.keras.Input(shape=(224, 224, 3))
feature_extractor = hub.KerasLayer(model_id, trainable=False)(inputs)
outputs = tf.keras.layers.Dense(1000, activation='softmax')(feature_extractor)
model = tf.keras.Model(inputs=inputs, outputs=outputs)

This API allows users to extract feature vectors from images using a pre-trained model from TensorFlow Hub. The feature vectors can then be used for various image recognition and classification tasks.


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 based on MobileNetV2 architecture for extracting features from images.


import tensorflow as tf
import tensorflow_hub as hub

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


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')
])

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


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 = tf.keras.preprocessing.image.img_to_array(image)
image = tf.expand_dims(image, axis=0)
results = model(image)
predicted_class = tf.math.argmax(results[0], axis=-1).numpy()

A pre-trained image classification model using MobileNetV2 architecture, trained on ImageNet dataset, and available on TensorFlow Hub for easy integration.


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)

A pre-trained image feature vector model based on MobileNetV2 architecture, which is optimized for performance on mobile devices and other resource-constrained environments. It can be used for various image classification tasks, transfer learning, or as a feature extractor for other models.


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_100_224/feature_vector/4')

# Load and preprocess the 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)

# Get the feature vector
feature_vector = model(image)

A pre-trained model that takes an input image tensor and outputs a 1280-dimensional feature vector representing the image.


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


Embed text into high-dimensional vectors

Input: A list of strings to be embedded

embeddings = embed(['hello world', 'my name is John'])

The Universal Sentence Encoder encodes text into high-dimensional vectors that can be used for text classification, semantic similarity, 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/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_array = tf.keras.preprocessing.image.img_to_array(image)
input_array = tf.expand_dims(input_array, 0)

# Predict the class of the image
predictions = model.predict(input_array)

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


Converts text into high-dimensional vectors

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?'])

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)


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))
input_image = tf.keras.preprocessing.image.img_to_array(image)
input_image = tf.expand_dims(input_image, 0)
input_image = tf.keras.applications.mobilenet_v2.preprocess_input(input_image)

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

print('Predicted class:', predicted_class)

A pre-trained image classification model based on MobileNetV2 architecture with 130 depth multiplier and 224x224 input size, trained on ImageNet dataset.


import tensorflow as tf
import tensorflow_hub as hub

model = tf.keras.Sequential([
    hub.KerasLayer('https://tfhub.dev/google/tf2-preview/mobilenet_v2/feature_vector/4', output_shape=[1280]),
    tf.keras.layers.Dense(1)
])

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.keras.applications.mobilenet_v2.preprocess_input(image)
image = tf.expand_dims(image, 0)

feature_vector = model.predict(image)
print(feature_vector)

This API allows you to extract a 1280-dimensional feature vector from an image using the MobileNetV2 architecture, which is pre-trained on the ImageNet dataset. The feature vector can be used for various tasks, such as image classification, object detection, and transfer learning.


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_array = tf.keras.preprocessing.image.img_to_array(image)
input_array = tf.expand_dims(input_array, 0)

predictions = model.predict(input_array)

This model is a pre-trained image classification model based on MobileNetV2 architecture. It can classify images into 1000 different categories.


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

Load a pre-trained TensorFlow Hub model to extract image feature vectors.


Input: A batch of images with shape [batch_size, height, width, 3]

Output: A batch of feature vectors with shape [batch_size, num_features]

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_batch = tf.zeros([batch_size, height, width, 3])
feature_vectors = model(image_batch)

A pre-trained MobileNetV2 model that extracts feature vectors from images.


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.


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')
])

This API provides a pre-trained MobileNetV2 model for extracting feature vectors from images. It is trained on the ImageNet dataset and has an accuracy of 71.9%.


Convert text into high-dimensional vectors

A text embedding model that converts input text into high-dimensional vectors for use in natural language processing tasks


Embedding text into high-dimensional vectors

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


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')
])

A pre-trained image feature vector model based on MobileNetV2 architecture, designed for extracting features from images for various tasks such as image classification, object detection, and semantic segmentation.


import tensorflow as tf
import tensorflow_hub as hub

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

YAMNet is a deep net that predicts 521 audio event classes based on the AudioSet dataset. It employs the Mobilenet_v1 depthwise-separable convolution architecture.


The ID of the pre-trained model to be loaded

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 specified 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),
                   trainable=False)
])

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

A pre-trained image feature vector model that uses MobileNetV2 architecture to extract features from images.


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/5')
])

decoded_image = tf.image.decode_jpeg(tf.io.read_file('image.jpg'))
resized_image = tf.image.resize(decoded_image, (224, 224))
input_image = tf.expand_dims(resized_image, 0)

predictions = model(input_image)

A pre-trained model for image classification using MobileNetV2 architecture with 130 depth multiplier and 224x224 input size, 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),
                  trainable=False),
    tf.keras.layers.Dense(1, activation='sigmoid')
])

A pre-trained model that can be used to extract feature vectors from images using MobileNetV2 architecture with 224x224 input size.


Input: Text input


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


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_url = 'https://example.com/path/to/image.jpg'
image = load_and_preprocess_image(image_url)

feature_vector = model.predict(image)

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


import tensorflow as tf
import tensorflow_hub as hub

module_name = 'https://tfhub.dev/google/imagenet/inception_v3/feature_vector/1'
module = hub.load(module_name)

image = tf.random.uniform((1, 299, 299, 3))
features = module(image)

This API allows you to extract feature vectors from images using a pre-trained model from TensorFlow Hub. The model is based on the Inception V3 architecture and has been trained on the ImageNet dataset.


Pre-trained models 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')
])
result = model.predict(image_batch)

A pre-trained model for image classification using MobileNetV2 architecture 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),
                   trainable=False)
])

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

This module uses MobileNet V2 architecture for image feature vector extraction. It accepts a batch of images of shape (224, 224, 3) and returns a 1280-dimensional feature vector for each image.


import tensorflow_hub as hub
model = hub.load("https://tfhub.dev/tensorflow/deeplabv3_257_mv_gpu/1")
segmentation = model(input_image)

DeepLabv3 is a state-of-the-art deep learning model for image segmentation. It assigns a semantic label to each pixel in the input image, allowing for a more detailed understanding of the image content. This model is trained on the PASCAL VOC 2012 dataset and achieves a mean intersection-over-union (mIoU) score of 0.897.


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 on ImageNet dataset with 100% depth and 224x224 input size.


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_hub as hub; embed = hub.load('https://tfhub.dev/google/universal-sentence-encoder/4'); embeddings = embed(['text to embed'])


Input: List of text

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'])
print(embeddings)


A text embedding model that maps text inputs to high-dimensional vectors for use in downstream tasks like text classification or clustering.


Input: List of strings

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


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 an image and preprocess it
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)

# Make predictions
predictions = model(image_array)

This API provides pre-trained image classification models from TensorFlow Hub. Users can load a model using its model_id and make predictions on images.


import tensorflow as tf
import tensorflow_hub as hub

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

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)

features = model.predict(image_batch)

This API provides a pre-trained MobileNetV2 model for extracting feature vectors from images. The model is trained on the ImageNet dataset and achieves 80.3% accuracy on the validation set.


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 pretrained on a variety of data sources and is available on TensorFlow Hub.


Loading pre-trained models for image classification

import tensorflow as tf
import tensorflow_hub as hub
model = hub.load('https://tfhub.dev/google/tf2-preview/mobilenet_v2/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 MobileNetV2 model for image classification using 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 transfer learning and fine-tuning


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)

A pre-trained image classification model using MobileNet V2 architecture with 224x224 input size, available on TensorFlow Hub


Image classification using pre-trained models

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/5')
])

# 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.predict(input_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 from TensorFlow Hub. The model is trained on ImageNet dataset and can 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/4'
model = tf.keras.Sequential([
    hub.KerasLayer(model_id, trainable=True)
])

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


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/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)

print(predictions)

A pre-trained image classification model using MobileNetV2 with a depth multiplier of 1.0 and input size of 224x224 pixels. It can classify images into 1000 classes.


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))
])

# 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)

# Predict the class of the image
predictions = model.predict(input_image)
predicted_class = tf.math.argmax(predictions, axis=-1)

A pre-trained image classification model using MobileNetV2 architecture 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/4')
input_image = tf.zeros([1, 224, 224, 3])
output = model(input_image)

A pre-trained image classification model using MobileNetV2 with 130 as width multiplier and 224 as input resolution. It is trained on ImageNet dataset and can be used for various image classification 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)

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


Loading a pre-trained image classification model

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)

This API allows you to load a pre-trained image classification model from TensorFlow Hub using a specific model_id. The model can then be used to classify images into different categories.


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.keras.applications.inception_v3.preprocess_input(image)

predictions = model(tf.expand_dims(image, 0))

Loads a pre-trained image classification model from TensorFlow Hub for Inception V3, and classifies an input 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/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.predict(image_array)

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 = 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/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 on ImageNet dataset. It can classify images into 1000 different categories with an accuracy of 71.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')
])

A pre-trained image feature extraction model using MobileNetV2 architecture on ImageNet dataset to convert images into feature vectors.


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('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)
print(predictions)


Input: List of sentences

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

A text embedding model that encodes text into 512-dimensional vectors, trained on a variety of data sources and 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!', 'Embedding is fun!'])

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/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)

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

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


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 to classify images using the MobileNet_v2 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!'])
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

pip install tensorflow
pip install tensorflow-hub

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

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 variety of data sources and can be used with TensorFlow Hub.


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. It is a pre-trained model available on TensorFlow Hub.


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', 'Another sample text']
embeddings = embed(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. The model is trained and optimized for greater-than-word length text, such as sentences, phrases, or short paragraphs.


A pre-trained model for converting spoken language in audio files into written text using 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)

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

result = detector(input_image)

Detect objects in an image using a pre-trained model 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)

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

result = detector(input_image)

print(result)

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 = tf.keras.preprocessing.image.load_img('path/to/image.jpg')
image_array = tf.keras.preprocessing.image.img_to_array(image)
input_image = tf.expand_dims(image_array, 0)

result = detector(input_image)

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