Created
August 14, 2021 00:37
-
-
Save AranKomat/30335ba79629a9352cc477c1e2cbc291 to your computer and use it in GitHub Desktop.
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
import argparse | |
import os | |
import json | |
import multiprocessing | |
from glob import glob | |
from os.path import join | |
from tqdm.contrib.concurrent import process_map | |
parser = argparse.ArgumentParser() | |
parser.add_argument('--data_path', default='') | |
args = parser.parse_args() | |
dirs = [join(args.data_path, f) for f in os.listdir(args.data_path) if os.path.isdir(join(args.data_path, f))] | |
def fun(dir): | |
files = [join(dir, f) for f in os.listdir(dir) if os.path.isfile(join(dir, f))] | |
return files | |
#with multiprocessing.Pool(processes=os.cpu_count()) as pool: | |
results = process_map(fun, dirs, max_workers=os.cpu_count()) | |
new_results = [] | |
for d in results: | |
new_results += d | |
with open("./index.json", 'w') as f: | |
json.dump(new_results, f, indent=4) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment