@@ -0,0 +1,2431 @@
+import argparse%0Aimport better_exceptions%0Afrom pathlib import Path%0Aimport zipfile%0Aimport urllib.request%0A%0A%0Azip_names = %5B%22train_1.zip%22, %22train_2.zip%22, %22train_gt.zip%22, %22valid.zip%22, %22valid_gt.zip%22%5D%0Aurls = %5B%22http://***/train_1.zip%22,%0A        %22http://***/train_2.zip%22,%0A        %22http://***/train_gt.zip%22,%0A        %22http://***/valid.zip%22,%0A        %22http://***/valid_gt.zip%22%5D%0Agt_pwd = b%22***%22%0A%0Adataset_root = Path(__file__).resolve().parent.joinpath(%22dataset%22)%0A%0A%0Adef get_args():%0A    parser = argparse.ArgumentParser(description=%22This script downloads the LAP dataset %22%0A                                                 %22and preprocess for training and evaluation%22,%0A                                     formatter_class=argparse.ArgumentDefaultsHelpFormatter)%0A    subparsers = parser.add_subparsers(help=%22subcommands%22, dest=%22subcommand%22)%0A    subparsers.add_parser(%22download%22, help=%22Downdload the LAP dataset%22)%0A    subparsers.add_parser(%22extract%22, help=%22Unzip the LAP dataset%22)%0A    subparsers.add_parser(%22crop%22, help=%22Crop face regions using dlib%22)%0A    args = parser.parse_args()%0A%0A    return parser, args%0A%0A%0Adef download():%0A    for zip_name, url in zip(zip_names, urls):%0A        local_path = dataset_root.joinpath(zip_name)%0A        urllib.request.urlretrieve(url, str(local_path))%0A%0A%0Adef crop():%0A    pass%0A%0A%0Adef extract():%0A    for zip_name in zip_names:%0A        zip_path = dataset_root.joinpath(zip_name)%0A        password = None%0A%0A        if not zip_path.is_file():%0A            raise RuntimeError(%22%7B%7D was not found. Please download the LAP dataset.%22.format(zip_name))%0A%0A        with zipfile.ZipFile(str(zip_path), %22r%22) as f:%0A%0A            if zip_name in %5B%22train_1.zip%22, %22train_2.zip%22%5D:%0A                extract_path = dataset_root.joinpath(%22train_images%22)%0A            elif zip_name == %22valid.zip%22:%0A                extract_path = dataset_root.joinpath(%22validation_images%22)%0A            else:%0A                extract_path = dataset_root%0A%0A            if zip_name == %22valid_gt.zip%22:%0A                password = gt_pwd%0A%0A            extract_path.mkdir(parents=True, exist_ok=True)  # requires Python 3.5 or above%0A            f.extractall(path=str(extract_path), pwd=password)%0A%0A%0Adef main():%0A    parser, args = get_args()%0A%0A    if args.subcommand == %22download%22:%0A        download()%0A    elif args.subcommand == %22extract%22:%0A        extract()%0A    elif args.subcommand == %22crop%22:%0A        crop()%0A    else:%0A        parser.print_help()%0A%0A%0Aif __name__ == '__main__':%0A    main()%0A

create lap dataset