Create RefRef_test.py
Browse files- RefRef_test.py +41 -0
RefRef_test.py
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# RefRef_test.py
|
2 |
+
from datasets import Dataset, DatasetDict, Features, Image, Value
|
3 |
+
import json
|
4 |
+
import os
|
5 |
+
|
6 |
+
# Define dataset features to match your YAML
|
7 |
+
features = Features({
|
8 |
+
"image": Image(),
|
9 |
+
"depth": Image(),
|
10 |
+
"mask": Image(),
|
11 |
+
"transform_matrix": Value("float64", shape=(4, 4)),
|
12 |
+
"rotation": Value("float32"),
|
13 |
+
})
|
14 |
+
|
15 |
+
def load_dataset(data_dir, **kwargs):
|
16 |
+
splits = ["train", "val", "test"]
|
17 |
+
dataset_dict = {}
|
18 |
+
|
19 |
+
for split in splits:
|
20 |
+
json_path = os.path.join(data_dir, f"transforms_{split}.json")
|
21 |
+
if not os.path.exists(json_path):
|
22 |
+
continue # Skip missing splits
|
23 |
+
|
24 |
+
with open(json_path, "r") as f:
|
25 |
+
data = json.load(f)
|
26 |
+
|
27 |
+
# Extract frames and rename keys
|
28 |
+
examples = []
|
29 |
+
for frame in data["frames"]:
|
30 |
+
example = {
|
31 |
+
"image": frame["file_path"],
|
32 |
+
"depth": frame["depth_file_path"],
|
33 |
+
"mask": frame["mask_file_path"],
|
34 |
+
"transform_matrix": frame["transform_matrix"],
|
35 |
+
"rotation": frame.get("rotation", 0.0),
|
36 |
+
}
|
37 |
+
examples.append(example)
|
38 |
+
|
39 |
+
dataset_dict[split] = Dataset.from_list(examples, features=features)
|
40 |
+
|
41 |
+
return DatasetDict(dataset_dict)
|