Create RefRef.py
Browse files
RefRef.py
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
import os
|
| 3 |
+
import datasets
|
| 4 |
+
|
| 5 |
+
_CITATION = """\
|
| 6 |
+
@InProceedings{...},
|
| 7 |
+
title = {Your Dataset Title},
|
| 8 |
+
author={Your Name},
|
| 9 |
+
year={2025}
|
| 10 |
+
}
|
| 11 |
+
"""
|
| 12 |
+
|
| 13 |
+
_DESCRIPTION = """\
|
| 14 |
+
Dataset containing multi-view images with camera poses, depth maps, and masks for NeRF training.
|
| 15 |
+
"""
|
| 16 |
+
|
| 17 |
+
_LICENSE = "MIT"
|
| 18 |
+
|
| 19 |
+
class RefRef(datasets.GeneratorBasedBuilder):
|
| 20 |
+
"""A dataset loader for NeRF-style data with camera poses, depth maps, and masks."""
|
| 21 |
+
|
| 22 |
+
VERSION = datasets.Version("1.0.0")
|
| 23 |
+
|
| 24 |
+
BUILDER_CONFIGS = [
|
| 25 |
+
datasets.BuilderConfig(
|
| 26 |
+
name="default",
|
| 27 |
+
version=VERSION,
|
| 28 |
+
description="Default configuration for NeRF dataset"
|
| 29 |
+
),
|
| 30 |
+
datasets.BuilderConfig(
|
| 31 |
+
name="ball",
|
| 32 |
+
version=VERSION,
|
| 33 |
+
description="Default configuration for NeRF dataset"
|
| 34 |
+
),
|
| 35 |
+
datasets.BuilderConfig(
|
| 36 |
+
name="ampoule",
|
| 37 |
+
version=VERSION,
|
| 38 |
+
description="Default configuration for NeRF dataset"
|
| 39 |
+
)
|
| 40 |
+
]
|
| 41 |
+
|
| 42 |
+
def _info(self):
|
| 43 |
+
features = datasets.Features({
|
| 44 |
+
"image": datasets.Image(),
|
| 45 |
+
"depth": datasets.Image(),
|
| 46 |
+
"mask": datasets.Image(),
|
| 47 |
+
"transform_matrix": datasets.Sequence(
|
| 48 |
+
datasets.Sequence(datasets.Value("float64"), length=4),
|
| 49 |
+
length=4
|
| 50 |
+
),
|
| 51 |
+
"rotation": datasets.Value("float32")
|
| 52 |
+
})
|
| 53 |
+
|
| 54 |
+
return datasets.DatasetInfo(
|
| 55 |
+
description=_DESCRIPTION,
|
| 56 |
+
features=features,
|
| 57 |
+
homepage="",
|
| 58 |
+
license=_LICENSE,
|
| 59 |
+
citation=_CITATION
|
| 60 |
+
)
|
| 61 |
+
|
| 62 |
+
def _split_generators(self, dl_manager):
|
| 63 |
+
# Automatically find all JSON files matching the split patterns
|
| 64 |
+
return [
|
| 65 |
+
datasets.SplitGenerator(
|
| 66 |
+
name=scene,
|
| 67 |
+
gen_kwargs={
|
| 68 |
+
"filepaths": os.path.join(f"https://huggingface.co/datasets/yinyue27/RefRef/resolve/main/image_data/textured_cube_scene/single-convex/{scene}/"),
|
| 69 |
+
"split": split
|
| 70 |
+
},
|
| 71 |
+
) for scene in ["ball", "ball_coloured", "cube", "cube_coloured"]
|
| 72 |
+
]
|
| 73 |
+
|
| 74 |
+
def _generate_examples(self, filepaths, split):
|
| 75 |
+
for split in ["train", "val", "test"]:
|
| 76 |
+
filepaths = os.path.join(filepaths, f"transforms_{split}.json")
|
| 77 |
+
with open(filepaths, "r", encoding="utf-8") as f:
|
| 78 |
+
try:
|
| 79 |
+
data = json.load(f)
|
| 80 |
+
except json.JSONDecodeError:
|
| 81 |
+
print("error")
|
| 82 |
+
|
| 83 |
+
scene_name = os.path.basename(os.path.dirname(filepaths))
|
| 84 |
+
|
| 85 |
+
for frame_idx, frame in enumerate(data.get("frames", [])):
|
| 86 |
+
base_dir = os.path.dirname(filepaths)
|
| 87 |
+
|
| 88 |
+
yield f"{scene_name}_{frame_idx}", {
|
| 89 |
+
"image": os.path.join(base_dir, frame["file_path"]+".png"),
|
| 90 |
+
"depth": os.path.join(base_dir, frame["depth_file_path"]),
|
| 91 |
+
"mask": os.path.join(base_dir, frame["mask_file_path"]),
|
| 92 |
+
"transform_matrix": frame["transform_matrix"],
|
| 93 |
+
"rotation": frame.get("rotation", 0.0)
|
| 94 |
+
}
|