Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 20 additions & 15 deletions notebooks/QuickStart.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,7 @@
"execution_count": null,
"id": "3cd0d138",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Enter JSON string: "
]
}
],
"outputs": [],
"source": [
"! adb config create --active --from-json"
]
Expand Down Expand Up @@ -307,23 +299,28 @@
"outputs": [],
"source": [
"from aperturedb.CommonLibrary import create_connector, execute_query\n",
"from aperturedb.NotebookHelpers import display\n",
"from aperturedb.NotebookHelpers import display as nbd\n",
"from IPython.display import display\n",
"import clip\n",
"import torch\n",
"\n",
"device = \"cuda\" if torch.cuda.is_available() else \"cpu\"\n",
"model, preprocess = clip.load(\"ViT-B/16\", device=device)\n",
"\n",
"search_tokens = clip.tokenize([f\"a photo of bread\"]).to(device)\n",
"search_tokens = clip.tokenize([f\"a photo of bread on plate\"]).to(device)\n",
"search_embeddings = model.encode_text(search_tokens)\n",
"\n",
"query = [{\n",
" \"FindDescriptor\": {\n",
" \"set\": \"ViT-B/16\", # Name of descriptor set to use\n",
" \"k_neighbors\": 5, # How many results to return\n",
" \"k_neighbors\": 10, # How many results to return\n",
" \"distances\": True, # Also return distances (as _distance property)\n",
" \"blobs\": False, # Don't return vectors of matching descriptors\n",
" \"_ref\": 1 # forward reference\n",
" \"_ref\": 1, # forward reference,\n",
" \"metric\": \"CS\",\n",
" \"results\": {\n",
" \"list\": [\"_uniqueid\"]\n",
" }\n",
" }\n",
"}, {\n",
" \"FindImage\": {\n",
Expand All @@ -332,7 +329,8 @@
" \"ref\": 1 # backward reference\n",
" },\n",
" \"results\": {\n",
" \"all_properties\": True # Return all properties\n",
" \"list\": [\"_uniqueid\"], # Return all properties\n",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
" \"list\": [\"_uniqueid\"], # Return all properties\n",
" \"list\": [\"_uniqueid\"], # Return only unique ids\n",

" \"group_by_source\": True\n",
" }\n",
" }\n",
"}]\n",
Expand All @@ -351,7 +349,14 @@
"\n",
"# Check if the query was successful\n",
"if result == 0:\n",
" display(blobs)\n"
" #Here we reorder the images based on the distances before displaying them\n",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
" #Here we reorder the images based on the distances before displaying them\n",
" # Here we reorder the images based on the distances before displaying them\n",

" # based on decreasing distance from the input vector.\n",
" descriptors = response[0][\"FindDescriptor\"][\"entities\"]\n",
" images = response[1][\"FindImage\"][\"entities\"]\n",
" for d in descriptors:\n",
" bi = images[d[\"_uniqueid\"]][0][\"_blob_index\"]\n",
" display(d[\"_distance\"], bi)\n",
" nbd([blobs[bi]])\n"
]
},
{
Expand Down