embed = hub.load('https://tfhub.dev/google/tf2-preview/gnews-swivel-20dim/1')
embeddings = embed(['cat is on the mat', 'dog is in the fog'])

A pre-trained text language model that generates embeddings for input text using TensorFlow Hub.


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

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


import tensorflow as tf
import tensorflow_hub as hub
model = 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 extraction 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_v3_small_100_224/feature_vector/5')

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

A pre-trained image feature vector model using MobileNetV3 architecture on ImageNet dataset with small model size and 100% target accuracy.


import tensorflow as tf
import tensorflow_hub as hub

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

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

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

This API provides a pre-trained image feature vector model, MobileNetV3-Large, from TensorFlow Hub. The model is trained on the ImageNet dataset and can be used to generate feature vectors for images of size 224x224 with 3 channels.


Image classification using a pre-trained model

import tensorflow as tf
import tensorflow_hub as hub

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

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

result = model.predict(image_array)

MobileNetV2 is a pre-trained image classification model that can classify images into 1000 different categories. It is lightweight and optimized for mobile devices.


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

A compact representation of MobileNetV2 model trained on ImageNet dataset for extracting image features using TensorFlow Hub.


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!', '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.


Pre-trained model for image classification

import tensorflow as tf
import tensorflow_hub as hub

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

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

# Classify the image
predictions = model(image_array)
predicted_class = tf.argmax(predictions, axis=-1).numpy()[0]
print('Predicted class:', predicted_class)

A pre-trained model for image classification 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)

Pearson correlation coefficient of 0.803


Input: Text input

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


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

A pre-trained MobileNetV2 model for extracting feature vectors from images, using TensorFlow Hub.


Generate intermediate frames between two input frames

import tensorflow as tf
import tensorflow_hub as hub

inputs = [frame1, frame2]
interpolated_frame = hub.load('https://tfhub.dev/google/two-frame-vgg/1').call(inputs)

This model generates intermediate frames between two input frames using a deep learning approach. It is useful for video frame rate up-conversion and slow motion generation.


Embedding text into a high-dimensional vector

Input: A list of strings

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.


import tensorflow as tf
import tensorflow_hub as hub

model = hub.load('https://tfhub.dev/google/tf2-preview/mobilenet_v2/feature_vector/4')
image_tensor = tf.zeros([1, 224, 224, 3])
feature_vector = model(image_tensor)

A pre-trained image feature vector model using MobileNetV2 architecture on TensorFlow Hub. It generates feature vectors from input images for various applications like image classification, object detection, and image similarity.


Input: list of sentences

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

The Universal Sentence Encoder encodes text into high-dimensional vectors that can be used for various natural language processing tasks. It is pre-trained on a variety of data sources and can be fine-tuned for specific tasks.


Loads a pre-trained MobileNet V1 model for image classification from 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!', 'Greetings, humans!'])
print(embeddings)

A pre-trained model for embedding text into high-dimensional vectors that can be used in 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))
])

# 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.expand_dims(image, 0)

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

A pre-trained image feature vector model using MobileNetV2 architecture and trained on ImageNet dataset. It can be used for feature extraction and fine-tuning on new classification tasks.


output: A tensor of shape (num_examples, embedding_dimension)

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

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.


import tensorflow as tf
import tensorflow_hub as hub

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

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

This API provides a pre-trained MobileNetV2 model for extracting image features. It takes an input 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],
                   output_shape=[1280],
                   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)

feature_vector = model.predict(image_array)

A pre-trained model for extracting feature vectors from images using MobileNetV2 architecture with 100% depth and 224x224 input size.


import tensorflow as tf
import tensorflow_hub as hub

model_id = 'https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/classification/4'
model = tf.keras.Sequential([hub.KerasLayer(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
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_id = 'https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/classification/4'
model = hub.load(model_id)

A pre-trained image classification model available on TensorFlow Hub. The model can be loaded using the provided model_id and used for image classification tasks.


Input: A list of strings or a single string

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

The Universal Sentence Encoder (USE) model is a pre-trained text embedding model that converts text input into a high-dimensional vector representation. 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 = tf.keras.Sequential([
    hub.KerasLayer('https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/feature_vector/4',
                    input_shape=(224, 224, 3),
                    trainable=False),
    tf.keras.layers.Dense(10, activation='softmax')
])

A pre-trained image feature vector model using MobileNet V2 architecture with 100% depth and 224x224 input size. It can be used for image classification, object detection, and other image-based tasks.


import tensorflow as tf
import tensorflow_hub as hub

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

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

# Run the model on the input image
predictions = model(input_image)

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

A pre-trained image classification model using TensorFlow Hub, capable of classifying images into 1000 different categories. The model is based on the Inception V3 architecture and has been trained on the ImageNet dataset.


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


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 feature vector for an image using the MobileNet V2 architecture trained on the ImageNet dataset. The feature vector can be used as input for training other models or for image similarity tasks.


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

This model is a pre-trained image classifier using MobileNet V2 architecture on ImageNet dataset with 100% depth and 224x224 input size. It is optimized for performance on mobile and edge devices.


input_shape, batch_size, dtype, trainable

import tensorflow as tf
import tensorflow_hub as hub

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

A pre-trained image feature vector model based on MobileNetV1 architecture for image classification and feature extraction. The model is trained on the ImageNet dataset and provides an accuracy of 70.9%.


import numpy as np
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 = np.random.rand(1, 224, 224, 3).astype(np.float32)
feature_vector = model.predict(image)
print(feature_vector.shape)

This API provides a pre-trained MobileNetV2 model for extracting feature vectors from images. The input images should have a size of 224x224 and 3 color channels. The output feature vector has a dimension of 1280.


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.zeros([1, 299, 299, 3])
features = model(image)

A TensorFlow Hub module for extracting image feature vectors using the Inception V3 architecture pretrained 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,))
])

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

features = model.predict(img_array)

This API provides a feature vector for an image using the MobileNetV2 model trained on ImageNet dataset. The input image should be of size 224x224.


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_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],
                   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_array = tf.expand_dims(image_array, 0)

features = model.predict(image_array)

A pre-trained image feature vector model based on MobileNetV2 architecture, which can be used for image classification or as a feature extractor for transfer learning.


import tensorflow_hub as hub
movenet = hub.load('https://tfhub.dev/google/movenet/singlepose/lightning/3')
pose_keypoints = movenet(image_tensor)

MoveNet is a family of pose detection models designed for efficient and accurate detection of human poses in 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'])
print(embeddings)

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


import tensorflow_hub as hub
model = hub.load('https://tfhub.dev/google/movenet/singlepose/lightning/3')
image_tensor = ... # Load image tensor
outputs = model(image_tensor)
keypoints = outputs['output_0'].numpy()

MoveNet is a family of efficient and accurate pose detection models designed for real-time applications. This model detects 17 key points of a single person in an image.


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

This API provides a pre-trained MobileNetV2 model for extracting feature vectors from images. The model is trained on the ImageNet dataset and achieves 71.9% accuracy in classification tasks.


import tensorflow as tf
import tensorflow_hub as hub

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

audio = tf.random.uniform([16000])

scores, embeddings, log_mel_spectrogram = model(audio)
print(embeddings.shape)

YAMNet is a pre-trained deep learning model that can extract audio features from audio signals. It is trained on the AudioSet dataset and can be used for various audio-related tasks such as audio classification, audio tagging, and audio event detection.


A single image or batch of images with shape [batch_size, height, width, 3]

import tensorflow as tf
import tensorflow_hub as hub
pose = hub.load('https://tfhub.dev/google/movenet/singlepose/lightning/4')
input_image = tf.zeros([1, 192, 192, 3])
output = pose(input_image)

MoveNet is a model that detects human poses in images. It is trained on the COCO dataset and available on TensorFlow Hub.


import tensorflow as tf
import tensorflow_hub as hub

model = hub.KerasLayer('https://tfhub.dev/google/imagenet/inception_v3/feature_vector/5')
feature_vector = model(image_input)

This API provides a feature vector for images using TensorFlow Hub and the Inception V3 model. It can be used for various image-related tasks such as classification, similarity search, and more.


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.


import tensorflow as tf
import tensorflow_hub as hub
model = tf.keras.Sequential([
    hub.KerasLayer('https://tfhub.dev/google/imagenet/mobilenet_v2_130_224/classification/4')
])
image = tf.keras.preprocessing.image.load_img('path/to/your/image.jpg', target_size=(224, 224))
image = tf.keras.preprocessing.image.img_to_array(image)
image = tf.expand_dims(image, 0)
predictions = model.predict(image)

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


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

STS (Semantic Textual Similarity) Benchmark

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


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

The Universal Sentence Encoder (USE) is a pre-trained model that encodes text into high-dimensional vectors that can be used for a wide range of natural language processing 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 as tf
import tensorflow_hub as hub
embed = hub.load('https://tfhub.dev/google/universal-sentence-encoder/4')
text = ['This is a sample text']
embeddings = embed(text)
print(embeddings)

The Universal Sentence Encoder encodes text into high-dimensional vectors that can be used for a wide range of tasks such as semantic similarity, text classification, clustering, and sentiment analysis.


import tensorflow as tf
import tensorflow_hub as hub

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

model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])
model.fit(x_train, y_train, epochs=10, validation_data=(x_test, y_test))

This API provides a pre-trained model for extracting feature vectors from images using TensorFlow Hub. The feature vector can be used as input for various machine learning tasks, such as classification or clustering.


Input: preprocessed image

Output: feature vector

import tensorflow as tf
import tensorflow_hub as hub

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

# Preprocess the image
image = tf.constant(IMAGE_DATA)
processed_image = tf.image.resize(image, [224, 224])
processed_image = tf.expand_dims(processed_image, 0)

# Extract the feature vector
feature_vector = model(processed_image)

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 tasks such as image classification, object detection, and image similarity.


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


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',
                    output_shape=[1280],
                    trainable=False),
    tf.keras.layers.Dense(5, activation='softmax')
])

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

A pre-trained image feature vector model using MobileNet V2 architecture on ImageNet dataset. Can be used for transfer learning and generating image feature vectors.


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
embed = hub.load('https://tfhub.dev/google/universal-sentence-encoder/4')
embeddings = embed(['Hello, world!', 'How are you?'])


embeddings = embed(['Hello, world!', 'How are you?'])

Pearson correlation coefficient of 0.768


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


Image classification using pre-trained models

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

A pre-trained image classification model available on TensorFlow Hub that can be used to classify images into one of the 1000 ImageNet classes. The example provided shows how to load the Inception V3 model, preprocess an image, and obtain predictions.


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


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

predictions = model(image)

print(predictions)

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


Loading pre-trained models for image classification

import tensorflow as tf
import tensorflow_hub as hub

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

# Load an image and preprocess it
def load_image(file_path):
    img = tf.keras.preprocessing.image.load_img(file_path, target_size=(224, 224))
    img_array = tf.keras.preprocessing.image.img_to_array(img)
    img_array = tf.expand_dims(img_array, 0)  # Create a batch
    return img_array

# Predict the class of the image
img_array = load_image('path/to/your/image.jpg')
predictions = model(img_array)

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

A pre-trained image classification model using MobileNetV2 architecture with 100% width and 224x224 input size. The model is trained on the ImageNet dataset and 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/feature_vector/4',
                   input_shape=[224, 224, 3],
                   output_shape=[1280],
                   trainable=False),
    tf.keras.layers.Dense(1, activation='sigmoid')
])

A pre-trained image feature vector model using MobileNetV2 architecture that extracts features from input 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'])

A model for embedding 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_id = 'https://tfhub.dev/google/openimages_v4/ssd/mobilenet_v2/1'
detector = hub.load(model_id)

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

result = detector(image_tensor)
print(result)

A pre-trained image object detection model based on the SSD architecture with MobileNetV2 as the backbone. The model is capable of detecting objects in images and returning their class labels and bounding box coordinates.


input_text: A list of strings to be embedded

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


Python 3, TensorFlow 2.x, TensorFlow Hub

import tensorflow as tf
import tensorflow_hub as hub
detector = hub.load('https://tfhub.dev/google/openimages_v4/ssd_mobilenet_v2/1')
result = detector(image, score_threshold=0.5)

A pre-trained SSD MobileNet V2 model for object detection in images, trained on the Open Images v4 dataset. Detects objects and outputs their bounding boxes and class labels with associated confidence scores.


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.keras.preprocessing.image.load_img('path/to/image.jpg')
image_np = np.array(image)

input_tensor = tf.convert_to_tensor(image_np)
input_tensor = input_tensor[tf.newaxis, ...]

output_dict = loaded_model(input_tensor)

boxes = output_dict['detection_boxes'][0].numpy()
scores = output_dict['detection_scores'][0].numpy()
classes = output_dict['detection_classes'][0].numpy().astype(np.int32)

This API provides a pre-trained object detection model using TensorFlow Hub. The model is based on the SSD MobileNet V2 architecture and is trained on the COCO dataset. It can be used to detect multiple objects in an image and returns their class, bounding box coordinates, and confidence scores.


A tensor of shape [1, height, width, 3] containing a batch of images

A pre-trained TensorFlow Hub model for detecting objects in images using the MobileNetV2 FPNLite architecture


import tensorflow as tf
import tensorflow_hub as hub

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

# Load image and preprocess
image_path = 'path/to/image.jpg'
image = tf.io.read_file(image_path)
image = tf.image.decode_jpeg(image, channels=3)
image = tf.image.convert_image_dtype(image, tf.float32)

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

# Process result
boxes = result['detection_boxes']
classes = result['detection_classes']
scores = result['detection_scores']

Detects objects in images using the Faster R-CNN model with Inception-ResNet V2 backbone trained on the OpenImages V4 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(10, activation='softmax')
])

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

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

The MobileNetV2 100 224 feature vector model is a pre-trained neural network that extracts features from images. It is trained on the ImageNet dataset and can be used for various image classification and feature extraction tasks.


import tensorflow as tf
import tensorflow_hub as hub

model = hub.load('https://tfhub.dev/tensorflow/ssd_mobilenet_v2_fpnlite_320x320_coco17_tpu-8/1')
image_tensor = tf.convert_to_tensor(image_np, dtype=tf.uint8)
image_tensor = tf.expand_dims(image_tensor, 0)
output_dict = model(image_tensor)

A pre-trained object detection model that can detect objects in images using Single Shot MultiBox Detector (SSD) with MobileNet V2 FPN-Lite 320x320 as the feature extractor. The model is trained on the COCO 2017 dataset and can detect 80 different object classes.


import tensorflow as tf
import tensorflow_hub as hub
model_id = 'https://tfhub.dev/tensorflow/ssd_mobilenet_v2/2'
detector = hub.load(model_id)
result = detector(image_tensor)

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


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

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


import tensorflow as tf
import tensorflow_hub as hub

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

image = tf.keras.preprocessing.image.load_img('path/to/image.jpg')
image = tf.keras.preprocessing.image.img_to_array(image)
result = detector(image[None, ...])
print(result)

A pre-trained image object detection model using TensorFlow Hub to detect and classify objects in an image.


Input: List of strings

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


A pre-trained object detection model that can detect multiple objects in an image. The model is based on the SSD Mobilenet V2 architecture and is trained on the COCO dataset.


A video classification model 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!'])

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


model_id: The identifier of the pre-trained model to load

import tensorflow as tf
import tensorflow_hub as hub

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

# Load an image and make a prediction
image = tf.keras.preprocessing.image.load_img('path/to/image.jpg', target_size=(299, 299))
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 the Inception V3 architecture, available on TensorFlow Hub. The model can be used to classify images into 1000 different categories.


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

A model for encoding variable-length English text into fixed-length high-dimensional vectors. It is useful for applications such as semantic similarity, clustering, or text classification.


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, which is optimized for mobile and edge devices. It is trained on ImageNet dataset and can be used for various image classification tasks.


import tensorflow_hub as hub
model = hub.load('https://tfhub.dev/vasudevgupta7/wav2vec2/1')
transcript = model.signatures['serving_default'](audio_input)['output_0']

A pre-trained model to convert audio speech to text using wav2vec2_large_xlsr_53 architecture from TensorFlow Hub.


A string representing the ID of the model to be loaded

import tensorflow as tf
import tensorflow_hub as hub

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

# Run the detector on an image
result = detector(image_tensor)

A collection of TensorFlow Hub models for detecting objects in images using the EfficientDet architecture. These models can be used for various tasks such as object detection, instance segmentation, and more.


Input: List of strings

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

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 range of tasks.


Input: List of strings

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

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


A pre-trained image feature vector model based on MobileNetV2 architecture for image classification 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!', 'How are you?'])
print(embeddings)

A text embedding model that converts sentences into fixed-size vectors, trained on a variety of data sources and capable of general-purpose text embedding tasks


input_shape, input_tensor, trainable, output_shape

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',
                   input_shape=(299, 299, 3),
                   trainable=False)
])

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

features = model.predict(image_array)

A pre-trained model that extracts feature vectors from images using Inception V3 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'])


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),
    tf.keras.layers.Dense(1, activation='sigmoid')
])

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

A pre-trained image feature vector model that extracts features from images using MobileNetV2 architecture with a width multiplier of 1.4 and an input size of 224x224 pixels. The model is trained on the ImageNet dataset and achieves 80.3% accuracy.


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.


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.zeros([1, 224, 224, 3])  # A batch of images with shape [batch_size, height, width, 3].
logits = model(image)  # Logits with shape [batch_size, num_classes].

MobileNetV2 model for image classification, pre-trained on ImageNet and optimized for TensorFlow Hub.


import tensorflow as tf
import tensorflow_hub as hub

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

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

A Keras layer that wraps the MobileNet V2 model pre-trained on ImageNet for image feature extraction. It can be used to create a custom image classification model by adding a dense layer with the desired number of output classes and training on a specific dataset.


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

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


A TensorFlow Hub model for classifying audio events.


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)


Output: 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/feature_vector/4')
image_tensor = tf.zeros([1, 224, 224, 3]) # Replace with your own image tensor
features = model(image_tensor)

A pre-trained image feature vector model based on MobileNetV2, designed for efficient on-device image classification and transfer learning. It takes a 224x224x3 image tensor as input and outputs a 1280-dimensional feature vector.


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

A text embedding model that maps text inputs to a 512-dimensional vector space.


import tensorflow as tf
import tensorflow_hub as hub

model_id = 'https://tfhub.dev/tensorflow/deeplabv3/1'
model = hub.load(model_id)
result = model(image)

DeepLabV3 is an image segmentation model that partitions an image into semantically meaningful regions. It is pre-trained on the PASCAL VOC 2012 dataset and achieves an accuracy of 70.5%.


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

# Extract features
features = model(input_image)

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


import tensorflow as tf
import tensorflow_hub as hub

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

features = model.predict(images)

A pre-trained image feature vector model based on MobileNetV2 architecture, designed for image classification tasks. The model takes input images of shape [224, 224, 3] and outputs a 1280-dimensional feature vector.


import tensorflow as tf
import tensorflow_hub as hub

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

# Load a wav file
filename = 'audio_file.wav'
file_contents = tf.io.read_file(filename)
waveform = tf.audio.decode_wav(file_contents).audio

# Extract features
scores, embeddings, spectrogram = model(waveform)

YAMNet is a deep net that predicts 521 audio event classes based on the AudioSet dataset. It's used for audio feature extraction and can be used for tasks like audio classification, tagging, and recommendation.


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

Load a pre-trained MobileNetV2 model for image classification from 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)

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


import tensorflow as tf
import tensorflow_hub as hub

model = tf.keras.Sequential([
    hub.KerasLayer(
        handle='https://tfhub.dev/google/imagenet/mobilenet_v2_130_224/classification/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)

predictions = model.predict(image_array)

A pre-trained image classification model using the MobileNetV2 architecture, trained on the ImageNet dataset. It is designed for efficient on-device performance with reduced computational and memory requirements.


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

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


Input: Text or list of texts

Output: Array of embeddings

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


import tensorflow as tf
import tensorflow_hub as hub

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

# Preprocess your image, e.g. resize to 224x224 and normalize pixel values
processed_image = ...

# Extract feature vector
feature_vector = model(processed_image)

A pre-trained MobileNetV2 model that takes an input image and outputs a 1280-dimensional feature vector. Useful for transfer learning applications.


Embedding text into high-dimensional space


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/1'
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)
features = model(image)

This API allows you to extract image features using a pre-trained model from TensorFlow Hub. The model is trained on the ImageNet dataset and can be used to generate feature vectors for various image 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 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):
    image = tf.image.resize(image, (224, 224))
    image = tf.expand_dims(image, 0) / 255.0
    logits = model(image)
    return tf.argmax(logits, axis=-1)

image = tf.io.read_file('path/to/image.jpg')
image = tf.image.decode_jpeg(image)
class_id = classify_image(image)
print(class_id)

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


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 trained on ImageNet dataset for extracting features from images.


import tensorflow as tf
import tensorflow_hub as hub

img = Image.open('path/to/your/image.jpg').resize((224, 224))

img_tensor = tf.expand_dims(img_array, 0)

Top-1 accuracy: 75.2%, Top-5 accuracy: 92.5%

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/feature_vector/5'
model = hub.KerasLayer(model_id)

image = tf.keras.Input(shape=(299, 299, 3), dtype=tf.float32)
features = model(image)

A pre-trained image feature vector model using Inception V3 architecture on TensorFlow Hub, designed for extracting high-level 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_100_224/feature_vector/4',
                   input_shape=(224, 224, 3),
                   output_shape=(1280,),
                   trainable=False),
    tf.keras.layers.Dense(10, activation='softmax')
])

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

A Keras-compatible TensorFlow Hub module for extracting feature vectors from images using the MobileNet V2 architecture trained on ImageNet.


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


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)

# Example: Load an image and classify it
# image = ...  # Load an image
# result = model(image)
# print(result)

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


import tensorflow as tf
import tensorflow_hub as hub

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

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

# Predict
predictions = model(image_array)

# Decode predictions
class_names = imagenet_labels()
predicted_class = class_names[np.argmax(predictions[0])]

Top-1 Accuracy: 80.9%, Top-5 Accuracy: 95.2%

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


import tensorflow as tf
import tensorflow_hub as hub

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

Load an image classification model from TensorFlow Hub using the model id


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.


Load a pre-trained image classification model 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_050_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 that extracts useful features from input images using the MobileNetV2 architecture with a width multiplier of 0.5 and an input size of 224x224 pixels.


import tensorflow as tf
import tensorflow_hub as hub

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

# Load audio file and get waveform
audio_file = 'path/to/audio/file.wav'
waveform, sample_rate = tf.audio.decode_wav(tf.io.read_file(audio_file), desired_channels=1)

# Run the model on the waveform
class_scores, embeddings, spectrogram = model(waveform)

# Get the top class
top_class = tf.argmax(class_scores, axis=-1)

# Print the top class
print('Top class:', top_class.numpy())

YAMNet is a pretrained deep net that predicts 521 audio event classes based on the AudioSet dataset. It's useful for audio event classification tasks.


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 high-dimensional vectors that can be used for text classification, semantic similarity, clustering and other natural language tasks. It is designed for greater-than-word length text like sentences, phrases or short paragraphs.


import tensorflow as tf
import tensorflow_hub as hub

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

# Load an image as an example
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, 0)

# Make predictions
predictions = model(image)

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


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))
])
features = model.predict(images)

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


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


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

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/mobilenet_v3_large_100_224/feature_vector/5", input_shape=(224, 224, 3), output_shape=(1280), trainable=False),
    tf.keras.layers.Dense(10, activation='softmax')
])

A pre-trained model that converts images into 1280-dimensional feature vectors using MobileNet V3 Large architecture trained on ImageNet dataset.


Embedding text for machine learning tasks

Input: A list of strings

import tensorflow_hub as hub
embed = hub.load('https://tfhub.dev/google/universal-sentence-encoder/4')
embeddings = embed(['hello world', 'my name is John'])

A text embedding model that converts text into high-dimensional vectors for use in various machine learning tasks. The Universal Sentence Encoder encodes text into 512-dimensional vectors that can be used for tasks such as semantic similarity, classification, or clustering.


import tensorflow as tf
import tensorflow_hub as hub

model = tf.keras.Sequential([
    hub.KerasLayer('https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/feature_vector/4',
                  input_shape=(224,224,3),
                  trainable=False),
    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 Keras layer that extracts features from images using the MobileNetV2 model 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)
])

# Load image and preprocess
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)
image = np.expand_dims(image, axis=0)

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

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


Load a pre-trained image classification model from TensorFlow Hub using a 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])
])

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


Input: preprocessed image

Output: feature vector

import tensorflow as tf
import tensorflow_hub as hub

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

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

A pre-trained image feature vector model using MobileNetV2 architecture on ImageNet dataset. It takes a preprocessed image as input 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_v1_100_224/feature_vector/4', input_shape=(224, 224, 3), trainable=False),
    tf.keras.layers.Dense(10, activation='softmax')
])

model.summary()

A pre-trained image feature extraction model using MobileNet architecture trained on ImageNet dataset. It can be used for transfer learning and fine-tuning on new image classification tasks.


import tensorflow_hub as hub
model_id = 'https://tfhub.dev/google/universal-sentence-encoder/4'
model = hub.load(model_id)

Load a pre-trained text preprocessing model from TensorFlow Hub using the model's unique identifier


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

# Make predictions
predictions = model(input_image)

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

This API loads a pre-trained image classification model from TensorFlow Hub, allowing users to classify images using the loaded model. The example demonstrates how to load a MobileNetV2 model, preprocess an input image, make predictions, and decode the predictions to obtain class names.


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 pre-trained image classification models that can be easily loaded and used for various image classification tasks.


Input: A list of sentences or phrases

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

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_hub as hub
model = tf.keras.Sequential([
    hub.KerasLayer('https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/classification/4')
])

predictions = model.predict(images)

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


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

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


import tensorflow as tf
import tensorflow_hub as hub

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

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

# Make a prediction
predictions = model(input_image)

# 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 MobileNetV2 architecture, trained on ImageNet dataset, and available on TensorFlow Hub.


Loading a pre-trained image classification model

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

A pre-trained image classification model using MobileNetV2 architecture with an input size of 224x224 pixels. The model is trained on the ImageNet dataset and has a top-1 accuracy of 85.6%.


Loading a pre-trained model for image classification

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


import tensorflow as tf
import tensorflow_hub as hub

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

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

A pre-trained model for image classification using MobileNetV3 Large architecture 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/classification/4', input_shape=(224,224,3))])

A pre-trained image classification model using MobileNet V2 architecture from TensorFlow Hub. It is capable of classifying images into 1000 categories with 71% accuracy on the ImageNet dataset.


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

A text embedding model that converts text into high-dimensional vectors that can be used for text classification, semantic similarity, and other natural language processing 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 an image
image = tf.keras.preprocessing.image.load_img('path/to/image.jpg', target_size=(224, 224))
image_array = tf.keras.preprocessing.image.img_to_array(image)
image_batch = tf.expand_dims(image_array, 0)

# Run the model
predictions = loaded_model(image_batch)

This API allows users to load pre-trained models for image classification from TensorFlow Hub. The loaded models can be used to classify images into one of the pre-defined categories.


import tensorflow as tf
import tensorflow_hub as hub

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

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)

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

Pre-trained image classification models available on TensorFlow Hub for easy integration and usage.


import tensorflow as tf
import tensorflow_hub as hub
embed = hub.load('https://tfhub.dev/google/universal-sentence-encoder/4')
text = ['This is a sentence.']
embedding = 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.


A pre-trained model that encodes text into 512-dimensional embeddings


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

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


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

85% on SNLI, 76.9% on MultiNLI, and 0.803 on STS Benchmark

A pre-trained model for embedding text into a high-dimensional vector that can be used 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!'])
print(embeddings)

Load and use the Universal Sentence Encoder model for text preprocessing in 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.image.decode_jpeg(tf.io.read_file('path/to/image.jpg'))
result = detector(image[tf.newaxis, ...])

This API allows you to detect objects in images using a pre-trained model from TensorFlow Hub. The model is based on the SSD MobileNet V2 architecture and has been trained on the COCO dataset.


import tensorflow as tf
import tensorflow_hub as hub

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

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

output = detector(input_image)

print(output)

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


Object detection and localization in images

import tensorflow as tf
import tensorflow_hub as hub
detector = hub.load('https://tfhub.dev/tensorflow/ssd_mobilenet_v2_fpnlite_320x320_coco17_tpu-8/1')
input_image = tf.keras.preprocessing.image.load_img('path/to/image.jpg')
input_tensor = tf.keras.preprocessing.image.img_to_array(input_image)
input_tensor = tf.expand_dims(input_tensor, 0)
detections = detector(input_tensor)

A pre-trained object detection model that detects and localizes multiple objects in images using a Single Shot MultiBox Detector with MobileNetV2 FPN-Lite feature extractor.


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_tensor = tf.random.uniform(shape=(1, 224, 224, 3))
features = model(image_tensor)

A pre-trained image feature vector model using MobileNet V2 architecture on ImageNet dataset. It can be used to extract features from an input image tensor.


import tensorflow as tf
import tensorflow_hub as hub
detector = hub.load('https://tfhub.dev/tensorflow/ssd_mobilenet_v2/2')
result = detector(image_tensor)
boxes, labels, scores = result['detection_boxes'], result['detection_classes'], result['detection_scores']

A pre-trained object detection model that detects objects in images using SSD MobileNet V2 architecture


Convert text into a dense vector representation

Input: Text or list of texts

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 dense vector representation that can be used for various natural language processing tasks.


import tensorflow as tf
import tensorflow_hub as hub

model_id = 'https://tfhub.dev/tensorflow/efficientdet/lite2/detection/1'
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)

This API allows for object detection in images using TensorFlow Hub and the EfficientDet model. It can be used to load a pre-trained model and detect objects in a given image.


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. It is pre-trained on a variety of data sources and can be fine-tuned for specific tasks if needed.


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

predictions = model.predict(image)

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


Object detection and classification in images

import tensorflow as tf
import tensorflow_hub as hub
model_id = 'https://tfhub.dev/tensorflow/ssd_mobilenet_v2/2'
detector = hub.load(model_id)
result = detector(image_tensor)

This API allows you to detect and classify objects in images using TensorFlow Hub and pre-trained models such as SSD MobileNet V2.


The id of the model to be loaded from TensorFlow Hub

import tensorflow as tf
import tensorflow_hub as hub

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

image = tf.image.decode_jpeg(tf.io.read_file('path/to/image.jpg'))
detected_objects = model(image[tf.newaxis, ...])

Load and use an object detection model from TensorFlow Hub for detecting objects in images.


import tensorflow_hub as hub
model = hub.load('https://tfhub.dev/google/Video_Classification_Model/1')
result = model(video_url)

A pre-trained video classification model available on TensorFlow Hub, capable of classifying videos into one of 700 action classes.


import tensorflow_hub as hub
model_id = 'https://tfhub.dev/tensorflow/ssd_mobilenet_v2/2'
detector = hub.load(model_id)
result = detector(image_tensor)

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


import tensorflow as tf
import tensorflow_hub as hub

model = hub.load('https://tfhub.dev/google/kinetics-i3d/1')
video_tensor = tf.random.uniform(shape=[1, 79, 224, 224, 3])
output = model(video_tensor)
print(output.shape)

A pre-trained video classification model using the Inflated 3D Convolutional Network (I3D) architecture on the Kinetics-400 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)
])

This API provides a feature vector for images using the MobileNetV2 architecture trained on the ImageNet dataset. The input images should have shape (224, 224, 3), and the output feature vector has 1280 dimensions. The model is available on TensorFlow Hub and can be used for transfer learning applications.


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/mobilenet_v2_100_224/feature_vector/4', input_shape=(224, 224, 3), output_shape=(1280,))
])

features = model.predict(images)

A pre-trained image feature vector model using MobileNetV2 architecture 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(['example sentence'])

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 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
embed = hub.load('https://tfhub.dev/google/universal-sentence-encoder/4')
text = ['This is a test sentence.']
embeddings = embed(text)

The Universal Sentence Encoder (USE) is a pre-trained model for generating embeddings of text. It is trained on a variety of data sources and can be used for tasks such as semantic similarity and classification.


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.Input(shape=(224, 224, 3))
features = model(image)

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


import tensorflow as tf
import tensorflow_hub as hub

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

Load a pre-trained image classification model from TensorFlow Hub for 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),
                   trainable=False),
    tf.keras.layers.Dense(10, activation='softmax')
])

A pre-trained image feature vector model using MobileNet V2 architecture on ImageNet dataset. Can be used for various image classification 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!', 'My name is John Doe.'])


import tensorflow as tf
import tensorflow_hub as hub

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

This API generates audio embeddings using a pre-trained model from TensorFlow Hub. The model can be loaded with a specified model_id, and embeddings can be extracted for input audio samples.


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/feature_vector/4',
                   input_shape=(224, 224, 3),
                   trainable=False),
    tf.keras.layers.Dense(1)
])

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

features = model.predict(image_array)

This API provides a compact representation of an image by extracting feature vectors using MobileNetV2 architecture pretrained on ImageNet dataset. It can be used for tasks like image classification, object detection, and image similarity.


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

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


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 using MobileNetV2 architecture on the ImageNet dataset. It can be used for various image recognition tasks by extracting meaningful features from input images.


import tensorflow as tf
import tensorflow_hub as hub

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

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

features = model.predict(image)

This API allows you to extract feature vectors from images using the Inception V3 model pretrained on the ImageNet dataset.


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

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


Embeds 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!', 'Embedding is fun!'])


This API provides a Keras layer for extracting feature vectors from images using the MobileNetV2 model pretrained on ImageNet dataset.


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


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.uniform((1, 224, 224, 3))
result = model(image)
print(result)

A pre-trained image classification model available on TensorFlow Hub that can be used to classify images into different categories.


The ID of the pre-trained model

trainable

Whether the model should be trainable or not

import tensorflow as tf
import tensorflow_hub as hub

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

# Load example image and preprocess it
image = tf.keras.preprocessing.image.load_img('example_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.predict(image_array)

A pre-trained image classification model using MobileNetV2 architecture on ImageNet dataset, available through TensorFlow Hub.


Text embedding using a pre-trained model

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

A pre-trained text embedding model that converts sentences into fixed-size vector representations, enabling efficient semantic similarity calculations and other 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],
                   output_shape=[1280],
                   trainable=False),
    tf.keras.layers.Dense(num_classes, activation='softmax')
])

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

This API provides a pre-trained MobileNetV2 model for extracting feature vectors from images. The model is trained on the ImageNet dataset and can be used as a feature extractor for various image classification tasks.


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

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


Extracts image features for various tasks

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

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


Input: image

import tensorflow_hub as hub
import tensorflow as tf

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

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

features = model.predict(image)

Feature extraction from images using Inception V3 model trained on ImageNet dataset


Tensor of shape [batch_size, num_samples] containing audio signals

import tensorflow as tf
import tensorflow_hub as hub

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

# Load an audio file
audio_data = ... # Load audio data as a tensor

# Generate embeddings
embeddings = model(audio_data)

This API allows you to generate embeddings for audio files using a pre-trained YAMNet model from TensorFlow Hub. The embeddings can be used for various tasks such as audio classification, similarity search, and more.


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


Input: Image tensor

Output: Segmentation mask tensor

import tensorflow as tf
import tensorflow_hub as hub
model = hub.load('https://tfhub.dev/tensorflow/deeplabv3_257_mv_gpu/1')
image_tensor = tf.image.resize(image, (257, 257))
segmentation_mask = model(image_tensor)

DeepLab is a state-of-the-art deep learning model for semantic image segmentation, where the goal is to assign semantic labels (e.g., person, dog, cat and so on) to every pixel in the input image. This model is trained on the PASCAL VOC 2012 dataset.


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

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

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

A pre-trained image feature vector model based on MobileNetV3 small architecture for TensorFlow Hub, which can be used for transfer learning or as a feature extractor for image classification tasks.


High similarity scores for semantically similar sentences

A text embedding model that converts text data into high-dimensional vectors, capturing semantic meaning and enabling various natural language processing tasks.


Embedding text into high-dimensional vectors

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


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)

Load a pre-trained model from TensorFlow Hub for image classification using the Inception V3 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!'])

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.


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

Extracts feature vectors from images using MobileNetV2 architecture pretrained 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 = tf.keras.Sequential([
    hub.KerasLayer(model_id, input_shape=(224, 224, 3))
])

# Load an image and make predictions
from PIL import Image
import numpy as np

image = Image.open('path/to/your/image.jpg')
image = image.resize((224, 224))
input_data = np.array(image) / 255.0
input_data = np.expand_dims(input_data, axis=0)

predictions = model.predict(input_data)
print(predictions)

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


import tensorflow as tf
import tensorflow_hub as hub

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

# Use the model to extract features from an image
feature_vector = model.predict(image)

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


import tensorflow as tf
import tensorflow_hub as hub
IMAGE_SHAPE = (224, 224)
classifier = tf.keras.Sequential([
    hub.KerasLayer('https://tfhub.dev/google/tf2-preview/mobilenet_v2/classification/4', input_shape=IMAGE_SHAPE+(3,))
])
image = tf.keras.utils.get_file('image.jpg','https://storage.googleapis.com/download.tensorflow.org/example_images/grace_hopper.jpg')
image = tf.keras.preprocessing.image.load_img(image, target_size=IMAGE_SHAPE)
image = tf.keras.preprocessing.image.img_to_array(image)
image = tf.expand_dims(image, 0)
prediction = classifier.predict(image)

MobileNetV2 model for image classification, pre-trained on 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', 'I am learning how to use the 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. 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/google/imagenet/mobilenet_v2_100_224/feature_vector/4'
model = tf.keras.Sequential([
    hub.KerasLayer(model_id, input_shape=(224, 224, 3), trainable=True),
    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 for image classification and transfer learning, based on MobileNetV2 architecture.


Load and use pre-trained image classification models

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

# Run inference
predictions = model(input_image)

# Process the predictions
predicted_class_index = tf.math.argmax(predictions, axis=-1).numpy()[0]
print('Predicted class index:', predicted_class_index)

A pre-trained image classification model using MobileNetV2 architecture trained on ImageNet dataset. The model is designed to classify images into one of 1000 categories.


import tensorflow as tf
import tensorflow_hub as hub

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

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 model for extracting feature vectors from images using MobileNetV2 architecture trained on ImageNet dataset


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


import tensorflow as tf
import tensorflow_hub as hub

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

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

feature_vector = model.predict(image)

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


import tensorflow as tf
import tensorflow_hub as hub

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

Load an image classification model from TensorFlow Hub using the model_id.


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

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


import tensorflow 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.Input(shape=(224, 224, 3))
features = model(image)

A pre-trained image feature extraction model using MobileNet V2 architecture with 224x224 input size and 1280-dimensional output feature vector. The model is trained on ImageNet dataset and can be used for various image recognition tasks.


import tensorflow as tf
import tensorflow_hub as hub

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

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

This model takes an input image and outputs a 1280-dimensional feature vector. It is based on the MobileNetV2 architecture and pretrained on the ImageNet dataset.


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

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


Image classification using pre-trained model

import tensorflow as tf
import tensorflow_hub as hub
from PIL import Image
import numpy as np

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

image = Image.open('path/to/your/image.jpg').resize((224, 224))
input_image = np.array(image) / 255.0
input_image = np.expand_dims(input_image, axis=0)

predictions = model.predict(input_image)
predicted_class = np.argmax(predictions[0])
print('Predicted class:', predicted_class)

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


Image classification using pre-trained models

The identifier of the pre-trained model to be loaded from TensorFlow Hub

Load and use pre-trained image classification models from TensorFlow Hub 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/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)

This API provides a Keras layer that extracts features from images using the MobileNetV2 model trained on ImageNet dataset. It can be used for various tasks such as image classification, object detection, 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'])
print(embeddings)


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

A deep-learning model for embedding 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/4', trainable=False),
  tf.keras.layers.Dense(10, activation='softmax')
])

This API provides a pre-trained image feature vector model based on MobileNetV2 architecture. It extracts features from images and can be used as a base model 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 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)

# Get the predictions
predictions = model(input_image)

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

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

A pre-trained image classification model using MobileNetV2 architecture with 100% depth and 224x224 input size, 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))
])

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

# Extract features
features = model.predict(image_array)

This API provides a feature vector for images using the MobileNetV2 model trained on ImageNet dataset. It takes an input image of shape (224, 224, 3) and outputs a 1280-dimensional feature vector.


import tensorflow as tf
import tensorflow_hub as hub

# Load the model
model_id = 'https://tfhub.dev/google/imagenet/inception_v3/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=(299, 299))
image = tf.keras.preprocessing.image.img_to_array(image)
image = tf.keras.applications.inception_v3.preprocess_input(image)

# Predict the class
predictions = model(image[None, ...])

# Get the class label
predicted_class = tf.keras.applications.inception_v3.decode_predictions(predictions.numpy())[0][0][1]

Top-1 Accuracy: 77.9%, Top-5 Accuracy: 93.7%

This API provides a pre-trained image classification model using TensorFlow Hub, which can be used to classify images into various categories. The model is trained on the ImageNet dataset and can be loaded using the `hub.load()` function.