Let's say I have an images
array that holds 100,000 images with 3 channels.
images = np.random.randint(0,255,(100000,32,32,3))
And I have a function foo
which accepts an image and performs some operation on it.
def foo(img):
#some operation on the image, say histogram equalization
How do I now apply the foo
function to 100000 images in parallel? I thought numpy would have some function for this purpose, but I was disappointed to not find any. I found numpy.apply_along_axis
but I read it is rather iterative. What should I do?
Here is an example, using
joblib
which performs histogram equalization on the images, in parallel withn_jobs
equal tonprocs
(here 10 processes but you can change as per your need)