Update RefRef_test.py
Browse files- RefRef_test.py +43 -19
RefRef_test.py
CHANGED
@@ -74,25 +74,49 @@ class RefRef_test(datasets.GeneratorBasedBuilder):
|
|
74 |
) for split in [datasets.Split.TRAIN, datasets.Split.VALIDATION, datasets.Split.TEST]
|
75 |
]
|
76 |
|
77 |
-
def _generate_examples(self, filepaths, split):
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
|
89 |
-
|
90 |
-
|
91 |
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
) for split in [datasets.Split.TRAIN, datasets.Split.VALIDATION, datasets.Split.TEST]
|
75 |
]
|
76 |
|
77 |
+
# def _generate_examples(self, filepaths, split):
|
78 |
+
# # Iterate through all JSON files for this split
|
79 |
+
# for scene_idx, filepath in enumerate(filepaths):
|
80 |
+
# print(filepath)
|
81 |
+
# with open(filepath, "r", encoding="utf-8") as f:
|
82 |
+
# data = json.load(f)
|
83 |
+
# scene_name = os.path.basename(os.path.dirname(filepath))
|
84 |
|
85 |
+
# for frame_idx, frame in enumerate(data["frames"]):
|
86 |
+
# # Build absolute paths relative to JSON file location
|
87 |
+
# base_dir = os.path.dirname(filepath)
|
88 |
|
89 |
+
# # Generate unique key using scene and frame indices
|
90 |
+
# unique_key = f"{scene_name}_{split}_{scene_idx}_{frame_idx}"
|
91 |
|
92 |
+
# yield unique_key, {
|
93 |
+
# "image": os.path.join(base_dir, frame["file_path"]),
|
94 |
+
# "depth": os.path.join(base_dir, frame["depth_file_path"]),
|
95 |
+
# "mask": os.path.join(base_dir, frame["mask_file_path"]),
|
96 |
+
# "transform_matrix": frame["transform_matrix"],
|
97 |
+
# "rotation": frame.get("rotation", 0.0)
|
98 |
+
# }
|
99 |
+
def _generate_examples(self, filepaths, split):
|
100 |
+
for filepath in filepaths:
|
101 |
+
# Add validation for JSON files
|
102 |
+
if not filepath.endswith(".json") or os.path.isdir(filepath):
|
103 |
+
continue
|
104 |
+
|
105 |
+
with open(filepath, "r", encoding="utf-8") as f:
|
106 |
+
try:
|
107 |
+
data = json.load(f)
|
108 |
+
except json.JSONDecodeError:
|
109 |
+
continue
|
110 |
+
|
111 |
+
scene_name = os.path.basename(os.path.dirname(filepath))
|
112 |
+
|
113 |
+
for frame_idx, frame in enumerate(data.get("frames", [])):
|
114 |
+
base_dir = os.path.dirname(filepath)
|
115 |
+
|
116 |
+
yield f"{scene_name}_{frame_idx}", {
|
117 |
+
"image": os.path.join(base_dir, frame["file_path"]),
|
118 |
+
"depth": os.path.join(base_dir, frame["depth_file_path"]),
|
119 |
+
"mask": os.path.join(base_dir, frame["mask_file_path"]),
|
120 |
+
"transform_matrix": frame["transform_matrix"],
|
121 |
+
"rotation": frame.get("rotation", 0.0)
|
122 |
+
}
|