Skip to content

Instantly share code, notes, and snippets.

@sharkdeng
Last active October 14, 2020 08:45
Show Gist options
  • Save sharkdeng/d3bb488a3d224f0788f66b961a33c9c1 to your computer and use it in GitHub Desktop.
Save sharkdeng/d3bb488a3d224f0788f66b961a33c9c1 to your computer and use it in GitHub Desktop.
use multiprocessing to speed up
# you have run this code in .py file (cannot be in .ipynb)
# you have to add the head `if __name__ == '__main__':`
if __name__ == '__main__':
start = time.time()
img_ids = df.image_id.values # a list
pool = Pool(processes=multiprocessing.cpu_count())
pool.map(crop_all_img, img_ids) # (function, list)
delta = time.time() - start
print(f'Used time: {delta}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment