I have a lot of PNG images that I want to classify, using a trained CNN model.
To speed up the process, I would like to use multiple-processing with CPUs (I have 72 avai
One python package I know that may help you is joblib
. Hope it can solve your problem.
from joblib import Parallel, delayed
# load model
mymodel = load_model('190704_1_fcs_plotclassifier.h5')
# Define callback function to collect the output in 'outcomes'
outcomes = []
def collect_result(result):
global outcomes
outcomes.append(result)
# Define prediction function
def prediction(img):
img = cv2.resize(img,(49,49))
img = img.astype('float32') / 255
img = np.reshape(img,[1,49,49,3])
status = mymodel.predict(img)
status = status[0][1]
return(status)
# Define evaluate function
def evaluate(i,figure):
# predict the propability of the picture to be in class 0 or 1
img = cv2.imread(figure)
status = prediction(img)
outcome = [figure, status]
return(i,outcome)
outcomes = Parallel(n_jobs=72)(delayed(evaluate)(i,figure) for figure in listoffigurepaths)