Created
August 19, 2021 13:33
-
-
Save Borda/17a6ace0f7568b4d460bc0c1ce44a852 to your computer and use it in GitHub Desktop.
blog: scale images with multiprocessing
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 os, tqdm, glob | |
import multiprocessing as mproc | |
ls_images = glob.glob("plant-pathology/train_images/*.jpg") | |
print(f'found images: {len(ls_images)}') | |
def _convert(pimg: str): | |
# it can be replaced by opencv implementation... | |
os.system(f'convert -resize 640 point {pimg} {pimg}') | |
nb_cpu = mproc.cpu_count() | |
pbar = tqdm.tqdm(total=len(ls_images), desc=f"Convert {nb_cpu}CPUs") | |
pool = mproc.Pool(processes=nb_cpu) | |
for _ in pool.imap(_convert, ls_images): | |
pbar.update() | |
pool.close() | |
pool.join() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment