Shortcuts

Image Embedder

The Task

Image embedding encodes an image into a vector of features which can be used for a downstream task. This could include: clustering, similarity search, or classification.


Example

Let’s see how to use the ImageEmbedder with a pretrained backbone to obtain feature vectors from the hymenoptera data. Once we’ve downloaded the data, we create the ImageEmbedder and perform inference (obtaining feature vectors / embeddings) using predict(). Here’s the full example:

from flash.core.data.utils import download_data
from flash.image import ImageEmbedder

# 1. Download the data
download_data("https://pl-flash-data.s3.amazonaws.com/hymenoptera_data.zip", "data/")

# 2. Build the task
embedder = ImageEmbedder(backbone="resnet101")

# 3. Generate an embedding from an image path.
embeddings = embedder.predict(["data/hymenoptera_data/predict/153783656_85f9c3ac70.jpg"])
print(embeddings)
Read the Docs v: stable
Versions
latest
stable
0.5.0
0.4.0
0.3.2
0.3.1
0.3.0
0.2.3
0.2.2
0.2.1
0.2.0
0.1.0post1
Downloads
pdf
html
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.