eztao commited on
Commit
4e9ffe6
·
verified ·
1 Parent(s): c8df592

Update RefRef_test.py

Browse files
Files changed (1) hide show
  1. RefRef_test.py +32 -19
RefRef_test.py CHANGED
@@ -2,37 +2,50 @@
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
 
 
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_nerf_dataset(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
  for split in splits:
20
+ json_path = os.path.join(data_dir, config_name, f"transforms_{split}.json")
 
 
21
 
22
  with open(json_path, "r") as f:
23
  data = json.load(f)
24
 
 
25
  examples = []
26
  for frame in data["frames"]:
27
+ # Resolve relative paths to load images
28
+ base_dir = os.path.dirname(json_path)
29
+
30
+ # Load image
31
+ image_path = os.path.join(base_dir, frame["file_path"])
32
+ image = PILImage.open(image_path)
33
+
34
+ # Load depth
35
+ depth_path = os.path.join(base_dir, frame["depth_file_path"])
36
+ depth = PILImage.open(depth_path)
37
+
38
+ # Load mask
39
+ mask_path = os.path.join(base_dir, frame["mask_file_path"])
40
+ mask = PILImage.open(mask_path)
41
+
42
+ # Create example
43
  example = {
44
+ "image": image,
45
+ "depth": depth,
46
+ "mask": mask,
47
  "transform_matrix": frame["transform_matrix"],
48
+ "rotation": frame.get("rotation", 0.0)
49
  }
50
  examples.append(example)
51