Last active
February 17, 2018 18:09
-
-
Save Hiroshiba/60985d79d32815b1bc4c2ea6ba94c98b to your computer and use it in GitHub Desktop.
numpy file validation
This file contains hidden or 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 glob | |
import multiprocessing | |
import numpy | |
import tqdm | |
parser = argparse.ArgumentParser() | |
parser.add_argument('glob') | |
parser.add_argument('--processes', type=int) | |
args = parser.parse_args() | |
def try_load(p): | |
try: | |
numpy.load(p, mmap_mode='r') | |
except: | |
return p | |
if __name__ == '__main__': | |
pool = multiprocessing.Pool(processes=args.processes) | |
paths_input = list(glob.glob(args.glob)) | |
paths_invalid = list(tqdm.tqdm(pool.imap(try_load, paths_input), total=len(paths_input))) | |
for path in paths_invalid: | |
if path is None: | |
continue | |
print(path) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment