anfera236 commited on
Commit
df0e176
·
verified ·
1 Parent(s): 170c70c

Upload check_dataset.py

Browse files
Files changed (1) hide show
  1. check_dataset.py +49 -0
check_dataset.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from datasets import load_dataset
2
+ from tqdm import tqdm
3
+ import torch
4
+ from torch.utils.data import DataLoader
5
+ from scripts.forward_model import LidarForwardImagingModel
6
+
7
+ forward_model = LidarForwardImagingModel()
8
+
9
+ BATCH_SIZE = 64
10
+
11
+ def make_loader(split: str):
12
+ ds = load_dataset("anfera236/HHDC", split=split)
13
+ # return PyTorch tensors for the "cube" column
14
+ ds.set_format(type="torch", columns=["cube"])
15
+ # wrap in a DataLoader to get batches
16
+ loader = DataLoader(
17
+ ds,
18
+ batch_size=BATCH_SIZE,
19
+ shuffle=False, # no need to shuffle for shape checking
20
+ )
21
+ return ds, loader
22
+
23
+
24
+ def check_split(split_name: str):
25
+ print(f"Checking {split_name} dataset batches (batch_size={BATCH_SIZE})...")
26
+ ds, loader = make_loader(split_name)
27
+
28
+ for batch in tqdm(loader):
29
+ cubes = batch["cube"] # shape: (B, 128, 48, 48)
30
+ # sanity check on input shape
31
+ assert cubes.ndim == 4, f"Expected 4D input (B, 128, 48, 48), got {cubes.shape}"
32
+ assert cubes.shape[1:] == (128, 48, 48), f"Bad input sample shape: {cubes.shape}"
33
+
34
+ # forward pass (expects model to support batched input)
35
+ output = forward_model(cubes) # expected shape: (B, 128, 32, 16)
36
+
37
+ # sanity checks on output shape
38
+ assert output.ndim == 4, f"Expected 4D output (B, 128, 32, 16), got {output.shape}"
39
+ assert output.shape[0] == cubes.shape[0], (
40
+ f"Batch size mismatch: input B={cubes.shape[0]}, output B={output.shape[0]}"
41
+ )
42
+ assert output.shape[1:] == (128, 32, 16), f"Bad output sample shape: {output.shape}"
43
+
44
+
45
+ if __name__ == "__main__":
46
+ check_split("train")
47
+ check_split("validation")
48
+ check_split("test")
49
+ print("All splits passed shape checks ✅")