eztao commited on
Commit
92dcb68
·
verified ·
1 Parent(s): b29321a

Update RefRef_test.py

Browse files
Files changed (1) hide show
  1. 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
- from PIL import Image as PILImage
6
 
7
- def load_RefRef_test(data_dir, config_name, splits=["train", "val", "test"]):
8
- dataset_dict = {}
9
-
10
- # Define features to match the YAML
11
- features = Features({
12
- "image": Image(),
13
- "depth": Image(),
14
- "mask": Image(),
15
- "transform_matrix": Value("float64", shape=(4, 4)),
16
- "rotation": Value("float32")
17
- })
18
-
19
- print("1111!")
 
 
 
 
 
20
 
21
- for split in splits:
22
- json_path = os.path.join(data_dir, config_name, f"transforms_{split}.json")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
 
24
- with open(json_path, "r") as f:
25
- data = json.load(f)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
 
27
- examples = []
28
- for frame in data["frames"]:
29
- # Resolve relative paths to load images
30
- base_dir = os.path.dirname(json_path)
31
-
32
- # Load image
33
- image_path = os.path.join(base_dir, frame["file_path"])
34
- image = PILImage.open(image_path)
35
 
36
- # Load depth
37
- depth_path = os.path.join(base_dir, frame["depth_file_path"])
38
- depth = PILImage.open(depth_path)
39
 
40
- # Load mask
41
- mask_path = os.path.join(base_dir, frame["mask_file_path"])
42
- mask = PILImage.open(mask_path)
43
-
44
- # Create example
45
- example = {
46
- "image": image,
47
- "depth": depth,
48
- "mask": mask,
49
- "transform_matrix": frame["transform_matrix"],
50
- "rotation": frame.get("rotation", 0.0)
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
+ }