Commit
·
6aea5a9
1
Parent(s):
239854f
extract base dataset files in dataset folder
Browse files- extract_base_dataset.py +45 -0
extract_base_dataset.py
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import argparse
|
3 |
+
import shutil
|
4 |
+
from safe_executor import SafeExecutor
|
5 |
+
import utils
|
6 |
+
|
7 |
+
script_dir = os.path.dirname(__file__)
|
8 |
+
dataset_dir = os.path.join(script_dir, "dataset")
|
9 |
+
annotations_dir = os.path.join(dataset_dir, "annotations")
|
10 |
+
|
11 |
+
def main():
|
12 |
+
parser = argparse.ArgumentParser()
|
13 |
+
supported_resolutions = utils.get_supported_resolutions()
|
14 |
+
str_supported_resolutions = ', '.join(supported_resolutions)
|
15 |
+
parser.add_argument('--from_res', type=str, help=f'Choose available dataset: {str_supported_resolutions}', required=True)
|
16 |
+
|
17 |
+
args = parser.parse_args()
|
18 |
+
if args.from_res not in supported_resolutions:
|
19 |
+
print(f"Unsupported resolution. Supported resolutions are: {str_supported_resolutions}")
|
20 |
+
exit(1)
|
21 |
+
|
22 |
+
paths_to_cleanup = [dataset_dir, annotations_dir, os.path.join(dataset_dir, f'{args.from_res}_images')]
|
23 |
+
|
24 |
+
with SafeExecutor(paths_to_cleanup):
|
25 |
+
if os.path.exists(dataset_dir):
|
26 |
+
print("Dataset folder already created")
|
27 |
+
else:
|
28 |
+
utils.check_and_create_dir(dataset_dir)
|
29 |
+
|
30 |
+
if os.path.exists(annotations_dir):
|
31 |
+
print("Annotations folder already extracted")
|
32 |
+
else:
|
33 |
+
utils.check_and_create_dir(annotations_dir)
|
34 |
+
utils.extract_tar_file(os.path.join(script_dir, 'annotations.tar.gz'), annotations_dir)
|
35 |
+
|
36 |
+
selected_res_dir = os.path.join(dataset_dir, f'{args.from_res}_images')
|
37 |
+
|
38 |
+
if os.path.exists(selected_res_dir):
|
39 |
+
print("Selected resolution already exists")
|
40 |
+
else:
|
41 |
+
utils.check_and_create_dir(selected_res_dir)
|
42 |
+
utils.extract_tar_file(os.path.join(script_dir, f'{args.from_res}_images.tar.gz'), dataset_dir)
|
43 |
+
|
44 |
+
if __name__ == "__main__":
|
45 |
+
main()
|