Tugas MediaPipe Image Embedder memungkinkan Anda membuat representasi numerik gambar,
yang berguna dalam menyelesaikan berbagai tugas gambar berbasis ML. Fungsi
ini sering digunakan untuk membandingkan kemiripan dua gambar menggunakan
teknik perbandingan matematika seperti Kemiripan Kosinus. Tugas ini beroperasi
pada data gambar dengan model machine learning (ML) sebagai data statis atau streaming
kontinu, dan menghasilkan representasi numerik dari data gambar sebagai daftar
vektor fitur berdimensi tinggi, yang juga dikenal sebagai vektor penyematan, dalam
bentuk floating point atau kuantisasi.
Mulai gunakan tugas ini dengan mengikuti salah satu panduan penerapan ini untuk
platform target Anda. Panduan khusus platform ini akan memandu Anda dalam penerapan dasar
tugas ini, menggunakan model yang direkomendasikan, dan memberikan contoh
kode dengan opsi konfigurasi yang direkomendasikan:
Bagian ini menjelaskan kemampuan, input, output, dan opsi konfigurasi tugas ini.
Fitur
Pemrosesan gambar input - Pemrosesan mencakup rotasi gambar, pengubahan ukuran,
normalisasi, dan konversi ruang warna.
Area minat - Melakukan penyematan pada area gambar, bukan
seluruh gambar.
Komputasi kemiripan penyematan - Fungsi utilitas bawaan untuk menghitung
kemiripan kosinus
antara dua vektor fitur
Kuantisasi - Mendukung kuantisasi skalar untuk vektor fitur.
Input tugas
Output tugas
Input dapat berupa salah satu jenis data berikut:
Gambar diam
Frame video yang didekode
Feed video live
Image Embedder menghasilkan daftar penyematan yang terdiri dari:
Embedding: vektor fitur itu sendiri, baik dalam bentuk floating point maupun
kuantisasi skalar.
Indeks head: indeks untuk head yang menghasilkan penyematan ini.
Nama head (opsional): nama head yang menghasilkan penyematan ini.
Opsi konfigurasi
Tugas ini memiliki opsi konfigurasi berikut:
Nama Opsi
Deskripsi
Rentang Nilai
Nilai Default
running_mode
Menetapkan mode berjalan untuk tugas. Ada tiga
mode:
GAMBAR: Mode untuk input gambar tunggal.
VIDEO: Mode untuk frame video yang didekode.
LIVE_STREAM: Mode untuk live stream data
input, seperti dari kamera. Dalam mode ini, resultListener harus
dipanggil untuk menyiapkan pemroses guna menerima hasil
secara asinkron.
{IMAGE, VIDEO, LIVE_STREAM}
IMAGE
l2_normalize
Apakah akan menormalisasi vektor fitur yang ditampilkan dengan norma L2.
Gunakan opsi ini hanya jika model belum berisi Opsi TFLite L2_NORMALIZATION native. Pada umumnya, hal ini sudah terjadi dan
normalisasi L2 akan dicapai melalui inferensi TFLite tanpa memerlukan
opsi ini.
Boolean
False
quantize
Apakah penyematan yang ditampilkan harus dikuantifikasi ke byte melalui
kuantisasi skalar. Secara implisit, penyematan diasumsikan sebagai unit-norm dan
oleh karena itu, dimensi apa pun dijamin memiliki nilai dalam [-1,0, 1,0]. Gunakan
opsi l2_normalize jika tidak demikian.
Boolean
False
result_callback
Menetapkan pemroses hasil untuk menerima hasil penyematan secara asinkron saat Penyematan Gambar berada dalam mode live stream. Hanya dapat digunakan jika mode berjalan disetel ke LIVE_STREAM
T/A
Tidak ditetapkan
Model
Image Embedder memerlukan model penyematan gambar untuk didownload dan disimpan
di direktori project Anda. Mulailah dengan model default yang direkomendasikan untuk
platform target Anda saat Anda mulai mengembangkan dengan tugas ini. Model lain yang tersedia
biasanya membuat kompromi antara performa, akurasi, resolusi, dan
persyaratan resource, dan dalam beberapa kasus, menyertakan fitur tambahan.
Model MobileNetV3
Grup model ini menggunakan arsitektur MobileNet V3
dan dilatih menggunakan data ImageNet.
Model ini menggunakan pengganda 0,75 untuk kedalaman (jumlah fitur) di
lapisan konvolusi untuk menyesuaikan kompromi akurasi-latensi. Selain itu,
MobileNet V3 tersedia dalam dua ukuran berbeda, kecil dan besar, untuk menyesuaikan jaringan
dengan kasus penggunaan resource rendah atau tinggi.
Berikut adalah tolok ukur tugas untuk seluruh pipeline berdasarkan
model terlatih di atas. Hasil latensi adalah latensi rata-rata di Pixel 6 yang menggunakan
CPU / GPU.
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Informasi yang saya butuhkan tidak ada","missingTheInformationINeed","thumb-down"],["Terlalu rumit/langkahnya terlalu banyak","tooComplicatedTooManySteps","thumb-down"],["Sudah usang","outOfDate","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Masalah kode / contoh","samplesCodeIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2025-01-13 UTC."],[],[],null,["# Image embedding task guide\n\nThe MediaPipe Image Embedder task lets you create a numeric representation of an image,\nwhich is useful in accomplishing various ML-based image tasks. This\nfunctionality is frequently used to compare the similarity of two images using\nmathematical comparison techniques such as Cosine Similarity. This task operates\non image data with a machine learning (ML) model as static data or a continuous\nstream, and outputs a numeric representation of the image data as a list of\nhigh-dimensional feature vectors, also known as embedding vectors, in either\nfloating-point or quantized form.\n\n[Try it!arrow_forward](https://mediapipe-studio.webapps.google.com/demo/image_embedder)\n\nGet Started\n-----------\n\nStart using this task by following one of these implementation guides for your\ntarget platform. These platform-specific guides walk you through a basic\nimplementation of this task, using a recommended model, and provide code\nexamples with the recommended configuration options:\n\n- **Android** - [Code\n example](https://github.com/google-ai-edge/mediapipe-samples/tree/main/examples/image_embedder/android) - [Guide](./android)\n- **Python** - [Code\n example](https://colab.sandbox.google.com/github/googlesamples/mediapipe/blob/main/examples/image_embedder/python/image_embedder.ipynb) - [Guide](./python)\n- **Web** - [Code example](https://codepen.io/mediapipe-preview/pen/yLqxbaZ) - [Guide](./web_js)\n\nTask details\n------------\n\nThis section describes the capabilities, inputs, outputs, and configuration\noptions of this task.\n\n### Features\n\n- **Input image processing** - Processing includes image rotation, resizing, normalization, and color space conversion.\n- **Region of interest** - Performs embedding on a region of the image instead of the whole image.\n- **Embedding similarity computation** - Built-in utility function to compute the [cosine similarity](https://en.wikipedia.org/wiki/Cosine_similarity) between two feature vectors\n- **Quantization** - Supports scalar quantization for the feature vectors.\n\n| Task inputs | Task outputs |\n|-------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| Input can be one of the following data types: - Still images \u003c!-- --\u003e - Decoded video frames \u003c!-- --\u003e - Live video feed | Image Embedder outputs a list of embeddings consisting of: - Embedding: the feature vector itself, either in floating-point form or scalar-quantized. \u003c!-- --\u003e - Head index: the index for the head that produced this embedding. \u003c!-- --\u003e - Head name (optional): the name of the head that produced this embedding. |\n\n### Configurations options\n\nThis task has the following configuration options:\n\n| Option Name | Description | Value Range | Default Value |\n|-------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------|---------------|\n| `running_mode` | Sets the running mode for the task. There are three modes: \u003cbr /\u003e IMAGE: The mode for single image inputs. \u003cbr /\u003e VIDEO: The mode for decoded frames of a video. \u003cbr /\u003e LIVE_STREAM: The mode for a livestream of input data, such as from a camera. In this mode, resultListener must be called to set up a listener to receive results asynchronously. | {`IMAGE, VIDEO, LIVE_STREAM`} | `IMAGE` |\n| `l2_normalize` | Whether to normalize the returned feature vector with L2 norm. Use this option only if the model does not already contain a native L2_NORMALIZATION TFLite Op. In most cases, this is already the case and L2 normalization is thus achieved through TFLite inference with no need for this option. | `Boolean` | `False` |\n| `quantize` | Whether the returned embedding should be quantized to bytes via scalar quantization. Embeddings are implicitly assumed to be unit-norm and therefore any dimension is guaranteed to have a value in \\[-1.0, 1.0\\]. Use the l2_normalize option if this is not the case. | `Boolean` | `False` |\n| `result_callback` | Sets the result listener to receive the embedding results asynchronously when the Image Embedder is in the live stream mode. Can only be used when running mode is set to `LIVE_STREAM` | N/A | Not set |\n\n| **Note:** The `resultListener` is dependent on `runningMode`. Only set the `resultListener` when `runningMode` is set to `LIVE_STREAM`.\n\nModels\n------\n\nThe Image Embedder requires an image embedding model to be downloaded and stored\nin your project directory. Start with the default, recommended model for your\ntarget platform when you start developing with this task. The other available\nmodels typically make trade-offs between performance, accuracy, resolution, and\nresource requirements, and in some cases, include additional features.\n| **Attention:** This MediaPipe Solutions Preview is an early release. [Learn more](/edge/mediapipe/solutions/about#notice).\n\n### MobileNetV3 model\n\nThis model family uses a [MobileNet V3](https://arxiv.org/abs/1905.02244)\narchitecture and was trained using [ImageNet](https://www.image-net.org) data.\nThis model uses a multiplier of 0.75 for the depth (number of features) in the\nconvolutional layers to tune the accuracy-latency trade off. In addition,\nMobileNet V3 comes in two different sizes, small and large, to adapt the network\nto low or high resource use cases.\n\n| Model name | Input shape | Quantization type | Versions |\n|----------------------------------------------------------------------------------------------------------------------------------------------------|-------------|-------------------|--------------------------------------------------------------------------------------------------------------------------------------|\n| [MobileNet-V3 (small)](https://storage.googleapis.com/mediapipe-models/image_embedder/mobilenet_v3_small/float32/latest/mobilenet_v3_small.tflite) | 224 x 224 | None (float32) | [Latest](https://storage.googleapis.com/mediapipe-models/image_embedder/mobilenet_v3_small/float32/latest/mobilenet_v3_small.tflite) |\n| [MobileNet-V3 (large)](https://storage.googleapis.com/mediapipe-models/image_embedder/mobilenet_v3_large/float32/latest/mobilenet_v3_large.tflite) | 224 x 224 | None (float32) | [Latest](https://storage.googleapis.com/mediapipe-models/image_embedder/mobilenet_v3_large/float32/latest/mobilenet_v3_large.tflite) |\n\nTask benchmarks\n---------------\n\nHere's the task benchmarks for the whole pipeline based on the above\npre-trained models. The latency result is the average latency on Pixel 6 using\nCPU / GPU.\n\n| Model Name | CPU Latency | GPU Latency |\n|----------------------|-------------|-------------|\n| MobileNet-V3 (small) | 3.94ms | 7.83ms |\n| MobileNet-V3 (large) | 9.75ms | 9.08ms |"]]