-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPrepare_A03.py
38 lines (28 loc) · 1.11 KB
/
Prepare_A03.py
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
import requests
import os
import pandas as pd
import shutil
import zipfile
from pathlib import Path
def download_file(file_url, output_dir, output_filename):
r = requests.get(file_url, stream=True, verify=True)
save_path = os.path.join(output_dir, output_filename)
with open(save_path,'wb') as f:
for chunk in r.iter_content(chunk_size=1024):
if chunk:
f.write(chunk)
def unzip_file(zip_file, out_folder):
with zipfile.ZipFile(zip_file, 'r') as zip_ref:
zip_ref.extractall(out_folder)
def main():
dog_url = "https://huggingface.co/datasets/l-lt/LaSOT/resolve/main/dog.zip"
zip_filename = "dog.zip"
data_dir = os.path.join(".", "data")
os.makedirs(data_dir, exist_ok=True)
download_file(dog_url, data_dir, zip_filename)
out_data_dir = os.path.join(data_dir, Path(zip_filename).stem)
full_zip_path = os.path.join(data_dir, zip_filename)
unzip_file(full_zip_path, out_data_dir)
os.remove(os.path.join(data_dir, zip_filename))
if __name__ == "__main__":
main()