jagennath-hari commited on
Commit
0c8bca5
·
1 Parent(s): ef994e9
scripts/__pycache__/upload_preview_to_hf.cpython-313.pyc DELETED
Binary file (6.53 kB)
 
scripts/upload_preview_to_hf.py DELETED
@@ -1,144 +0,0 @@
1
- #!/usr/bin/env python3
2
-
3
- import argparse
4
- import math
5
- import os
6
-
7
- import pandas as pd
8
- from datasets import Dataset, Features, Image, Sequence, Value
9
-
10
-
11
- def parse_args():
12
- parser = argparse.ArgumentParser()
13
- parser.add_argument("--data", required=True, help="Path to preview folder")
14
- parser.add_argument("--repo", required=True, help="HF dataset repo (e.g. org/name)")
15
- parser.add_argument("--split", default="preview", help="Dataset split name")
16
- return parser.parse_args()
17
-
18
-
19
- def _coerce_dt(x: object) -> float:
20
- """Coerce merge-produced values (NaN/None/str) into a sane float offset."""
21
- try:
22
- v = float(x)
23
- except (TypeError, ValueError):
24
- return 0.0
25
- if math.isnan(v) or math.isinf(v):
26
- return 0.0
27
- return v
28
-
29
-
30
- def main():
31
- args = parse_args()
32
-
33
- data_dir = args.data
34
- imu_path = os.path.join(data_dir, "imu.csv")
35
- odom_path = os.path.join(data_dir, "odom.csv")
36
-
37
- if not os.path.exists(imu_path):
38
- raise FileNotFoundError(f"imu.csv not found in {data_dir}")
39
-
40
- print("Loading IMU data...")
41
- imu = pd.read_csv(imu_path)
42
-
43
- # Normalize timestamps (filename-friendly and merge-stable).
44
- imu["t"] = imu["t"].map(lambda x: f"{float(x):.6f}")
45
-
46
- has_odom = os.path.exists(odom_path)
47
- if has_odom:
48
- print("Loading ODOM data...")
49
- odom = pd.read_csv(odom_path)
50
- odom["t"] = odom["t"].map(lambda x: f"{float(x):.6f}")
51
- df = pd.merge(imu, odom, on="t", how="left")
52
- else:
53
- print("No odom.csv found -> filling pose with inf")
54
- df = imu.copy()
55
-
56
- print(f"Rows after merge: {len(df)}")
57
-
58
- left_paths = []
59
- right_paths = []
60
- timestamps = []
61
- gyro = []
62
- accel = []
63
- sync_dt = []
64
- position = []
65
- orientation = []
66
-
67
- missing = 0
68
- for _, row in df.iterrows():
69
- t = row["t"]
70
-
71
- l = os.path.join(data_dir, "left", f"{t}.png")
72
- r = os.path.join(data_dir, "right", f"{t}.png")
73
-
74
- if not os.path.exists(l) or not os.path.exists(r):
75
- missing += 1
76
- continue
77
-
78
- left_paths.append(l)
79
- right_paths.append(r)
80
- timestamps.append(float(t))
81
-
82
- # IMU
83
- gyro.append([row["gx"], row["gy"], row["gz"]])
84
- accel.append([row["ax"], row["ay"], row["az"]])
85
-
86
- # Sync offsets (seconds) relative to the left-image timestamp.
87
- dt_r = _coerce_dt(row.get("dt_right", 0.0))
88
- dt_i = _coerce_dt(row.get("dt_imu", 0.0))
89
- sync_dt.append([dt_r, dt_i])
90
-
91
- # ODOM (optional)
92
- if has_odom:
93
- position.append([row["px"], row["py"], row["pz"]])
94
- orientation.append([row["qx"], row["qy"], row["qz"], row["qw"]])
95
- else:
96
- position.append([math.inf, math.inf, math.inf])
97
- orientation.append([math.inf, math.inf, math.inf, math.inf])
98
-
99
- if not left_paths:
100
- raise RuntimeError("No valid samples found")
101
-
102
- if missing:
103
- print(f"Skipped {missing} rows due to missing images")
104
-
105
- print(f"Final dataset size: {len(left_paths)}")
106
-
107
- features = Features(
108
- {
109
- "image_left": Image(),
110
- "image_right": Image(),
111
- "timestamp": Value("float64"),
112
- "gyro": Sequence(Value("float32"), length=3),
113
- "accel": Sequence(Value("float32"), length=3),
114
- "sync_dt": Sequence(Value("float32"), length=2),
115
- "position": Sequence(Value("float32"), length=3),
116
- "orientation": Sequence(Value("float32"), length=4),
117
- }
118
- )
119
-
120
- data = {
121
- "image_left": left_paths,
122
- "image_right": right_paths,
123
- "timestamp": timestamps,
124
- "gyro": gyro,
125
- "accel": accel,
126
- "sync_dt": sync_dt,
127
- "position": position,
128
- "orientation": orientation,
129
- }
130
-
131
- print("Creating Hugging Face dataset...")
132
- ds = Dataset.from_dict(data, features=features)
133
-
134
- print(ds)
135
-
136
- print(f"Pushing to {args.repo} (split={args.split})...")
137
- ds.push_to_hub(args.repo, split=args.split)
138
-
139
- print("Done.")
140
-
141
-
142
- if __name__ == "__main__":
143
- main()
144
-