Untitled
unknown
python
2 years ago
1.7 kB
5
Indexable
Never
# autoreload to load change in imported files import numpy as np import os import glob from tqdm import tqdm import sys import time import importlib.util import pandas as pd import multiprocessing as mp import concurrent.futures def create_base_(filename): # setsegmentation path : segpath = filename.replace('_UH.npz','_DL_LREPHY.npz') # prepare target path: dirs = "\\".join(filename.replace(npzpath, Target_folder).split("\\")[:-1]) target_full_path = filename.replace(npzpath, Target_folder) if not os.path.exists(target_full_path): os.makedirs(dirs, exist_ok = True) np.savez_compressed(target_full_path, vol = uh, spacing = spacing, vol_leftlung = left_lung, vol_rightlung = right_lung, origin_z = z_dict) # Estiamte size reduction ratio: before_crop_size, after_crop_size = convert_unit(os.path.getsize(filename)), convert_unit(os.path.getsize(target_full_path)) print("Size reduction ratio : {:.2f} % ".format((after_crop_size/before_crop_size)*100)) print("###########################################################################################") if __name__ == '__main__': patlist = ... #patlist start = time.perf_counter() print("Processors : ", mp.cpu_count()) with concurrent.futures.ProcessPoolExecutor() as executor: executor.map(create_base_, patlist[20469:]) finish = time.perf_counter() print(f'Finished in {round(finish-start,2)} seconds')