Update RefRef_test.py
Browse files- RefRef_test.py +82 -48
RefRef_test.py
CHANGED
@@ -1,56 +1,90 @@
|
|
1 |
-
# RefRef_test.py
|
2 |
-
from datasets import Dataset, DatasetDict, Features, Image, Value
|
3 |
import json
|
4 |
import os
|
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 |
-
# Load image
|
33 |
-
image_path = os.path.join(base_dir, frame["file_path"])
|
34 |
-
image = PILImage.open(image_path)
|
35 |
|
36 |
-
|
37 |
-
|
38 |
-
depth = PILImage.open(depth_path)
|
39 |
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
}
|
52 |
-
examples.append(example)
|
53 |
-
|
54 |
-
dataset_dict[split] = Dataset.from_list(examples, features=features)
|
55 |
-
|
56 |
-
return DatasetDict(dataset_dict)
|
|
|
|
|
|
|
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={2023}
|
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_test(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 |
+
# No multiple configs needed - using single configuration
|
25 |
+
BUILDER_CONFIGS = [
|
26 |
+
datasets.BuilderConfig(
|
27 |
+
name="default",
|
28 |
+
version=VERSION,
|
29 |
+
description="Default configuration for NeRF dataset"
|
30 |
+
)
|
31 |
+
]
|
32 |
+
|
33 |
+
def _info(self):
|
34 |
+
features = datasets.Features({
|
35 |
+
"image": datasets.Image(),
|
36 |
+
"depth": datasets.Image(),
|
37 |
+
"mask": datasets.Image(),
|
38 |
+
"transform_matrix": datasets.Sequence(
|
39 |
+
datasets.Sequence(datasets.Value("float64"), length=4),
|
40 |
+
length=4
|
41 |
+
),
|
42 |
+
"rotation": datasets.Value("float32")
|
43 |
+
})
|
44 |
|
45 |
+
return datasets.DatasetInfo(
|
46 |
+
description=_DESCRIPTION,
|
47 |
+
features=features,
|
48 |
+
homepage="",
|
49 |
+
license=_LICENSE,
|
50 |
+
citation=_CITATION
|
51 |
+
)
|
52 |
+
|
53 |
+
def _split_generators(self, dl_manager):
|
54 |
+
return [
|
55 |
+
datasets.SplitGenerator(
|
56 |
+
name=datasets.Split.TRAIN,
|
57 |
+
gen_kwargs={"split": "train"}
|
58 |
+
),
|
59 |
+
datasets.SplitGenerator(
|
60 |
+
name=datasets.Split.VALIDATION,
|
61 |
+
gen_kwargs={"split": "val"}
|
62 |
+
),
|
63 |
+
datasets.SplitGenerator(
|
64 |
+
name=datasets.Split.TEST,
|
65 |
+
gen_kwargs={"split": "test"}
|
66 |
+
),
|
67 |
+
]
|
68 |
+
|
69 |
+
def _generate_examples(self, split):
|
70 |
+
base_path = os.path.join("./") # Update this path
|
71 |
|
72 |
+
# Assuming your directory structure has scene folders (ball, ampoule)
|
73 |
+
# with transforms_{split}.json files
|
74 |
+
for scene in ["ball", "ampoule"]: # Add all your scene names here
|
75 |
+
json_path = os.path.join(base_path, scene, f"transforms_{split}.json")
|
|
|
|
|
|
|
|
|
76 |
|
77 |
+
with open(json_path, "r") as f:
|
78 |
+
data = json.load(f)
|
|
|
79 |
|
80 |
+
for idx, frame in enumerate(data["frames"]):
|
81 |
+
# Construct full paths relative to JSON file location
|
82 |
+
base_dir = os.path.dirname(json_path)
|
83 |
+
|
84 |
+
yield f"{scene}_{split}_{idx}", {
|
85 |
+
"image": os.path.join(base_dir, frame["file_path"]),
|
86 |
+
"depth": os.path.join(base_dir, frame["depth_file_path"]),
|
87 |
+
"mask": os.path.join(base_dir, frame["mask_file_path"]),
|
88 |
+
"transform_matrix": frame["transform_matrix"],
|
89 |
+
"rotation": frame.get("rotation", 0.0)
|
90 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|