Compare commits

...
Author SHA1 Message Date
Andrew Ferlitsch 45071a5fac fix: rebrand/clean 2023-10-05 19:58:51 +00:00
@@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"metadata": {
"id": "ur8xi4C7S06n"
},
@@ -29,7 +29,7 @@
"id": "JAPoU8Sm5E6e"
},
"source": [
"# Using Vertex AI Multimodal Embeddings and Matching Engine\n",
"# Using Vertex AI Multimodal Embeddings and Vector Search\n",
"![ ](https://www.google-analytics.com/collect?v=2&tid=G-L6X3ECH596&cid=1&en=page_view&sid=1&dt=sdk_matching_engine_create_multimodal_embeddings.ipynb&dl=notebooks%2Fofficial%2Fmatching_engine%2Fsdk_matching_engine_create_multimodal_embeddings.ipynb)\n",
"<table align=\"left\">\n",
" <td>\n",
@@ -60,9 +60,9 @@
"source": [
"## Overview\n",
"\n",
"This example demonstrates how to create text-to-image embeddings using the DiffusionDB dataset and the Vertex AI Multimodal Embeddings model. The embeddings are uploaded to the Vertex AI Matching Engine service, which is a high scale, low latency solution to find similar vectors for a large corpus. Moreover, it is a fully managed offering, further reducing operational overhead. It is built upon [Approximate Nearest Neighbor (ANN) technology](https://ai.googleblog.com/2020/07/announcing-scann-efficient-vector.html) developed by Google Research.\n",
"This example demonstrates how to create text-to-image embeddings using the DiffusionDB dataset and the Vertex AI Multimodal Embeddings model. The embeddings are uploaded to the Vertex AI Vector Search service, which is a high scale, low latency solution to find similar vectors for a large corpus. Moreover, it is a fully managed offering, further reducing operational overhead. It is built upon [Approximate Nearest Neighbor (ANN) technology](https://ai.googleblog.com/2020/07/announcing-scann-efficient-vector.html) developed by Google Research.\n",
"\n",
"To learn more, see the official documentation for [Vertex AI Multimodal Embeddings](https://cloud.google.com/vertex-ai/docs/generative-ai/embeddings/get-multimodal-embeddings#supported_models), and [Vertex AI Matching Engine](https://cloud.google.com/vertex-ai/docs/matching-engine/overview)."
"To learn more, see the official documentation for [Vertex AI Multimodal Embeddings](https://cloud.google.com/vertex-ai/docs/generative-ai/embeddings/get-multimodal-embeddings#supported_models), and [Vertex AI Vector Search](https://cloud.google.com/vertex-ai/docs/matching-engine/overview)."
]
},
{
@@ -78,7 +78,7 @@
"This tutorial uses the following Google Cloud ML services:\n",
"\n",
"- `Vertex AI Multimodal Embeddings`\n",
"- `Vertex AI Matching Engine`\n",
"- `Vertex AI Vector Search`\n",
"\n",
"The steps performed include:\n",
"\n",
@@ -124,7 +124,7 @@
"source": [
"# Install the packages\n",
"! pip3 install --upgrade google-cloud-aiplatform \\\n",
" google-cloud-storage"
" google-cloud-storage"
]
},
{
@@ -159,7 +159,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": null,
"metadata": {
"id": "bea801acf6b5"
},
@@ -214,7 +214,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": null,
"metadata": {
"id": "474be5183c27"
},
@@ -255,7 +255,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": null,
"metadata": {
"id": "fbc9cd30cc4b"
},
@@ -275,7 +275,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": null,
"metadata": {
"id": "a336a05c6149"
},
@@ -317,13 +317,13 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": null,
"metadata": {
"id": "MzGDU7TWdts_"
},
"outputs": [],
"source": [
"BUCKET_URI = \"gs://your-bucket-name-unique\" # @param {type:\"string\"}"
"BUCKET_URI = f\"gs://your-bucket-name-{PROJECT_ID}-unique\" # @param {type:\"string\"}"
]
},
{
@@ -408,19 +408,11 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": null,
"metadata": {
"id": "7d27d986c61f"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Downloading files |████████████████████████████████████████| 4/4 [100%] in 36.3s\u001b[?25h\u001b[J\n"
]
}
],
"outputs": [],
"source": [
"# Download image files from 1 to 5. Each file is 1000 images.\n",
"! python diffusiondb/scripts/download.py -i 1 -r 5"
@@ -460,22 +452,11 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": null,
"metadata": {
"id": "2cacd9869ee5"
},
"outputs": [
{
"data": {
"text/plain": [
"4000"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"import json\n",
"import os\n",
@@ -508,7 +489,7 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": null,
"metadata": {
"id": "ce31cc893826"
},
@@ -551,7 +532,7 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": null,
"metadata": {
"id": "fc3c32afb383"
},
@@ -594,26 +575,11 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": null,
"metadata": {
"id": "bc753c9264a9"
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"100%|██████████| 4000/4000 [02:14<00:00, 29.69it/s]\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Safe images = 3292 out of 4000 images\n"
]
}
],
"outputs": [],
"source": [
"import time\n",
"from concurrent.futures import ThreadPoolExecutor\n",
@@ -662,7 +628,7 @@
},
{
"cell_type": "code",
"execution_count": 27,
"execution_count": null,
"metadata": {
"id": "00c8234f9828"
},
@@ -699,7 +665,7 @@
},
{
"cell_type": "code",
"execution_count": 28,
"execution_count": null,
"metadata": {
"id": "ec925af6f502"
},
@@ -870,7 +836,7 @@
},
{
"cell_type": "code",
"execution_count": 51,
"execution_count": null,
"metadata": {
"id": "ae5933cb5a51"
},
@@ -940,44 +906,11 @@
},
{
"cell_type": "code",
"execution_count": 31,
"execution_count": null,
"metadata": {
"id": "42f869fd66f5"
},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "a0b8bc02ec814607b62ef9ebcc18d1e4",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
" 0%| | 0/1000 [00:00<?, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"CPU times: user 6.99 s, sys: 1.41 s, total: 8.4 s\n",
"Wall time: 1min 52s\n"
]
},
{
"data": {
"text/plain": [
"1000"
]
},
"execution_count": 31,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"%%time\n",
"# Encode a sample subset of images\n",
@@ -1105,18 +1038,7 @@
"metadata": {
"id": "55a128883028"
},
"outputs": [
{
"data": {
"text/plain": [
"1408"
]
},
"execution_count": 40,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"DIMENSIONS = len(text_embedding)\n",
"\n",
@@ -1221,7 +1143,7 @@
},
{
"cell_type": "code",
"execution_count": 42,
"execution_count": null,
"metadata": {
"id": "qiIg9b5zJLi1"
},
@@ -1233,7 +1155,7 @@
},
{
"cell_type": "code",
"execution_count": 43,
"execution_count": null,
"metadata": {
"id": "Y4zooldkGoM4"
},
@@ -1378,7 +1300,7 @@
},
{
"cell_type": "code",
"execution_count": 53,
"execution_count": null,
"metadata": {
"id": "48e4e417a496"
},
@@ -1390,41 +1312,11 @@
},
{
"cell_type": "code",
"execution_count": 54,
"execution_count": null,
"metadata": {
"id": "A3KYVw5HB-4v"
},
"outputs": [
{
"data": {
"text/plain": [
"[[MatchNeighbor(id='40d7df76-5413-4948-9a19-6360f9461390.png', distance=0.8957392573356628),\n",
" MatchNeighbor(id='f31deabd-b18f-43ae-a336-dfe7a74f521c.png', distance=0.9005841016769409),\n",
" MatchNeighbor(id='9d990860-cc36-400c-b414-ea7a6257bff8.png', distance=0.9158724546432495),\n",
" MatchNeighbor(id='6ba4dfe8-e163-4264-971a-257d12facb7c.png', distance=0.919234037399292),\n",
" MatchNeighbor(id='2ece928d-264b-4283-ae86-78be08b27820.png', distance=0.9204674363136292),\n",
" MatchNeighbor(id='b5e3502d-0b1d-4362-b14e-c09c84ff0238.png', distance=0.9226469993591309),\n",
" MatchNeighbor(id='9c96ecbe-a749-4c47-bd30-8853606c3c87.png', distance=0.9258934259414673),\n",
" MatchNeighbor(id='e7f5f1a7-88d1-4ab3-83b8-f02d50e5d564.png', distance=0.9260851144790649),\n",
" MatchNeighbor(id='21c6313b-55bd-4e83-8fab-751d901a8855.png', distance=0.9280754327774048),\n",
" MatchNeighbor(id='bb0b2d6b-8b74-4f0e-88be-fc8dc3d6ff9e.png', distance=0.9368126392364502),\n",
" MatchNeighbor(id='4e4c32d0-70ba-4491-8adb-e0d46a92e3b0.png', distance=0.9379324913024902),\n",
" MatchNeighbor(id='21b7bde7-b29e-44e7-ac8c-a4f748199342.png', distance=0.9382714629173279),\n",
" MatchNeighbor(id='f8714403-6baa-4cec-8757-897a83a04ec6.png', distance=0.9383534789085388),\n",
" MatchNeighbor(id='4754616e-cd52-4a5f-a9b7-6f3a9d569d6b.png', distance=0.9387881755828857),\n",
" MatchNeighbor(id='de7dafef-67ed-4d3f-9b7d-58b8a8a008d6.png', distance=0.9389169216156006),\n",
" MatchNeighbor(id='d460aa8b-a435-4746-b249-5bf32648bddb.png', distance=0.939376175403595),\n",
" MatchNeighbor(id='e4430d8c-3200-4b4e-822e-000453a3d5ce.png', distance=0.9404100179672241),\n",
" MatchNeighbor(id='b0a566fa-504a-4f67-a2d1-d54169ce19f7.png', distance=0.9415013194084167),\n",
" MatchNeighbor(id='87971cfd-ac2c-4ac0-ad9b-e5d999fc0509.png', distance=0.9416283369064331),\n",
" MatchNeighbor(id='b6a4ca3e-d98d-4d1b-af97-d54f47806491.png', distance=0.9424576163291931)]]"
]
},
"execution_count": 54,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"# Define number of neighbors to return\n",
"NUM_NEIGHBORS = 20\n",