How to speed up my forecasting task

I am currently working on a U-net implementation in keras based on: Lung Segmentation

I am working on very large images (~ 20,000 * ~ 20,000) and am getting a probability map for the whole image. I am using 256 * 256 patches.

I am currently doing the following:

UNet = load_model(model_name)

for posX in range(0,im.level_dimensions[level][0]-256,stride):
    for posY in range(0,im.level_dimensions[level][1]-256,stride):

        xx = np.expand_dims(imload[posY:posY+256,posX:posX+256,:],0)
        yy = maskload[posY:posY+256,posX:posX+256,:]

        #The following line is the bottleneck
        pred = UNet.predict(xx)[..., 0].reshape(patchShape[:2])

        #Reconstruct the probability map
        part=outputProba[posY:posY+256,posX:posX+256]
        part[:,:]+=pred[0:part.shape[0],0:part.shape[1]]
        outputProbaTimes[posY:posY+256,posX:posX+256]+=1

      

This piece of code takes about 1 minute to execute, with an increment set to 256. I would do it in increments of 64, but it takes ~ 16 minutes.

I am new to keras and Deep Learning and I would like to know if anyone has any smart advice to speed up this code.

I looked around to use pred_generator. It would be great because it could use multiprocessing. But I don't understand the meaning of data generation when predicting.

Thank you for your help!

ps: code works on nvidia GTX 1080

ps2: UNet.predict is a prediction from keras

+3


source to share





All Articles