|
a |
|
b/run/download.py |
|
|
1 |
# python run/download.py |
|
|
2 |
# python run/download.py --dir=path/to/dataset/dir |
|
|
3 |
# python run/download.py --dir=datasets |
|
|
4 |
|
|
|
5 |
import argparse |
|
|
6 |
import tarfile |
|
|
7 |
import gdown |
|
|
8 |
import os |
|
|
9 |
|
|
|
10 |
|
|
|
11 |
def run(dataset_dir="datasets"): |
|
|
12 |
os.makedirs(dataset_dir, exist_ok=True) |
|
|
13 |
|
|
|
14 |
url = 'https://drive.google.com/uc?id=1RzPB1_bqzQhlWvU-YGvZzhx2omcDh38C&export=download' |
|
|
15 |
output_tar = os.path.join(dataset_dir, 'Task04_Hippocampus.tar') |
|
|
16 |
if not os.path.exists(output_tar): |
|
|
17 |
gdown.download(url, output_tar, quiet=False) |
|
|
18 |
else: |
|
|
19 |
print("Output tar {} already exists!".format(output_tar)) |
|
|
20 |
|
|
|
21 |
tar = tarfile.open(output_tar) |
|
|
22 |
tar.extractall(path=dataset_dir) |
|
|
23 |
tar.close() |
|
|
24 |
|
|
|
25 |
|
|
|
26 |
############################ |
|
|
27 |
# MAIN |
|
|
28 |
############################ |
|
|
29 |
if __name__ == "__main__": |
|
|
30 |
parser = argparse.ArgumentParser(description="Download Dataset for Hippocampus Segmentation") |
|
|
31 |
parser.add_argument( |
|
|
32 |
"-D", |
|
|
33 |
"--dir", |
|
|
34 |
default="datasets", type=str, |
|
|
35 |
help="Local path to datasets dir" |
|
|
36 |
) |
|
|
37 |
|
|
|
38 |
args = parser.parse_args() |
|
|
39 |
run(dataset_dir=args.dir) |