Elffuss BraidHub

kikocis/lancedb public

docs: revamp Voxel51 v1 (#1714)

Revamp Voxel51

![image](https://github.com/user-attachments/assets/7ac34457-74ec-4654-b1d1-556e3d7357f5)
Changesetcdf1aa093b13e3226f7b91bae7dfe369725a1d67f0b435cd7f5683890dc09e74
AuthorRithik Kumar <46047011+rithikJha@users.noreply.github.com> · 2024-10-01 11:59 +05:30
CommitterGitHub <noreply@github.com> · 2024-10-01 11:59 +05:30
Parents9434ba17655a

Browse the files at this changeset

1 file changed

modified docs/src/integrations/voxel51.md +175 −12
@@ -1,13 +1,73 @@
11 # FiftyOne
22
3-FiftyOne is an open source toolkit for building high-quality datasets and computer vision models. It provides an API to create LanceDB tables and run similarity queries, both programmatically in Python and via point-and-click in the App.
3+FiftyOne is an open source toolkit that enables users to curate better data and build better models. It includes tools for data exploration, visualization, and management, as well as features for collaboration and sharing.
4+
5+Any developers, data scientists, and researchers who work with computer vision and machine learning can use FiftyOne to improve the quality of their datasets and deliver insights about their models.
6+
47
58 ![example](../assets/voxel.gif)
69
7-## Basic recipe
10+**FiftyOne** provides an API to create LanceDB tables and run similarity queries, both **programmatically in Python** and via **point-and-click in the App**.
11+
12+Let's get started and see how to use **LanceDB** to create a **similarity index** on your FiftyOne datasets.
13+
14+## Overview
15+
16+**[Embeddings](../embeddings/understanding_embeddings.md)** are foundational to all of the **vector search** features. In FiftyOne, embeddings are managed by the [**FiftyOne Brain**](https://docs.voxel51.com/user_guide/brain.html) that provides powerful machine learning techniques designed to transform how you curate your data from an art into a measurable science.
17+
18+!!!question "Have you ever wanted to find the images most similar to an image in your dataset?"
19+ The **FiftyOne Brain** makes computing **visual similarity** really easy. You can compute the similarity of samples in your dataset using an embedding model and store the results in the **brain key**.
20+
21+ You can then sort your samples by similarity or use this information to find potential duplicate images.
22+
23+Here we will be doing the following :
24+
25+1. **Create Index** - In order to run similarity queries against our media, we need to **index** the data. We can do this via the `compute_similarity()` function.
26+
27+ - In the function, specify the **model** you want to use to generate the embedding vectors, and what **vector search engine** you want to use on the **backend** (here LanceDB).
28+
29+ !!!tip
30+ You can also give the similarity index a name(`brain_key`), which is useful if you want to run vector searches against multiple indexes.
31+
32+2. **Query** - Once you have generated your similarity index, you can query your dataset with `sort_by_similarity()`. The query can be any of the following:
33+
34+ - An ID (sample or patch)
35+ - A query vector of same dimension as the index
36+ - A list of IDs (samples or patches)
37+ - A text prompt (search semantically)
38+
39+## Prerequisites: install necessary dependencies
40+
41+1. **Create and activate a virtual environment**
42+
43+ Install virtualenv package and run the following command in your project directory.
44+ ```python
45+ python -m venv fiftyone_
46+ ```
47+ From inside the project directory run the following to activate the virtual environment.
48+ === "Windows"
49+
50+ ```python
51+ fiftyone_/Scripts/activate
52+ ```
53+
54+ === "macOS/Linux"
55+
56+ ```python
57+ source fiftyone_/Scripts/activate
58+ ```
59+
60+2. **Install the following packages in the virtual environment**
61+
62+ To install FiftyOne, ensure you have activated any virtual environment that you are using, then run
63+ ```python
64+ pip install fiftyone
65+ ```
66+
67+
68+## Understand basic workflow
869
9-The basic workflow shown below uses LanceDB to create a similarity index on your FiftyOne
10-datasets:
70+The basic workflow shown below uses LanceDB to create a similarity index on your FiftyOne datasets:
1171
1272 1. Load a dataset into FiftyOne.
1373
@@ -19,14 +79,10 @@
1979
2080 5. If desired, delete the table.
2181
22-The example below demonstrates this workflow.
82+## Quick Example
2383
24-!!! Note
84+Let's jump on a quick example that demonstrates this workflow.
2585
26- Install the LanceDB Python client to run the code shown below.
27- ```
28- pip install lancedb
29- ```
3086
3187 ```python
3288
@@ -36,7 +92,10 @@
3692
3793 # Step 1: Load your data into FiftyOne
3894 dataset = foz.load_zoo_dataset("quickstart")
95+```
96+Make sure you install torch ([guide here](https://pytorch.org/get-started/locally/)) before proceeding.
3997
98+```python
4099 # Steps 2 and 3: Compute embeddings and create a similarity index
41100 lancedb_index = fob.compute_similarity(
42101 dataset,
@@ -45,8 +104,11 @@
45104 backend="lancedb",
46105 )
47106 ```
48-Once the similarity index has been generated, we can query our data in FiftyOne
49-by specifying the `brain_key`:
107+
108+!!! note
109+ Running the code above will download the clip model (2.6Gb)
110+
111+Once the similarity index has been generated, we can query our data in FiftyOne by specifying the `brain_key`:
50112
51113 ```python
52114 # Step 4: Query your data
@@ -56,7 +118,22 @@
56118 brain_key="lancedb_index",
57119 k=10, # limit to 10 most similar samples
58120 )
121+```
122+The returned result are of type - `DatasetView`.
123+
124+!!! note
125+ `DatasetView` does not hold its contents in-memory. Views simply store the rule(s) that are applied to extract the content of interest from the underlying Dataset when the view is iterated/aggregated on.
59126
127+ This means, for example, that the contents of a `DatasetView` may change as the underlying Dataset is modified.
128+
129+??? question "Can you query a view instead of dataset?"
130+ Yes, you can also query a view.
131+
132+ Performing a similarity search on a `DatasetView` will only return results from the view; if the view contains samples that were not included in the index, they will never be included in the result.
133+
134+ This means that you can index an entire Dataset once and then perform searches on subsets of the dataset by constructing views that contain the images of interest.
135+
136+```python
60137 # Step 5 (optional): Cleanup
61138
62139 # Delete the LanceDB table
@@ -66,4 +143,90 @@
66143 dataset.delete_brain_run("lancedb_index")
67144 ```
68145
146+
147+## Using LanceDB backend
148+By default, calling `compute_similarity()` or `sort_by_similarity()` will use an sklearn backend.
149+
150+To use the LanceDB backend, simply set the optional `backend` parameter of `compute_similarity()` to `"lancedb"`:
151+
152+```python
153+import fiftyone.brain as fob
154+#... rest of the code
155+fob.compute_similarity(..., backend="lancedb", ...)
156+```
157+
158+Alternatively, you can configure FiftyOne to use the LanceDB backend by setting the following environment variable.
159+
160+In your terminal, set the environment variable using:
161+=== "Windows"
162+
163+ ```python
164+ $Env:FIFTYONE_BRAIN_DEFAULT_SIMILARITY_BACKEND="lancedb" //powershell
165+
166+ set FIFTYONE_BRAIN_DEFAULT_SIMILARITY_BACKEND=lancedb //cmd
167+ ```
168+
169+=== "macOS/Linux"
170+
171+ ```python
172+ export FIFTYONE_BRAIN_DEFAULT_SIMILARITY_BACKEND=lancedb
173+ ```
174+
175+!!! note
176+ This will only run during the terminal session. Once terminal is closed, environment variable is deleted.
177+
178+Alternatively, you can **permanently** configure FiftyOne to use the LanceDB backend creating a `brain_config.json` at `~/.fiftyone/brain_config.json`. The JSON file may contain any desired subset of config fields that you wish to customize.
179+
180+```json
181+{
182+ "default_similarity_backend": "lancedb"
183+}
184+```
185+This will override the default `brain_config` and will set it according to your customization. You can check the configuration by running the following code :
186+
187+```python
188+import fiftyone.brain as fob
189+# Print your current brain config
190+print(fob.brain_config)
191+```
192+
193+## LanceDB config parameters
194+
195+The LanceDB backend supports query parameters that can be used to customize your similarity queries. These parameters include:
196+
197+| Name| Purpose | Default |
198+|:----|:--------|:--------|
199+|**table_name**|The name of the LanceDB table to use. If none is provided, a new table will be created|`None`|
200+|**metric**|The embedding distance metric to use when creating a new table. The supported values are ("cosine", "euclidean")|`"cosine"`|
201+|**uri**| The database URI to use. In this Database URI, tables will be created. |`"/tmp/lancedb"`|
202+
203+There are two ways to specify/customize the parameters:
204+
205+1. **Using `brain_config.json` file**
206+
207+ ```json
208+ {
209+ "similarity_backends": {
210+ "lancedb": {
211+ "table_name": "your-table",
212+ "metric": "euclidean",
213+ "uri": "/tmp/lancedb"
214+ }
215+ }
216+ }
217+ ```
218+
219+2. **Directly passing to `compute_similarity()` to configure a specific new index** :
220+
221+ ```python
222+ lancedb_index = fob.compute_similarity(
223+ ...
224+ backend="lancedb",
225+ brain_key="lancedb_index",
226+ table_name="your-table",
227+ metric="euclidean",
228+ uri="/tmp/lancedb",
229+ )
230+ ```
231+
69232 For a much more in depth walkthrough of the integration, visit the LanceDB x Voxel51 [docs page](https://docs.voxel51.com/integrations/lancedb.html).