Document the Visual Genome scene graph dataset
#2
by wliafe - opened
README.md
CHANGED
|
@@ -457,3 +457,114 @@ configs:
|
|
| 457 |
- split: test
|
| 458 |
path: data/test-*
|
| 459 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 457 |
- split: test
|
| 458 |
path: data/test-*
|
| 459 |
---
|
| 460 |
+
|
| 461 |
+
|
| 462 |
+
# Visual Genome Scene Graph Dataset
|
| 463 |
+
|
| 464 |
+
该仓库提供经过结构化处理的 Visual Genome 场景图数据集,可直接通过 Hugging Face `datasets` 加载。数据采用常用的 VG150 类别体系,包含 150 个前景对象类别、50 个前景关系类别和 200 个前景属性类别;每组类别还包含索引为 0 的 `__background__`。
|
| 465 |
+
|
| 466 |
+
## 数据划分
|
| 467 |
+
|
| 468 |
+
| Split | 样本数 |
|
| 469 |
+
| --- | ---: |
|
| 470 |
+
| train | 62,407 |
|
| 471 |
+
| validation | 8,915 |
|
| 472 |
+
| test | 17,832 |
|
| 473 |
+
| **合计** | **89,154** |
|
| 474 |
+
|
| 475 |
+
仓库下载大小约为 12.7 GB。图片直接嵌入 Parquet,因此 `image` 字段由 Hugging Face 解码为 PIL 图片对象。
|
| 476 |
+
|
| 477 |
+
## 字段说明
|
| 478 |
+
|
| 479 |
+
每行表示一张图片及其场景图:
|
| 480 |
+
|
| 481 |
+
- `id`:样本 ID。
|
| 482 |
+
- `image`:Hugging Face `Image` 字段,读取样本时返回 PIL 图片。
|
| 483 |
+
- `width`、`height`:图片宽高。
|
| 484 |
+
- `boxes`:对象边界框,格式为 `[x_min, y_min, x_max, y_max]`。
|
| 485 |
+
- `labels`:与 `boxes` 一一对应的对象类别 ID。
|
| 486 |
+
- `attributes`:与对象一一对应的属性类别 ID 列表。
|
| 487 |
+
- `relations.subject_index`:关系主语在对象数组中的索引。
|
| 488 |
+
- `relations.object_index`:关系宾语在对象数组中的索引。
|
| 489 |
+
- `relations.predicate`:关系类别 ID。
|
| 490 |
+
|
| 491 |
+
对象、属性和关系均使用 `ClassLabel`,可以通过 Dataset 的 `features` 取得类别名称。
|
| 492 |
+
|
| 493 |
+
## 加载数据
|
| 494 |
+
|
| 495 |
+
```python
|
| 496 |
+
from datasets import load_dataset
|
| 497 |
+
|
| 498 |
+
|
| 499 |
+
dataset = load_dataset("wliafe/vg")
|
| 500 |
+
print(dataset)
|
| 501 |
+
|
| 502 |
+
sample = dataset["train"][0]
|
| 503 |
+
print(sample["id"])
|
| 504 |
+
print(sample["image"].size)
|
| 505 |
+
print(len(sample["boxes"]))
|
| 506 |
+
print(len(sample["relations"]["predicate"]))
|
| 507 |
+
```
|
| 508 |
+
|
| 509 |
+
如需避免立即解码图片,可以先把 `image` 字段转换为 `decode=False`:
|
| 510 |
+
|
| 511 |
+
```python
|
| 512 |
+
from datasets import Image, load_dataset
|
| 513 |
+
|
| 514 |
+
|
| 515 |
+
dataset = load_dataset("wliafe/vg")
|
| 516 |
+
dataset = dataset.cast_column("image", Image(decode=False))
|
| 517 |
+
|
| 518 |
+
sample = dataset["train"][0]
|
| 519 |
+
print(sample["image"])
|
| 520 |
+
```
|
| 521 |
+
|
| 522 |
+
## 读取类别名称
|
| 523 |
+
|
| 524 |
+
```python
|
| 525 |
+
from datasets import load_dataset
|
| 526 |
+
|
| 527 |
+
|
| 528 |
+
dataset = load_dataset("wliafe/vg")
|
| 529 |
+
features = dataset["train"].features
|
| 530 |
+
|
| 531 |
+
object_names = features["labels"].feature.names
|
| 532 |
+
attribute_names = features["attributes"].feature.feature.names
|
| 533 |
+
predicate_names = features["relations"]["predicate"].feature.names
|
| 534 |
+
|
| 535 |
+
sample = dataset["train"][0]
|
| 536 |
+
for subject_index, object_index, predicate_id in zip(
|
| 537 |
+
sample["relations"]["subject_index"],
|
| 538 |
+
sample["relations"]["object_index"],
|
| 539 |
+
sample["relations"]["predicate"],
|
| 540 |
+
):
|
| 541 |
+
subject_label = object_names[sample["labels"][subject_index]]
|
| 542 |
+
object_label = object_names[sample["labels"][object_index]]
|
| 543 |
+
predicate = predicate_names[predicate_id]
|
| 544 |
+
print(f"{subject_label} --{predicate}--> {object_label}")
|
| 545 |
+
```
|
| 546 |
+
|
| 547 |
+
## 标注约定
|
| 548 |
+
|
| 549 |
+
- 边界框会裁剪到图片范围内。
|
| 550 |
+
- 裁剪后面积为零的对象不会保留。
|
| 551 |
+
- 引用已删除对象的关系不会保留。
|
| 552 |
+
- 关系端点保存为当前对象数组的索引,而不是 Visual Genome 的原始对象 ID。
|
| 553 |
+
- `boxes`、`labels` 和 `attributes` 使用相同的对象顺序。
|
| 554 |
+
|
| 555 |
+
## 引用
|
| 556 |
+
|
| 557 |
+
如果该数据集对你的研究有帮助,请引用 Visual Genome:
|
| 558 |
+
|
| 559 |
+
```bibtex
|
| 560 |
+
@article{krishna2017visual,
|
| 561 |
+
title={Visual Genome: Connecting Language and Vision Using Crowdsourced Dense Image Annotations},
|
| 562 |
+
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},
|
| 563 |
+
journal={International Journal of Computer Vision},
|
| 564 |
+
volume={123},
|
| 565 |
+
pages={32--73},
|
| 566 |
+
year={2017}
|
| 567 |
+
}
|
| 568 |
+
```
|
| 569 |
+
|
| 570 |
+
数据的使用许可和适用范围请以 Visual Genome 官方发布条款为准。
|