File size: 1,729 Bytes
6aea5a9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
import argparse
import shutil
from safe_executor import SafeExecutor
import utils

script_dir = os.path.dirname(__file__)
dataset_dir = os.path.join(script_dir, "dataset")
annotations_dir = os.path.join(dataset_dir, "annotations")

def main():
    parser = argparse.ArgumentParser()
    supported_resolutions = utils.get_supported_resolutions()
    str_supported_resolutions = ', '.join(supported_resolutions)
    parser.add_argument('--from_res', type=str, help=f'Choose available dataset: {str_supported_resolutions}', required=True)

    args = parser.parse_args()
    if args.from_res not in supported_resolutions:
        print(f"Unsupported resolution. Supported resolutions are: {str_supported_resolutions}")
        exit(1)

    paths_to_cleanup = [dataset_dir, annotations_dir, os.path.join(dataset_dir, f'{args.from_res}_images')]

    with SafeExecutor(paths_to_cleanup):
        if os.path.exists(dataset_dir):
            print("Dataset folder already created")
        else:
            utils.check_and_create_dir(dataset_dir)

        if os.path.exists(annotations_dir):
            print("Annotations folder already extracted")
        else:
            utils.check_and_create_dir(annotations_dir)
            utils.extract_tar_file(os.path.join(script_dir, 'annotations.tar.gz'), annotations_dir)

        selected_res_dir = os.path.join(dataset_dir, f'{args.from_res}_images')    

        if os.path.exists(selected_res_dir):
            print("Selected resolution already exists")
        else:
            utils.check_and_create_dir(selected_res_dir)
            utils.extract_tar_file(os.path.join(script_dir, f'{args.from_res}_images.tar.gz'), dataset_dir)

if __name__ == "__main__":
    main()