Spaces:
Running
on
Zero
Running
on
Zero
File size: 1,878 Bytes
9e15541 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
import argparse
import pickle
from pathlib import Path
from tqdm import tqdm
import numpy as np
def load_data(mode_path: Path, failures_path: Path):
seq_files = sorted(mode_path.glob('*.txt'))
with open(failures_path, "r") as f:
failures = set(l[:-1] for l in f.readlines())
skipped = 0
seq_data = {}
for seq_file in tqdm(seq_files):
seq_name = seq_file.stem
if seq_name in failures:
# print(f"Skipping sequence {seq_name} because the download had failed.")
skipped += 1
continue
try:
timestamps = np.loadtxt(seq_file, dtype=int, skiprows=1).reshape((-1, 19))[:, 0]
except:
print(seq_file)
pass
data = np.loadtxt(seq_file, dtype=float, skiprows=1).reshape((-1, 19))[:, 1:]
intrinsics = data[:, :6]
pose = np.reshape(data[:, 6:], (-1, 3, 4))
seq_data[seq_name] = {
"timestamps": timestamps,
"intrinsics": intrinsics,
"poses": pose
}
print(f"Skipped {skipped} sequences because the video download had failed.")
return seq_data
def main():
parser = argparse.ArgumentParser()
parser.add_argument("-m", "--mode", type=str)
parser.add_argument("-d", "--data_path", type=str)
args = parser.parse_args()
mode = args.mode
data_path = Path(args.data_path)
if mode not in ["test", "train"]:
raise ValueError(f"Invalid split mode: {mode}")
mode_path = data_path / mode
failures_path = data_path / f"failed_videos_{mode}.txt"
print("Loading data")
data = load_data(mode_path, failures_path)
print()
print("Saving data into a single file.")
with open(data_path / f"{mode}.pickle", "wb") as f:
pickle.dump(data, f)
print()
print("Done")
if __name__ == "__main__":
main()
|