id int64 0 48.4k | image imagewidth (px) 72 640 | image_id int64 9 241k | width int32 72 640 | height int32 51 640 | bboxes listlengths 1 93 | categories listlengths 1 93 | category_names listlengths 1 93 | areas listlengths 1 93 | num_objects int32 1 93 | categories_present listlengths 1 16 | image_emb list |
|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 9 | 640 | 480 | [
[
1.0800000429153442,
187.69000244140625,
612.6699829101562,
473.5299987792969
],
[
311.7300109863281,
4.309999942779541,
631.010009765625,
232.99000549316406
],
[
249.60000610351562,
229.27000427246094,
565.8400268554688,
474.3500061035156
],
[
0,
... | [
45,
45,
50,
45,
49,
49,
49,
49
] | [
"bowl",
"bowl",
"broccoli",
"bowl",
"orange",
"orange",
"orange",
"orange"
] | [
120057.140625,
44434.75,
49577.9453125,
24292.78125,
2239.29248046875,
1658.891357421875,
3609.302978515625,
2975.27587890625
] | 8 | [
"bowl",
"broccoli",
"orange"
] | [
-0.0625,
0.140869140625,
0.0208282470703125,
0.038116455078125,
-0.03326416015625,
-0.004444122314453125,
-0.017120361328125,
0.006313323974609375,
0.01480865478515625,
0.0023288726806640625,
-0.04595947265625,
-0.0273895263671875,
-0.05126953125,
0.00803375244140625,
-0.0155792236328125... | |
1 | 25 | 640 | 426 | [
[
385.5299987792969,
60.029998779296875,
600.5,
357.19000244140625
],
[
53.0099983215332,
356.489990234375,
185.0399932861328,
411.67999267578125
]
] | [
23,
23
] | [
"giraffe",
"giraffe"
] | [
19686.59765625,
2785.84765625
] | 2 | [
"giraffe"
] | [
-0.01213836669921875,
0.156982421875,
-0.09014892578125,
-0.0345458984375,
-0.007358551025390625,
0.00923919677734375,
0.0170440673828125,
0.0006351470947265625,
0.0462646484375,
0.061248779296875,
0.040985107421875,
0.01438140869140625,
0.037506103515625,
-0.029510498046875,
0.054534912... | |
2 | 30 | 640 | 428 | [
[
204.86000061035156,
31.020000457763672,
459.739990234375,
355.1400146484375
],
[
237.55999755859375,
155.80999755859375,
403.9599914550781,
351.05999755859375
]
] | [
58,
75
] | [
"potted plant",
"vase"
] | [
47675.6640625,
16202.7978515625
] | 2 | [
"potted plant",
"vase"
] | [
0.06976318359375,
0.20068359375,
-0.0919189453125,
0.0096435546875,
0.01235198974609375,
0.010009765625,
0.0338134765625,
0.0179443359375,
0.03485107421875,
0.0506591796875,
-0.0048675537109375,
-0.026123046875,
0.028289794921875,
0.06744384765625,
-0.059417724609375,
-0.01988220214843... | |
3 | 34 | 640 | 425 | [
[
0.9599999785423279,
20.059999465942383,
442.19000244140625,
399.2099914550781
]
] | [
22
] | [
"zebra"
] | [
92920.15625
] | 1 | [
"zebra"
] | [
-0.020660400390625,
0.1651611328125,
-0.12152099609375,
-0.0240478515625,
-0.037994384765625,
0.0120849609375,
0.035369873046875,
0.0246124267578125,
0.0239410400390625,
0.07373046875,
0.01512908935546875,
0.0229339599609375,
0.042755126953125,
-0.041412353515625,
0.01010894775390625,
... | |
4 | 36 | 481 | 640 | [
[
0,
50.119998931884766,
457.67999267578125,
480.4700012207031
],
[
167.5800018310547,
162.88999938964844,
478.19000244140625,
628.0800170898438
]
] | [
25,
0
] | [
"umbrella",
"person"
] | [
97486.8046875,
86145.296875
] | 2 | [
"person",
"umbrella"
] | [
0.0750732421875,
0.142578125,
-0.084228515625,
-0.1041259765625,
0.006244659423828125,
-0.0098114013671875,
0.055206298828125,
0.01483917236328125,
-0.033538818359375,
0.056182861328125,
-0.005413055419921875,
-0.048370361328125,
0.00604248046875,
-0.0645751953125,
-0.023284912109375,
... | |
5 | 42 | 640 | 478 | [
[
214.14999389648438,
41.290000915527344,
562.4099731445312,
285.07000732421875
]
] | [
16
] | [
"dog"
] | [
53481.51171875
] | 1 | [
"dog"
] | [
-0.00536346435546875,
0.0252838134765625,
0.01306915283203125,
-0.056793212890625,
0.03521728515625,
-0.01751708984375,
0.06732177734375,
0.047515869140625,
0.01096343994140625,
0.0297088623046875,
-0.016510009765625,
-0.0297698974609375,
0.0111083984375,
0.024810791015625,
0.00377082824... | |
6 | 49 | 381 | 500 | [
[
162.57000732421875,
226.55999755859375,
292.9800109863281,
410.989990234375
],
[
81.69999694824219,
244.94000244140625,
165.41000366210938,
403.1400146484375
],
[
203.38999938964844,
260.42999267578125,
269.0799865722656,
333.4700012207031
],
[
118.4... | [
17,
17,
0,
0,
0,
58,
0,
0,
0
] | [
"horse",
"horse",
"person",
"person",
"person",
"potted plant",
"person",
"person",
"person"
] | [
8451.2236328125,
5295.95751953125,
1754.8175048828125,
1349.9822998046875,
250.8199005126953,
2736.25537109375,
162.90005493164062,
90.16190338134766,
83.6895523071289
] | 9 | [
"horse",
"person",
"potted plant"
] | [
0.0192718505859375,
0.10101318359375,
-0.10467529296875,
0.037811279296875,
-0.0164947509765625,
0.01120758056640625,
0.02490234375,
0.03961181640625,
-0.00257110595703125,
0.0596923828125,
-0.05029296875,
0.019927978515625,
0.052947998046875,
0.00002658367156982422,
-0.045166015625,
-... | |
7 | 61 | 640 | 488 | [
[
261.20001220703125,
205.9199981689453,
309.2799987792969,
263.1600036621094
],
[
393.3900146484375,
210.33999633789062,
425.9200134277344,
250.0800018310547
],
[
370.1099853515625,
248.89999389648438,
453.20001220703125,
296.5400085449219
],
[
223.25... | [
0,
0,
20,
20,
0
] | [
"person",
"person",
"elephant",
"elephant",
"person"
] | [
914.361328125,
531.7515258789062,
3086.66357421875,
5214.435546875,
546.5148315429688
] | 5 | [
"elephant",
"person"
] | [
-0.03564453125,
0.04083251953125,
-0.07196044921875,
0.09808349609375,
0.031707763671875,
-0.0285797119140625,
0.0011758804321289062,
-0.01483154296875,
0.043670654296875,
-0.0211944580078125,
-0.021392822265625,
-0.0184173583984375,
0.0096282958984375,
0.0210723876953125,
-0.01216125488... | |
8 | 64 | 480 | 640 | [
[
52.36000061035156,
387.7699890136719,
228.72000122070312,
545.3900146484375
],
[
52.63999938964844,
353.7799987792969,
177.22000122070312,
413.25
],
[
115.83999633789062,
226.58999633789062,
152.86000061035156,
301.760009765625
],
[
112.0400009155273... | [
2,
7,
11,
74
] | [
"car",
"truck",
"stop sign",
"clock"
] | [
15185.1796875,
3406.182373046875,
2151.35400390625,
17624.40234375
] | 4 | [
"car",
"clock",
"stop sign",
"truck"
] | [
0.0765380859375,
0.0877685546875,
-0.062286376953125,
0.048797607421875,
-0.006053924560546875,
-0.0218353271484375,
-0.022735595703125,
0.032440185546875,
-0.0037631988525390625,
0.0164337158203125,
0.041229248046875,
0.0252532958984375,
-0.0214080810546875,
0.040435791015625,
0.0402526... | |
9 | 71 | 640 | 426 | [
[
467.82000732421875,
216.92999267578125,
495.57000732421875,
231.0800018310547
],
[
522.6900024414062,
223.39999389648438,
547.0399780273438,
235.39999389648438
],
[
436.8999938964844,
217.8300018310547,
460.2200012207031,
226.4499969482422
],
[
586.3... | [
2,
2,
2,
2,
6,
2,
2,
7,
7,
2,
2,
2,
2,
2,
2,
2
] | [
"car",
"car",
"car",
"car",
"train",
"car",
"car",
"truck",
"truck",
"car",
"car",
"car",
"car",
"car",
"car",
"car"
] | [
161.82940673828125,
205.83944702148438,
141.6260986328125,
274.7764892578125,
19503.666015625,
216.00155639648438,
67.95549774169922,
176.30455017089844,
127.83159637451172,
224.21180725097656,
207.67474365234375,
26.063199996948242,
124.19039916992188,
80.27144622802734,
73.070098876953... | 16 | [
"car",
"train",
"truck"
] | [
0.0015354156494140625,
-0.09783935546875,
-0.10943603515625,
-0.040771484375,
0.002872467041015625,
0.025390625,
-0.005542755126953125,
-0.01178741455078125,
0.05230712890625,
-0.0259857177734375,
-0.01207733154296875,
-0.06463623046875,
0.0184173583984375,
-0.02960205078125,
-0.00386047... | |
10 | 72 | 427 | 640 | [
[
136.6300048828125,
129.44000244140625,
425.7099914550781,
628.489990234375
],
[
50.45000076293945,
72.06999969482422,
283.9599914550781,
640
]
] | [
23,
23
] | [
"giraffe",
"giraffe"
] | [
80168.796875,
41879.1953125
] | 2 | [
"giraffe"
] | [
0.00036835670471191406,
0.1337890625,
-0.06597900390625,
-0.0084228515625,
0.00974273681640625,
-0.0207977294921875,
-0.0005307197570800781,
0.021575927734375,
0.0438232421875,
0.046630859375,
0.01824951171875,
-0.003620147705078125,
0.0208740234375,
-0.05609130859375,
0.035675048828125,... | |
11 | 73 | 565 | 640 | [
[
13,
22.75,
548.97998046875,
632.4199829101562
],
[
1.659999966621399,
3.319999933242798,
270.260009765625,
275.2300109863281
]
] | [
3,
3
] | [
"motorcycle",
"motorcycle"
] | [
172022.4375,
52666.33984375
] | 2 | [
"motorcycle"
] | [
0.00977325439453125,
0.04150390625,
-0.044158935546875,
-0.0177764892578125,
0.049224853515625,
-0.01885986328125,
-0.01343536376953125,
0.03460693359375,
0.0312042236328125,
0.043975830078125,
-0.009552001953125,
0.0411376953125,
0.042236328125,
-0.02508544921875,
0.003978729248046875,
... | |
12 | 74 | 640 | 426 | [
[
61.869998931884766,
276.25,
358.2900085449219,
379.42999267578125
],
[
2.75,
3.6600000858306885,
162.14999389648438,
316.05999755859375
],
[
295.54998779296875,
93.95999908447266,
313.9700012207031,
152.7899932861328
],
[
326.94000244140625,
97.0... | [
16,
1,
0,
0,
0,
0,
0,
0
] | [
"dog",
"bicycle",
"person",
"person",
"person",
"person",
"person",
"person"
] | [
18234.623046875,
30078.494140625,
638.7158203125,
180.86094665527344,
562.1028442382812,
758.616943359375,
319.6597900390625,
131.11439514160156
] | 8 | [
"bicycle",
"dog",
"person"
] | [
0.0108642578125,
0.1646728515625,
-0.1318359375,
0.032867431640625,
0.00041413307189941406,
0.052825927734375,
-0.012115478515625,
0.006000518798828125,
-0.033294677734375,
0.0201568603515625,
0.06805419921875,
-0.0239105224609375,
-0.023712158203125,
-0.046539306640625,
0.03994750976562... | |
13 | 77 | 500 | 375 | [
[
216.0399932861328,
56.310001373291016,
319.489990234375,
175.24000549316406
],
[
320.7300109863281,
53.72999954223633,
415.3599853515625,
151.00999450683594
],
[
41.54999923706055,
320.3399963378906,
92.08999633789062,
344.5799865722656
],
[
236.6300... | [
0,
0,
36,
36,
0,
0,
36,
0
] | [
"person",
"person",
"skateboard",
"skateboard",
"person",
"person",
"skateboard",
"person"
] | [
3733.542724609375,
2735.84375,
379.45733642578125,
174.3225555419922,
8154.572265625,
631.9514770507812,
151.0251007080078,
656.7854614257812
] | 8 | [
"person",
"skateboard"
] | [
-0.036102294921875,
0.052703857421875,
-0.0947265625,
0.10980224609375,
0.004505157470703125,
0.0135040283203125,
0.033233642578125,
-0.031707763671875,
-0.02728271484375,
-0.0384521484375,
0.0266876220703125,
-0.0164337158203125,
-0.0012912750244140625,
-0.0263824462890625,
-0.012580871... | |
14 | 78 | 612 | 612 | [
[
359.79998779296875,
2.069999933242798,
573.9299926757812,
237.97999572753906
]
] | [
74
] | [
"clock"
] | [
36828.0625
] | 1 | [
"clock"
] | [
0.03204345703125,
0.254150390625,
-0.06005859375,
0.06951904296875,
0.0012073516845703125,
0.044097900390625,
-0.021453857421875,
-0.01515960693359375,
0.01009368896484375,
0.06475830078125,
-0.00560760498046875,
0.00894927978515625,
-0.03094482421875,
-0.0035552978515625,
0.012886047363... | |
15 | 81 | 640 | 425 | [
[
38.54999923706055,
40.47999954223633,
622.5599975585938,
358.5
]
] | [
4
] | [
"airplane"
] | [
65010.4375
] | 1 | [
"airplane"
] | [
-0.0606689453125,
-0.20654296875,
-0.07769775390625,
-0.01329803466796875,
-0.036712646484375,
-0.0499267578125,
-0.05926513671875,
-0.01336669921875,
-0.0255889892578125,
0.047515869140625,
-0.046142578125,
-0.0257720947265625,
-0.004291534423828125,
0.052581787109375,
0.047943115234375... | |
16 | 86 | 512 | 640 | [
[
152.11000061035156,
183.10000610351562,
281.260009765625,
559.0700073242188
],
[
130.13999938964844,
346.5199890136719,
424.3999938964844,
635.1599731445312
],
[
265.1000061035156,
294.5899963378906,
399.70001220703125,
404.7699890136719
]
] | [
0,
3,
26
] | [
"person",
"motorcycle",
"handbag"
] | [
24441.5703125,
43566.796875,
11227.02734375
] | 3 | [
"handbag",
"motorcycle",
"person"
] | [
0.004459381103515625,
0.09893798828125,
-0.092529296875,
0.00650787353515625,
0.056793212890625,
0.01181793212890625,
0.01277923583984375,
-0.032562255859375,
-0.026824951171875,
0.0113677978515625,
-0.04510498046875,
0.036529541015625,
0.04156494140625,
0.0034637451171875,
-0.0254974365... | |
17 | 89 | 640 | 480 | [
[
502.6000061035156,
105.47000122070312,
528.4299926757812,
237.85000610351562
],
[
476.6199951171875,
127.48999786376953,
496.3399963378906,
233.60000610351562
],
[
528.7999877929688,
99.30000305175781,
555.27001953125,
237.19000244140625
],
[
555.669... | [
43,
43,
43,
43,
43,
69,
68,
73,
73,
73
] | [
"knife",
"knife",
"knife",
"knife",
"knife",
"oven",
"microwave",
"book",
"book",
"book"
] | [
2101.468994140625,
1167.2392578125,
2028.3297119140625,
1312.2186279296875,
1422.6409912109375,
77283.171875,
14312.041015625,
1889.6090087890625,
1485.163330078125,
2664.3046875
] | 10 | [
"book",
"knife",
"microwave",
"oven"
] | [
-0.023956298828125,
0.034332275390625,
0.035430908203125,
0.035980224609375,
-0.0305938720703125,
-0.01629638671875,
-0.046539306640625,
-0.0011606216430664062,
0.01261138916015625,
0.031494140625,
-0.0116119384765625,
-0.0216064453125,
0.013214111328125,
-0.057525634765625,
0.0108489990... | |
18 | 92 | 640 | 427 | [
[
418.6499938964844,
118.5999984741211,
583.3300170898438,
427
],
[
125.69999694824219,
0.9599999785423279,
501.8399963378906,
293.6199951171875
]
] | [
42,
55
] | [
"fork",
"cake"
] | [
10475.5849609375,
80095.6796875
] | 2 | [
"cake",
"fork"
] | [
0.055908203125,
0.1746826171875,
0.0030002593994140625,
0.06121826171875,
-0.0036773681640625,
-0.041351318359375,
0.0030117034912109375,
-0.01971435546875,
-0.009246826171875,
0.0284271240234375,
-0.02532958984375,
0.027801513671875,
-0.0167236328125,
0.038330078125,
0.035186767578125,
... |
YAML Metadata Warning:The task_categories "lance" is not in the official list: text-classification, token-classification, table-question-answering, question-answering, zero-shot-classification, translation, summarization, feature-extraction, text-generation, fill-mask, sentence-similarity, text-to-speech, text-to-audio, automatic-speech-recognition, audio-to-audio, audio-classification, audio-text-to-text, voice-activity-detection, depth-estimation, image-classification, object-detection, image-segmentation, text-to-image, image-to-text, image-to-image, image-to-video, unconditional-image-generation, video-classification, reinforcement-learning, robotics, tabular-classification, tabular-regression, tabular-to-text, table-to-text, multiple-choice, text-ranking, text-retrieval, time-series-forecasting, text-to-video, image-text-to-text, image-text-to-image, image-text-to-video, visual-question-answering, document-question-answering, zero-shot-image-classification, graph-ml, mask-generation, zero-shot-object-detection, text-to-3d, image-to-3d, image-feature-extraction, video-text-to-text, keypoint-detection, visual-document-retrieval, any-to-any, video-to-video, other
COCO 2017 Object Detection (Lance Format)
A Lance-formatted version of the COCO 2017 object detection benchmark, sourced from detection-datasets/coco. Each row is one image with its inline JPEG bytes, the full per-image list of bounding boxes, COCO 80-class category ids and names, per-object areas, an OpenCLIP image embedding, and pre-built indices — all available directly from the Hub at hf://datasets/lance-format/coco-detection-2017-lance/data.
Key features
- Inline JPEG bytes in the
imagecolumn — no sidecar files, no image folders. - Per-object annotations as parallel list columns —
bboxes,categories,category_names, andareasare aligned position-for-position, so iterating boxes alongside their labels is a single row read. - Pre-aggregated annotation summaries —
num_objects(int) andcategories_present(deduped string list) precompute the predicates curation queries hit most. - CLIP image embeddings (
image_emb, OpenCLIP ViT-B/32, 512-d, cosine-normalized) with a bundledIVF_PQindex for visual retrieval.
Splits
| Split | Rows |
|---|---|
train.lance |
117,000+ |
val.lance |
4,950+ |
Total annotated boxes: ~860k train / ~37k val.
Schema
| Column | Type | Notes |
|---|---|---|
id |
int64 |
Row index within split |
image |
large_binary |
Inline JPEG bytes |
image_id |
int64 |
COCO image id (natural join key) |
width, height |
int32 |
Image dimensions in pixels |
bboxes |
list<list<float32, 4>> |
Each box is [x_min, y_min, x_max, y_max] in absolute pixel coordinates |
categories |
list<int32> |
COCO 80-class id (0–79), aligned with bboxes |
category_names |
list<string> |
Human-readable class name per object (e.g. person, dog) |
areas |
list<float32> |
Bounding-box area in pixels², aligned with bboxes |
num_objects |
int32 |
Number of annotated objects in the image |
categories_present |
list<string> |
Deduped class names — feeds the LABEL_LIST index |
image_emb |
fixed_size_list<float32, 512> |
OpenCLIP ViT-B/32 image embedding (cosine-normalized) |
Pre-built indices
IVF_PQonimage_emb— vector similarity search (cosine)BTREEonimage_id— fast lookup by COCO image idBTREEonnum_objects— range filters on image complexityLABEL_LISToncategories_present— supportsarray_has_any/array_has_allfor class-presence filtering
Why Lance?
- Blazing Fast Random Access: Optimized for fetching scattered rows, making it ideal for random sampling, real-time ML serving, and interactive applications without performance degradation.
- Native Multimodal Support: Store text, embeddings, and other data types together in a single file. Large binary objects are loaded lazily, and vectors are optimized for fast similarity search.
- Native Index Support: Lance comes with fast, on-disk, scalable vector and FTS indexes that sit right alongside the dataset on the Hub, so you can share not only your data but also your embeddings and indexes without your users needing to recompute them.
- Efficient Data Evolution: Add new columns and backfill data without rewriting the entire dataset. This is perfect for evolving ML features, adding new embeddings, or introducing moderation tags over time.
- Versatile Querying: Supports combining vector similarity search, full-text search, and SQL-style filtering in a single query, accelerated by on-disk indexes.
- Data Versioning: Every mutation commits a new version; previous versions remain intact on disk. Tags pin a snapshot by name, so retrieval systems and training runs can reproduce against an exact slice of history.
Load with datasets.load_dataset
You can load Lance datasets via the standard HuggingFace datasets interface, suitable when your pipeline already speaks Dataset / IterableDataset or you want a quick streaming sample without installing anything Lance-specific.
import datasets
hf_ds = datasets.load_dataset("lance-format/coco-detection-2017-lance", split="val", streaming=True)
for row in hf_ds.take(3):
print(row["image_id"], row["num_objects"], row["categories_present"][:5])
Load with LanceDB
LanceDB is the embedded retrieval library built on top of the Lance format (docs), and is the interface most users interact with. It wraps the dataset as a queryable table with search and filter builders, and is the entry point used by the Search, Curate, Evolve, Versioning, and Materialize-a-subset sections below.
import lancedb
db = lancedb.connect("hf://datasets/lance-format/coco-detection-2017-lance/data")
tbl = db.open_table("val")
print(len(tbl))
Load with Lance
pylance is the Python binding for the Lance format and works directly with the format's lower-level APIs. Reach for it when you want to inspect dataset internals — schema, scanner, fragments, the list of pre-built indices.
import lance
ds = lance.dataset("hf://datasets/lance-format/coco-detection-2017-lance/data/val.lance")
print(ds.count_rows(), ds.schema.names)
print(ds.list_indices())
Tip — for production use, download locally first. Streaming from the Hub works for exploration, but heavy random access, ANN search, and any mutation are far faster against a local copy:
hf download lance-format/coco-detection-2017-lance --repo-type dataset --local-dir ./coco-detection-2017-lanceThen point Lance or LanceDB at
./coco-detection-2017-lance/data.
Search
The bundled IVF_PQ index on image_emb makes approximate-nearest-neighbor visual retrieval a single call. In production you would encode a query image through the same OpenCLIP ViT-B/32 model used at ingest and pass the resulting 512-d vector to tbl.search(...). The example below uses the embedding stored on row 42 as a runnable stand-in, so the snippet works without loading any model.
import lancedb
db = lancedb.connect("hf://datasets/lance-format/coco-detection-2017-lance/data")
tbl = db.open_table("val")
seed = (
tbl.search()
.select(["image_emb", "image_id", "categories_present"])
.limit(1)
.offset(42)
.to_list()[0]
)
hits = (
tbl.search(seed["image_emb"])
.metric("cosine")
.select(["image_id", "categories_present", "num_objects"])
.limit(10)
.to_list()
)
print("query categories:", seed["categories_present"])
for r in hits:
print(f" image_id={r['image_id']:>10} n={r['num_objects']:>3} cats={r['categories_present'][:5]}")
Because the embeddings are cosine-normalized, the first hit will typically be the source image itself — a useful sanity check. Tune nprobes and refine_factor to trade recall against latency for your workload.
Curate
Curation for a detection workflow usually means picking images that contain a specific class combination, possibly bounded by scene complexity. The LABEL_LIST index on categories_present makes class-presence predicates trivial, and Lance evaluates them inside the same scan as range filters on num_objects or width/height. The bounded .limit(500) keeps the result small and inspectable, and the image column is left out of the projection so the candidate scan is dominated by annotation metadata, not JPEG bytes.
import lancedb
db = lancedb.connect("hf://datasets/lance-format/coco-detection-2017-lance/data")
tbl = db.open_table("val")
candidates = (
tbl.search()
.where(
"array_has_all(categories_present, ['person', 'frisbee']) "
"AND num_objects BETWEEN 3 AND 12",
prefilter=True,
)
.select(["image_id", "categories_present", "num_objects", "width", "height"])
.limit(500)
.to_list()
)
print(f"{len(candidates)} candidates; first image_id: {candidates[0]['image_id']}")
The result is a plain list of dictionaries, ready to inspect, persist as a manifest of image_ids, or feed into the Evolve and Train workflows below. Swapping array_has_all for array_has_any widens recall to images containing any of the listed classes; replacing the structural predicate with num_objects >= 10 selects busy scenes for crowd-detection ablations.
Evolve
Lance stores each column independently, so a new column can be appended without rewriting the existing data. The lightest form is a SQL expression: derive the new column from columns that already exist, and Lance computes it once and persists it. The example below adds a has_person flag, an aspect_ratio, and a max_box_area that surfaces the largest annotated object area per image — all of which can then be used directly in where clauses without recomputing the predicate on every query.
Note: Mutations require a local copy of the dataset, since the Hub mount is read-only. See the Materialize-a-subset section at the end of this card for a streaming pattern that downloads only the rows and columns you need, or use
hf downloadto pull the full split first.
import lancedb
db = lancedb.connect("./coco-detection-2017-lance/data") # local copy required for writes
tbl = db.open_table("val")
tbl.add_columns({
"has_person": "array_has_any(categories_present, ['person'])",
"aspect_ratio": "CAST(width AS DOUBLE) / CAST(height AS DOUBLE)",
"max_box_area": "array_max(areas)",
"crowded": "num_objects >= 10",
})
If the values you want to attach already live in another table (offline predictions from a baseline detector, per-image difficulty scores, or a second-pass embedding), merge them in by joining on image_id:
import pyarrow as pa
predictions = pa.table({
"image_id": pa.array([397133, 37777, 252219], type=pa.int64()),
"baseline_map": pa.array([0.31, 0.48, 0.22]),
})
tbl.merge(predictions, on="image_id")
The original columns and indices are untouched, so existing code that does not reference the new columns continues to work unchanged. New columns become visible to every reader as soon as the operation commits. For column values that require a Python computation (e.g., running a second detector over the image bytes), Lance provides a batch-UDF API — see the Lance data evolution docs.
Train
Projection lets a training loop read only the columns each step actually needs. LanceDB tables expose this through Permutation.identity(tbl).select_columns([...]), which plugs straight into the standard torch.utils.data.DataLoader so prefetching, shuffling, and batching behave as in any PyTorch pipeline. For a detector training run, project the JPEG bytes alongside the parallel annotation columns the loss consumes — boxes, category ids, and (optionally) areas. Columns added in the Evolve section above cost nothing per batch until they are explicitly projected.
import lancedb
from lancedb.permutation import Permutation
from torch.utils.data import DataLoader
db = lancedb.connect("hf://datasets/lance-format/coco-detection-2017-lance/data")
tbl = db.open_table("train")
train_ds = Permutation.identity(tbl).select_columns(
["image", "bboxes", "categories", "areas"]
)
loader = DataLoader(train_ds, batch_size=16, shuffle=True, num_workers=4,
collate_fn=lambda b: b) # detection targets are ragged
for batch in loader:
# batch is a list of dicts: decode each JPEG, stack the bboxes / categories
# into the target dictionary your detector expects, forward, loss...
...
Switching feature sets is a configuration change: passing ["image_emb", "categories_present"] to select_columns(...) on the next run skips JPEG decoding entirely and reads only the cached 512-d vectors plus the deduped class list, which is the right shape for training a lightweight multi-label classifier or a class-presence probe on top of frozen features.
Versioning
Every mutation to a Lance dataset, whether it adds a column, merges labels, or builds an index, commits a new version. Previous versions remain intact on disk. You can list versions and inspect the history directly from the Hub copy; creating new tags requires a local copy since tags are writes.
import lancedb
db = lancedb.connect("hf://datasets/lance-format/coco-detection-2017-lance/data")
tbl = db.open_table("val")
print("Current version:", tbl.version)
print("History:", tbl.list_versions())
print("Tags:", tbl.tags.list())
Once you have a local copy, tag a version for reproducibility:
local_db = lancedb.connect("./coco-detection-2017-lance/data")
local_tbl = local_db.open_table("val")
local_tbl.tags.create("detector-baseline-v1", local_tbl.version)
A tagged version can be opened by name, or any version reopened by its number, against either the Hub copy or a local one:
tbl_v1 = db.open_table("val", version="detector-baseline-v1")
tbl_v5 = db.open_table("val", version=5)
Pinning supports two workflows. An evaluation harness locked to detector-baseline-v1 keeps scoring against the exact same boxes and category ids while the dataset evolves in parallel; newly merged predictions or evolved columns do not change what the tag resolves to. A training experiment pinned to the same tag can be rerun later against the exact same images and annotations, so changes in mAP reflect model changes rather than data drift. Neither workflow needs shadow copies or external manifest tracking.
Materialize a subset
Reads from the Hub are lazy, so exploratory queries only transfer the columns and row groups they touch. Mutating operations (Evolve, tag creation) need a writable backing store, and a training loop benefits from a local copy with fast random access. Both can be served by a subset of the dataset rather than the full split. The pattern is to stream a filtered query through .to_batches() into a new local table; only the projected columns and matching row groups cross the wire, and the bytes never fully materialize in Python memory.
import lancedb
remote_db = lancedb.connect("hf://datasets/lance-format/coco-detection-2017-lance/data")
remote_tbl = remote_db.open_table("train")
batches = (
remote_tbl.search()
.where("array_has_any(categories_present, ['dog', 'cat']) AND num_objects >= 2")
.select(["image_id", "image", "bboxes", "categories", "category_names",
"areas", "num_objects", "categories_present", "image_emb"])
.to_batches()
)
local_db = lancedb.connect("./coco-pets-subset")
local_db.create_table("train", batches)
The resulting ./coco-pets-subset is a first-class LanceDB database. Every snippet in the Evolve, Train, and Versioning sections above works against it by swapping hf://datasets/lance-format/coco-detection-2017-lance/data for ./coco-pets-subset.
Source & license
Converted from detection-datasets/coco. COCO annotations are released under CC BY 4.0; the underlying images are subject to Flickr terms of service. See the COCO Terms of Use before redistribution.
Citation
@inproceedings{lin2014microsoft,
title={Microsoft COCO: Common objects in context},
author={Lin, Tsung-Yi and Maire, Michael and Belongie, Serge and Hays, James and Perona, Pietro and Ramanan, Deva and Doll{\'a}r, Piotr and Zitnick, C Lawrence},
booktitle={European Conference on Computer Vision (ECCV)},
year={2014}
}
- Downloads last month
- 73