Datasets:
Update README with LanceDB examples
Browse files
README.md
CHANGED
|
@@ -57,6 +57,18 @@ ds = lance.dataset("hf://datasets/lance-format/ade20k-lance/data/validation.lanc
|
|
| 57 |
print(ds.count_rows(), ds.schema.names, ds.list_indices())
|
| 58 |
```
|
| 59 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
## Read an image with its segmentation
|
| 61 |
|
| 62 |
```python
|
|
@@ -87,6 +99,23 @@ rows = ds.scanner(
|
|
| 87 |
).to_table().to_pylist()
|
| 88 |
```
|
| 89 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
## Visual similarity search
|
| 91 |
|
| 92 |
```python
|
|
@@ -104,6 +133,26 @@ neighbors = ds.scanner(
|
|
| 104 |
).to_table().to_pylist()
|
| 105 |
```
|
| 106 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
## Why Lance?
|
| 108 |
|
| 109 |
- One dataset for images + segmentation + instance + scene + objects + embeddings + indices — no folder of paired files.
|
|
|
|
| 57 |
print(ds.count_rows(), ds.schema.names, ds.list_indices())
|
| 58 |
```
|
| 59 |
|
| 60 |
+
## Load with LanceDB
|
| 61 |
+
|
| 62 |
+
These tables can also be consumed by [LanceDB](https://lancedb.github.io/lancedb/), the serverless vector database built on Lance, for simplified vector search and other queries.
|
| 63 |
+
|
| 64 |
+
```python
|
| 65 |
+
import lancedb
|
| 66 |
+
|
| 67 |
+
db = lancedb.connect("hf://datasets/lance-format/ade20k-lance/data")
|
| 68 |
+
tbl = db.open_table("validation")
|
| 69 |
+
print(f"LanceDB table opened with {len(tbl)} scene images")
|
| 70 |
+
```
|
| 71 |
+
|
| 72 |
## Read an image with its segmentation
|
| 73 |
|
| 74 |
```python
|
|
|
|
| 99 |
).to_table().to_pylist()
|
| 100 |
```
|
| 101 |
|
| 102 |
+
### Filter with LanceDB
|
| 103 |
+
|
| 104 |
+
```python
|
| 105 |
+
import lancedb
|
| 106 |
+
|
| 107 |
+
db = lancedb.connect("hf://datasets/lance-format/ade20k-lance/data")
|
| 108 |
+
tbl = db.open_table("validation")
|
| 109 |
+
|
| 110 |
+
rows = (
|
| 111 |
+
tbl.search()
|
| 112 |
+
.where("array_has_all(objects_present, ['bed', 'window'])")
|
| 113 |
+
.select(["filename", "scene"])
|
| 114 |
+
.limit(10)
|
| 115 |
+
.to_list()
|
| 116 |
+
)
|
| 117 |
+
```
|
| 118 |
+
|
| 119 |
## Visual similarity search
|
| 120 |
|
| 121 |
```python
|
|
|
|
| 133 |
).to_table().to_pylist()
|
| 134 |
```
|
| 135 |
|
| 136 |
+
### LanceDB visual similarity search
|
| 137 |
+
|
| 138 |
+
```python
|
| 139 |
+
import lancedb
|
| 140 |
+
|
| 141 |
+
db = lancedb.connect("hf://datasets/lance-format/ade20k-lance/data")
|
| 142 |
+
tbl = db.open_table("validation")
|
| 143 |
+
|
| 144 |
+
ref = tbl.search().limit(1).select(["image_emb"]).to_list()[0]
|
| 145 |
+
query_embedding = ref["image_emb"]
|
| 146 |
+
|
| 147 |
+
results = (
|
| 148 |
+
tbl.search(query_embedding)
|
| 149 |
+
.metric("cosine")
|
| 150 |
+
.select(["filename", "scene"])
|
| 151 |
+
.limit(5)
|
| 152 |
+
.to_list()
|
| 153 |
+
)
|
| 154 |
+
```
|
| 155 |
+
|
| 156 |
## Why Lance?
|
| 157 |
|
| 158 |
- One dataset for images + segmentation + instance + scene + objects + embeddings + indices — no folder of paired files.
|