I've got a program that loads 2600 images in a loop, does some processing and returns a value. Pseudo code:
for file in files:
codes[file] = my_function(file)
return codes
The problem is - this process takes around 20-30 minutes, and seems to only use one CPU core. I'm looking for a quick and dirty way to run this across more cores, perhaps by splitting the list in two. I've read a bunch about Python and it's problems/solutions, but I can't figure what to do next. How do I do this?
FYI Using Python 2.7 on 2009 Macbook Pro (Core 2 Duo) w/ Numpy Scipy Scikit-image & OpenCV.
The easiest way is with multiprocessing:
from multiprocessing import Pool
with Pool() as p:
all_codes = p.map(my_function, files)
return {f:code for code, f in zip(all_codes, files)}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With