Skip to content

Instantly share code, notes, and snippets.

@Borda
Created August 19, 2021 13:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Borda/17a6ace0f7568b4d460bc0c1ce44a852 to your computer and use it in GitHub Desktop.
Save Borda/17a6ace0f7568b4d460bc0c1ce44a852 to your computer and use it in GitHub Desktop.
blog: scale images with multiprocessing
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