ZOD-Mini-2D-Road-Scenes / extract_base_dataset.py
yasintuncerr's picture
extract base dataset files in dataset folder
6aea5a9
raw
history blame
1.73 kB
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()