|
import json |
|
import os |
|
import datasets |
|
|
|
_CITATION = """\ |
|
@InProceedings{...}, |
|
title = {Your Dataset Title}, |
|
author={Your Name}, |
|
year={2023} |
|
} |
|
""" |
|
|
|
_DESCRIPTION = """\ |
|
Dataset containing multi-view images with camera poses, depth maps, and masks for NeRF training. |
|
""" |
|
|
|
_LICENSE = "MIT" |
|
|
|
class RefRef_test(datasets.GeneratorBasedBuilder): |
|
"""A dataset loader for NeRF-style data with camera poses, depth maps, and masks.""" |
|
|
|
VERSION = datasets.Version("1.0.0") |
|
|
|
|
|
BUILDER_CONFIGS = [ |
|
datasets.BuilderConfig( |
|
name="ball", |
|
version=VERSION, |
|
description="Default configuration for NeRF dataset" |
|
), |
|
datasets.BuilderConfig( |
|
name="ampoule", |
|
version=VERSION, |
|
description="Default configuration for NeRF dataset" |
|
) |
|
] |
|
|
|
def _info(self): |
|
features = datasets.Features({ |
|
"image": datasets.Image(), |
|
"depth": datasets.Image(), |
|
"mask": datasets.Image(), |
|
"transform_matrix": datasets.Sequence( |
|
datasets.Sequence(datasets.Value("float64"), length=4), |
|
length=4 |
|
), |
|
"rotation": datasets.Value("float32") |
|
}) |
|
|
|
return datasets.DatasetInfo( |
|
description=_DESCRIPTION, |
|
features=features, |
|
homepage="", |
|
license=_LICENSE, |
|
citation=_CITATION |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
return [ |
|
datasets.SplitGenerator( |
|
name=split, |
|
gen_kwargs={ |
|
"filepaths": os.path.join(f"https://huggingface.co/datasets/eztao/RefRef_test/resolve/main/{self.config.name}/", f"transforms_{split}.json"), |
|
"split": split |
|
}, |
|
) for split in ["train", "val", "test"] |
|
] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _generate_examples(self, filepaths, split): |
|
|
|
|
|
|
|
|
|
|
|
|
|
with open(filepaths, "r", encoding="utf-8") as f: |
|
try: |
|
data = json.load(f) |
|
except json.JSONDecodeError: |
|
print("error") |
|
|
|
scene_name = os.path.basename(os.path.dirname(filepaths)) |
|
|
|
for frame_idx, frame in enumerate(data.get("frames", [])): |
|
base_dir = os.path.dirname(filepaths) |
|
print(os.path.join(base_dir, frame["file_path"]+".png")) |
|
yield f"{scene_name}_{frame_idx}", { |
|
"image": os.path.join(base_dir, frame["file_path"]+".png"), |
|
"depth": os.path.join(base_dir, frame["depth_file_path"]), |
|
"mask": os.path.join(base_dir, frame["mask_file_path"]), |
|
"transform_matrix": frame["transform_matrix"], |
|
"rotation": frame.get("rotation", 0.0) |
|
} |