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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
---
dataset_info:
  features:
  - name: id
    dtype: string
  - name: image
    dtype: image
  - name: width
    dtype: int32
  - name: height
    dtype: int32
  - name: boxes
    list:
      list: float32
      length: 4
  - name: labels
    list:
      class_label:
        names:
          '0': __background__
          '1': airplane
          '2': animal
          '3': arm
          '4': bag
          '5': banana
          '6': basket
          '7': beach
          '8': bear
          '9': bed
          '10': bench
          '11': bike
          '12': bird
          '13': board
          '14': boat
          '15': book
          '16': boot
          '17': bottle
          '18': bowl
          '19': box
          '20': boy
          '21': branch
          '22': building
          '23': bus
          '24': cabinet
          '25': cap
          '26': car
          '27': cat
          '28': chair
          '29': child
          '30': clock
          '31': coat
          '32': counter
          '33': cow
          '34': cup
          '35': curtain
          '36': desk
          '37': dog
          '38': door
          '39': drawer
          '40': ear
          '41': elephant
          '42': engine
          '43': eye
          '44': face
          '45': fence
          '46': finger
          '47': flag
          '48': flower
          '49': food
          '50': fork
          '51': fruit
          '52': giraffe
          '53': girl
          '54': glass
          '55': glove
          '56': guy
          '57': hair
          '58': hand
          '59': handle
          '60': hat
          '61': head
          '62': helmet
          '63': hill
          '64': horse
          '65': house
          '66': jacket
          '67': jean
          '68': kid
          '69': kite
          '70': lady
          '71': lamp
          '72': laptop
          '73': leaf
          '74': leg
          '75': letter
          '76': light
          '77': logo
          '78': man
          '79': men
          '80': motorcycle
          '81': mountain
          '82': mouth
          '83': neck
          '84': nose
          '85': number
          '86': orange
          '87': pant
          '88': paper
          '89': paw
          '90': people
          '91': person
          '92': phone
          '93': pillow
          '94': pizza
          '95': plane
          '96': plant
          '97': plate
          '98': player
          '99': pole
          '100': post
          '101': pot
          '102': racket
          '103': railing
          '104': rock
          '105': roof
          '106': room
          '107': screen
          '108': seat
          '109': sheep
          '110': shelf
          '111': shirt
          '112': shoe
          '113': short
          '114': sidewalk
          '115': sign
          '116': sink
          '117': skateboard
          '118': ski
          '119': skier
          '120': sneaker
          '121': snow
          '122': sock
          '123': stand
          '124': street
          '125': surfboard
          '126': table
          '127': tail
          '128': tie
          '129': tile
          '130': tire
          '131': toilet
          '132': towel
          '133': tower
          '134': track
          '135': train
          '136': tree
          '137': truck
          '138': trunk
          '139': umbrella
          '140': vase
          '141': vegetable
          '142': vehicle
          '143': wave
          '144': wheel
          '145': window
          '146': windshield
          '147': wing
          '148': wire
          '149': woman
          '150': zebra
  - name: attributes
    list:
      list:
        class_label:
          names:
            '0': __background__
            '1': white
            '2': black
            '3': blue
            '4': green
            '5': red
            '6': brown
            '7': yellow
            '8': small
            '9': large
            '10': wooden
            '11': silver
            '12': orange
            '13': grey
            '14': tall
            '15': long
            '16': dark
            '17': pink
            '18': standing
            '19': round
            '20': tan
            '21': glass
            '22': here
            '23': wood
            '24': open
            '25': purple
            '26': short
            '27': plastic
            '28': parked
            '29': sitting
            '30': walking
            '31': striped
            '32': brick
            '33': young
            '34': gold
            '35': old
            '36': hanging
            '37': empty
            '38': 'on'
            '39': bright
            '40': concrete
            '41': cloudy
            '42': colorful
            '43': one
            '44': beige
            '45': bare
            '46': wet
            '47': light
            '48': square
            '49': closed
            '50': stone
            '51': shiny
            '52': thin
            '53': dirty
            '54': flying
            '55': smiling
            '56': painted
            '57': thick
            '58': part
            '59': sliced
            '60': playing
            '61': tennis
            '62': calm
            '63': leather
            '64': distant
            '65': rectangular
            '66': looking
            '67': grassy
            '68': dry
            '69': cement
            '70': leafy
            '71': wearing
            '72': tiled
            '73': man's
            '74': baseball
            '75': cooked
            '76': pictured
            '77': curved
            '78': decorative
            '79': dead
            '80': eating
            '81': paper
            '82': paved
            '83': fluffy
            '84': lit
            '85': back
            '86': framed
            '87': plaid
            '88': dirt
            '89': watching
            '90': colored
            '91': stuffed
            '92': clean
            '93': in the picture
            '94': steel
            '95': stacked
            '96': covered
            '97': full
            '98': three
            '99': street
            '100': flat
            '101': baby
            '102': black and white
            '103': beautiful
            '104': ceramic
            '105': present
            '106': grazing
            '107': sandy
            '108': golden
            '109': blurry
            '110': side
            '111': chocolate
            '112': wide
            '113': growing
            '114': chrome
            '115': cut
            '116': bent
            '117': train
            '118': holding
            '119': water
            '120': up
            '121': arched
            '122': metallic
            '123': spotted
            '124': folded
            '125': electrical
            '126': pointy
            '127': running
            '128': leafless
            '129': electric
            '130': in background
            '131': rusty
            '132': furry
            '133': traffic
            '134': ripe
            '135': behind
            '136': laying
            '137': rocky
            '138': tiny
            '139': down
            '140': fresh
            '141': floral
            '142': stainless steel
            '143': high
            '144': surfing
            '145': close
            '146': 'off'
            '147': leaning
            '148': moving
            '149': multicolored
            '150': woman's
            '151': pair
            '152': huge
            '153': some
            '154': background
            '155': chain link
            '156': checkered
            '157': top
            '158': tree
            '159': broken
            '160': maroon
            '161': iron
            '162': worn
            '163': patterned
            '164': ski
            '165': overcast
            '166': waiting
            '167': rubber
            '168': riding
            '169': skinny
            '170': grass
            '171': porcelain
            '172': adult
            '173': wire
            '174': cloudless
            '175': curly
            '176': cardboard
            '177': jumping
            '178': tile
            '179': pointed
            '180': blond
            '181': cream
            '182': four
            '183': male
            '184': smooth
            '185': hazy
            '186': computer
            '187': older
            '188': pine
            '189': raised
            '190': many
            '191': bald
            '192': snow covered
            '193': skateboarding
            '194': narrow
            '195': reflective
            '196': rear
            '197': khaki
            '198': extended
            '199': roman
            '200': american
  - name: relations
    struct:
    - name: subject_index
      list: int64
    - name: object_index
      list: int64
    - name: predicate
      list:
        class_label:
          names:
            '0': __background__
            '1': above
            '2': across
            '3': against
            '4': along
            '5': and
            '6': at
            '7': attached to
            '8': behind
            '9': belonging to
            '10': between
            '11': carrying
            '12': covered in
            '13': covering
            '14': eating
            '15': flying in
            '16': for
            '17': from
            '18': growing on
            '19': hanging from
            '20': has
            '21': holding
            '22': in
            '23': in front of
            '24': laying on
            '25': looking at
            '26': lying on
            '27': made of
            '28': mounted on
            '29': near
            '30': of
            '31': 'on'
            '32': on back of
            '33': over
            '34': painted on
            '35': parked on
            '36': part of
            '37': playing
            '38': riding
            '39': says
            '40': sitting on
            '41': standing on
            '42': to
            '43': under
            '44': using
            '45': walking in
            '46': walking on
            '47': watching
            '48': wearing
            '49': wears
            '50': with
  splits:
  - name: train
    num_bytes: 8889584511
    num_examples: 62407
  - name: validation
    num_bytes: 1260526902
    num_examples: 8915
  - name: test
    num_bytes: 2706740524
    num_examples: 17832
  download_size: 12730567170
  dataset_size: 12856851937
configs:
- config_name: default
  data_files:
  - split: train
    path: data/train-*
  - split: validation
    path: data/validation-*
  - split: test
    path: data/test-*
---


# Visual Genome Scene Graph Dataset

该仓库提供经过结构化处理的 Visual Genome 场景图数据集,可直接通过 Hugging Face `datasets` 加载。数据采用常用的 VG150 类别体系,包含 150 个前景对象类别、50 个前景关系类别和 200 个前景属性类别;每组类别还包含索引为 0 的 `__background__`## 数据划分

| Split | 样本数 |
| --- | ---: |
| train | 62,407 |
| validation | 8,915 |
| test | 17,832 |
| **合计** | **89,154** |

仓库下载大小约为 12.7 GB。图片直接嵌入 Parquet,因此 `image` 字段由 Hugging Face 解码为 PIL 图片对象。

## 字段说明

每行表示一张图片及其场景图:

- `id`:样本 ID。
- `image`:Hugging Face `Image` 字段,读取样本时返回 PIL 图片。
- `width``height`:图片宽高。
- `boxes`:对象边界框,格式为 `[x_min, y_min, x_max, y_max]`- `labels`:与 `boxes` 一一对应的对象类别 ID。
- `attributes`:与对象一一对应的属性类别 ID 列表。
- `relations.subject_index`:关系主语在对象数组中的索引。
- `relations.object_index`:关系宾语在对象数组中的索引。
- `relations.predicate`:关系类别 ID。

对象、属性和关系均使用 `ClassLabel`,可以通过 Dataset 的 `features` 取得类别名称。

## 加载数据

```python
from datasets import load_dataset


dataset = load_dataset("wliafe/vg")
print(dataset)

sample = dataset["train"][0]
print(sample["id"])
print(sample["image"].size)
print(len(sample["boxes"]))
print(len(sample["relations"]["predicate"]))
```

如需避免立即解码图片,可以先把 `image` 字段转换为 `decode=False````python
from datasets import Image, load_dataset


dataset = load_dataset("wliafe/vg")
dataset = dataset.cast_column("image", Image(decode=False))

sample = dataset["train"][0]
print(sample["image"])
```

## 读取类别名称

```python
from datasets import load_dataset


dataset = load_dataset("wliafe/vg")
features = dataset["train"].features

object_names = features["labels"].feature.names
attribute_names = features["attributes"].feature.feature.names
predicate_names = features["relations"]["predicate"].feature.names

sample = dataset["train"][0]
for subject_index, object_index, predicate_id in zip(
    sample["relations"]["subject_index"],
    sample["relations"]["object_index"],
    sample["relations"]["predicate"],
):
    subject_label = object_names[sample["labels"][subject_index]]
    object_label = object_names[sample["labels"][object_index]]
    predicate = predicate_names[predicate_id]
    print(f"{subject_label} --{predicate}--> {object_label}")
```

## 标注约定

- 边界框会裁剪到图片范围内。
- 裁剪后面积为零的对象不会保留。
- 引用已删除对象的关系不会保留。
- 关系端点保存为当前对象数组的索引,而不是 Visual Genome 的原始对象 ID。
- `boxes``labels``attributes` 使用相同的对象顺序。

## 引用

如果该数据集对你的研究有帮助,请引用 Visual Genome:

```bibtex
@article{krishna2017visual,
  title={Visual Genome: Connecting Language and Vision Using Crowdsourced Dense Image Annotations},
  author={Krishna, Ranjay and Zhu, Yuke and Groth, Oliver and Johnson, Justin and Hata, Kenji and Kravitz, Joshua and Chen, Stephanie and Kalantidis, Yannis and Li, Li-Jia and Shamma, David A. and Bernstein, Michael S. and Fei-Fei, Li},
  journal={International Journal of Computer Vision},
  volume={123},
  pages={32--73},
  year={2017}
}
```

数据的使用许可和适用范围请以 Visual Genome 官方发布条款为准。