Skip to content

Commit 2d7f697

Browse files
committed
Add download_dataset.py
1 parent 7cc22a7 commit 2d7f697

File tree

1 file changed

+251
-0
lines changed

1 file changed

+251
-0
lines changed

benchmark/scripts/download_dataset.py

+251
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,251 @@
1+
#!/usr/bin/env python3
2+
import os
3+
import glob
4+
import urllib.request
5+
import zipfile
6+
7+
from tqdm import tqdm
8+
9+
################################################################################
10+
# DOWNLOAD UTILS
11+
################################################################################
12+
13+
14+
def download(url, save_dir):
15+
# Get the size of the file first
16+
response = urllib.request.urlopen(url)
17+
total_size = int(response.info().get('Content-Length').strip())
18+
19+
# Initialize the progress bar
20+
desc = f"Downloading [{url}]"
21+
pbar = tqdm(total=total_size, unit='B', unit_scale=True, desc=desc)
22+
23+
try:
24+
# Open the URL and the output file
25+
response = urllib.request.urlopen(url)
26+
save_path = os.path.join(save_dir, os.path.basename(url))
27+
out_file = open(save_path, 'wb')
28+
29+
# Read and write the file in chunks
30+
chunk_size = 1024
31+
while True:
32+
chunk = response.read(chunk_size)
33+
if not chunk:
34+
break
35+
out_file.write(chunk)
36+
pbar.update(len(chunk))
37+
38+
finally:
39+
# Clean up: Close the file and the response
40+
pbar.close()
41+
out_file.close()
42+
response.close()
43+
44+
45+
def extract_zip(src, dst):
46+
""" Extract zip file """
47+
dir_name = os.path.basename(src).replace(".zip", "")
48+
dir_name = dir_name.replace("_easy", "")
49+
dir_name = dir_name.replace("_medium", "")
50+
dir_name = dir_name.replace("_difficult", "")
51+
dst_path = os.path.join(dst, dir_name)
52+
53+
with zipfile.ZipFile(src, 'r') as zip_ref:
54+
zip_ref.extractall(dst_path)
55+
56+
57+
################################################################################
58+
# EUROC DATASET
59+
################################################################################
60+
61+
62+
def download_euroc_sequences(dst_dir):
63+
""" Download EuRoC MAV sequences """
64+
base_url = "http://robotics.ethz.ch/~asl-datasets/ijrr_euroc_mav_dataset"
65+
seqs = [
66+
"calibration_datasets/cam_april/cam_april.zip",
67+
"calibration_datasets/imu_april/imu_april.zip",
68+
"machine_hall/MH_01_easy/MH_01_easy.zip",
69+
"machine_hall/MH_02_easy/MH_02_easy.zip",
70+
"machine_hall/MH_03_medium/MH_03_medium.zip",
71+
"machine_hall/MH_04_difficult/MH_04_difficult.zip",
72+
"machine_hall/MH_05_difficult/MH_05_difficult.zip",
73+
"machine_hall/MH_01_easy/MH_01_easy.zip",
74+
"machine_hall/MH_02_easy/MH_02_easy.zip",
75+
"machine_hall/MH_03_medium/MH_03_medium.zip",
76+
"machine_hall/MH_04_difficult/MH_04_difficult.zip",
77+
"machine_hall/MH_05_difficult/MH_05_difficult.zip",
78+
"vicon_room1/V1_01_easy/V1_01_easy.zip",
79+
"vicon_room1/V1_02_medium/V1_02_medium.zip",
80+
"vicon_room1/V1_03_difficult/V1_03_difficult.zip",
81+
"vicon_room2/V2_01_easy/V2_01_easy.zip",
82+
"vicon_room2/V2_02_medium/V2_02_medium.zip",
83+
"vicon_room2/V2_03_difficult/V2_03_difficult.zip",
84+
]
85+
86+
# Make destination folder if it doesn't exist already
87+
ds_path = os.path.join(dst_dir, "euroc2")
88+
os.makedirs(ds_path, exist_ok=True)
89+
90+
# Download sequences
91+
for seq in seqs:
92+
download(os.path.join(base_url, seq), ds_path)
93+
94+
seq_name = os.path.basename(seq).replace(".zip", "")
95+
seq_name = seq_name.replace("_easy", "")
96+
seq_name = seq_name.replace("_medium", "")
97+
seq_name = seq_name.replace("_difficult", "")
98+
seq_dir = os.path.join(ds_path, seq_name)
99+
os.makedirs(seq_dir, exist_ok=True)
100+
101+
zip_file = os.path.join(ds_path, os.path.basename(seq))
102+
extract_zip(zip_file, seq_dir)
103+
104+
105+
def download_euroc_rosbags(dst_dir):
106+
""" Download EuRoC MAV ROS bags """
107+
base_url = "http://robotics.ethz.ch/~asl-datasets/ijrr_euroc_mav_dataset"
108+
bags = [
109+
"machine_hall/MH_01_easy/MH_01_easy.bag",
110+
"machine_hall/MH_02_easy/MH_02_easy.bag",
111+
"machine_hall/MH_03_medium/MH_03_medium.bag",
112+
"machine_hall/MH_04_difficult/MH_04_difficult.bag",
113+
"machine_hall/MH_05_difficult/MH_05_difficult.bag",
114+
"machine_hall/MH_01_easy/MH_01_easy.bag",
115+
"machine_hall/MH_02_easy/MH_02_easy.bag",
116+
"machine_hall/MH_03_medium/MH_03_medium.bag",
117+
"machine_hall/MH_04_difficult/MH_04_difficult.bag",
118+
"machine_hall/MH_05_difficult/MH_05_difficult.bag",
119+
"vicon_room1/V1_01_easy/V1_01_easy.bag",
120+
"vicon_room1/V1_02_medium/V1_02_medium.bag",
121+
"vicon_room1/V1_03_difficult/V1_03_difficult.bag",
122+
"vicon_room2/V2_01_easy/V2_01_easy.bag",
123+
"vicon_room2/V2_02_medium/V2_02_medium.bag",
124+
"vicon_room2/V2_03_difficult/V2_03_difficult.bag",
125+
]
126+
127+
# Make destination folder if it doesn't exist already
128+
ds_path = os.path.join(dst_dir, "euroc")
129+
os.makedirs(ds_path, exist_ok=True)
130+
131+
# Download sequences
132+
for bag in bags:
133+
download(os.path.join(base_url, bag), ds_path)
134+
135+
old_bag_path = os.path.join(ds_path, bag_name)
136+
new_bag_path = old_bag_path.replace("_easy", "")
137+
new_bag_path = new_bag_path.replace("_medium", "")
138+
new_bag_path = new_bag_path.replace("_difficult", "")
139+
os.rename(old_bag_path, new_bag_path)
140+
141+
################################################################################
142+
# KITTI ODOMETRY DATASET
143+
################################################################################
144+
145+
146+
def download_kitti_odometry(dst_dir):
147+
""" Download KITTI Odometry Dataset """
148+
kitti_url = "https://s3.eu-central-1.amazonaws.com/avg-kitti"
149+
sequences = [
150+
"data_odometry_calib.zip", "data_odometry_gray.zip",
151+
"data_odometry_poses.zip"
152+
]
153+
154+
# Make destination folder if it doesn't exist already
155+
ds_path = os.path.join(dst_dir, "kitti_odometry")
156+
os.makedirs(ds_path, exist_ok=True)
157+
158+
# Download sequence
159+
for seq in sequences:
160+
url = f"{kitti_url}/{seq}"
161+
url_dst = f"{ds_path}/{seq}"
162+
download(url, url_dst)
163+
extract_zip(url_dst, ds_path)
164+
165+
166+
################################################################################
167+
# KITTI RAW DATASET
168+
################################################################################
169+
170+
171+
def download_kitti_raw(dst_dir):
172+
# download_path = "/data/kitt_raw"
173+
kitti_url = "https://s3.eu-central-1.amazonaws.com/avg-kitti/raw_data"
174+
sequences = [
175+
"2011_09_26_calib.zip", "2011_09_26_drive_0001", "2011_09_26_drive_0002",
176+
"2011_09_26_drive_0005", "2011_09_26_drive_0009", "2011_09_26_drive_0011",
177+
"2011_09_26_drive_0013", "2011_09_26_drive_0014", "2011_09_26_drive_0015",
178+
"2011_09_26_drive_0017", "2011_09_26_drive_0018", "2011_09_26_drive_0019",
179+
"2011_09_26_drive_0020", "2011_09_26_drive_0022", "2011_09_26_drive_0023",
180+
"2011_09_26_drive_0027", "2011_09_26_drive_0028", "2011_09_26_drive_0029",
181+
"2011_09_26_drive_0032", "2011_09_26_drive_0035", "2011_09_26_drive_0036",
182+
"2011_09_26_drive_0039", "2011_09_26_drive_0046", "2011_09_26_drive_0048",
183+
"2011_09_26_drive_0051", "2011_09_26_drive_0052", "2011_09_26_drive_0056",
184+
"2011_09_26_drive_0057", "2011_09_26_drive_0059", "2011_09_26_drive_0060",
185+
"2011_09_26_drive_0061", "2011_09_26_drive_0064", "2011_09_26_drive_0070",
186+
"2011_09_26_drive_0079", "2011_09_26_drive_0084", "2011_09_26_drive_0086",
187+
"2011_09_26_drive_0087", "2011_09_26_drive_0091", "2011_09_26_drive_0093",
188+
"2011_09_26_drive_0095", "2011_09_26_drive_0096", "2011_09_26_drive_0101",
189+
"2011_09_26_drive_0104", "2011_09_26_drive_0106", "2011_09_26_drive_0113",
190+
"2011_09_26_drive_0117", "2011_09_26_drive_0119", "2011_09_28_calib.zip",
191+
"2011_09_28_drive_0001", "2011_09_28_drive_0002", "2011_09_28_drive_0016",
192+
"2011_09_28_drive_0021", "2011_09_28_drive_0034", "2011_09_28_drive_0035",
193+
"2011_09_28_drive_0037", "2011_09_28_drive_0038", "2011_09_28_drive_0039",
194+
"2011_09_28_drive_0043", "2011_09_28_drive_0045", "2011_09_28_drive_0047",
195+
"2011_09_28_drive_0053", "2011_09_28_drive_0054", "2011_09_28_drive_0057",
196+
"2011_09_28_drive_0065", "2011_09_28_drive_0066", "2011_09_28_drive_0068",
197+
"2011_09_28_drive_0070", "2011_09_28_drive_0071", "2011_09_28_drive_0075",
198+
"2011_09_28_drive_0077", "2011_09_28_drive_0078", "2011_09_28_drive_0080",
199+
"2011_09_28_drive_0082", "2011_09_28_drive_0086", "2011_09_28_drive_0087",
200+
"2011_09_28_drive_0089", "2011_09_28_drive_0090", "2011_09_28_drive_0094",
201+
"2011_09_28_drive_0095", "2011_09_28_drive_0096", "2011_09_28_drive_0098",
202+
"2011_09_28_drive_0100", "2011_09_28_drive_0102", "2011_09_28_drive_0103",
203+
"2011_09_28_drive_0104", "2011_09_28_drive_0106", "2011_09_28_drive_0108",
204+
"2011_09_28_drive_0110", "2011_09_28_drive_0113", "2011_09_28_drive_0117",
205+
"2011_09_28_drive_0119", "2011_09_28_drive_0121", "2011_09_28_drive_0122",
206+
"2011_09_28_drive_0125", "2011_09_28_drive_0126", "2011_09_28_drive_0128",
207+
"2011_09_28_drive_0132", "2011_09_28_drive_0134", "2011_09_28_drive_0135",
208+
"2011_09_28_drive_0136", "2011_09_28_drive_0138", "2011_09_28_drive_0141",
209+
"2011_09_28_drive_0143", "2011_09_28_drive_0145", "2011_09_28_drive_0146",
210+
"2011_09_28_drive_0149", "2011_09_28_drive_0153", "2011_09_28_drive_0154",
211+
"2011_09_28_drive_0155", "2011_09_28_drive_0156", "2011_09_28_drive_0160",
212+
"2011_09_28_drive_0161", "2011_09_28_drive_0162", "2011_09_28_drive_0165",
213+
"2011_09_28_drive_0166", "2011_09_28_drive_0167", "2011_09_28_drive_0168",
214+
"2011_09_28_drive_0171", "2011_09_28_drive_0174", "2011_09_28_drive_0177",
215+
"2011_09_28_drive_0179", "2011_09_28_drive_0183", "2011_09_28_drive_0184",
216+
"2011_09_28_drive_0185", "2011_09_28_drive_0186", "2011_09_28_drive_0187",
217+
"2011_09_28_drive_0191", "2011_09_28_drive_0192", "2011_09_28_drive_0195",
218+
"2011_09_28_drive_0198", "2011_09_28_drive_0199", "2011_09_28_drive_0201",
219+
"2011_09_28_drive_0204", "2011_09_28_drive_0205", "2011_09_28_drive_0208",
220+
"2011_09_28_drive_0209", "2011_09_28_drive_0214", "2011_09_28_drive_0216",
221+
"2011_09_28_drive_0220", "2011_09_28_drive_0222", "2011_09_28_drive_0225",
222+
"2011_09_29_calib.zip", "2011_09_29_drive_0004", "2011_09_29_drive_0026",
223+
"2011_09_29_drive_0071", "2011_09_29_drive_0108", "2011_09_30_calib.zip",
224+
"2011_09_30_drive_0016", "2011_09_30_drive_0018", "2011_09_30_drive_0020",
225+
"2011_09_30_drive_0027", "2011_09_30_drive_0028", "2011_09_30_drive_0033",
226+
"2011_09_30_drive_0034", "2011_09_30_drive_0072", "2011_10_03_calib.zip",
227+
"2011_10_03_drive_0027", "2011_10_03_drive_0034", "2011_10_03_drive_0042",
228+
"2011_10_03_drive_0047", "2011_10_03_drive_0058"
229+
]
230+
231+
# Make destination folder if it doesn't exist already
232+
ds_path = os.path.join(dst_dir, "kitti_raw")
233+
os.makedirs(ds_path, exist_ok=True)
234+
235+
# Download sequences
236+
for seq in sequences:
237+
url_path = seq if seq[-4:] == ".zip" else f"{seq}/{seq}_sync.zip"
238+
save_path = f"{ds_path}/{url_path}"
239+
# os.makedirs(os.path.dirname(save_path), exist_ok=True)
240+
241+
download(f"{kitti_url}/{url_path}", ds_path)
242+
# extract_zip(save_path, os.path.dirname(save_path))
243+
244+
245+
if __name__ == "__main__":
246+
dst_dir = "/data"
247+
download_euroc_sequences(dst_dir)
248+
# download_euroc_rosbags(dst_dir)
249+
# download_kitti_odometry(dst_dir)
250+
# download_kitti_raw(dst_dir)
251+
pass

0 commit comments

Comments
 (0)