-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [docs] Update citation * [feat] Add multi-processing downloading --------- Co-authored-by: Anton Okhotnikov <[email protected]>
- Loading branch information
1 parent
c7c7073
commit e0f066c
Showing
5 changed files
with
74 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#!/usr/bin/env python3 | ||
import argparse | ||
import multiprocessing as mp | ||
import os | ||
import subprocess as sp | ||
from functools import partial | ||
from pathlib import Path | ||
|
||
from tqdm import tqdm | ||
|
||
|
||
def load_json(json_path, dataset_root, load_script_path): | ||
try: | ||
status = sp.run(["python3", load_script_path, str(json_path), dataset_root]) | ||
return status | ||
except Exception as e: | ||
print(f'Error while loading channel {json_path}') | ||
print(f'Exception: {str(e)}') | ||
|
||
|
||
def main(dataset_root, nj=1): | ||
# Define default variables | ||
fwd = os.path.dirname(os.path.realpath(__file__)) | ||
meta_path = Path(f'{fwd}/../resources/meta') | ||
json_paths = sorted(list(meta_path.glob('*.json'))) | ||
path_to_download_script = f'{fwd}/load_example.py' | ||
|
||
# Run downloading | ||
load_job = partial( | ||
load_json, | ||
dataset_root=dataset_root, | ||
load_script_path=path_to_download_script | ||
) | ||
|
||
# with mp.Pool(nj) as pool: | ||
# _ = pool.imap( | ||
# load_job, tqdm(json_paths, total=len(json_paths)) | ||
# ) | ||
|
||
with tqdm(total=len(json_paths)) as pb: | ||
with mp.Pool(nj) as pool: | ||
for _ in pool.imap(load_job, json_paths): | ||
pb.update() | ||
|
||
print(f'Finished loading! Please check {dataset_root}') | ||
|
||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser( | ||
formatter_class=argparse.ArgumentDefaultsHelpFormatter | ||
) | ||
parser.add_argument('-r', '--dataset_root', help='Path to store loaded data', | ||
required=True, type=str) | ||
parser.add_argument('-j', '--njobs', help='Number of parallel jobs to run', | ||
default=1, type=int, required=False) | ||
args = parser.parse_args() | ||
main(args.dataset_root, args.njobs) |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters