I have the function below which is used to process an input image using probablityprobability predicted by a CNN network model.
def interp_map(prob, zoom, width, height):
zoom_prob = np.zeros((height, width, prob.shape[2]), dtype=np.float32)
for c in range(prob.shape[2]):
for h in range(height):
for w in range(width):
r0 = h // zoom
r1 = r0 + 1
c0 = w // zoom
c1 = c0 + 1
rt = float(h) / zoom - r0
ct = float(w) / zoom - c0
v0 = rt * prob[r1, c0, c] + (1 - rt) * prob[r0, c0, c]
v1 = rt * prob[r1, c1, c] + (1 - rt) * prob[r0, c1, c]
zoom_prob[h, w, c] = (1 - ct) * v0 + ct * v1
return zoom_prob
At the moment, the method takes around 26-30 secs execution time. I want to reduce it, if possible. The 3 for loops consumes a lot of time, however, not sure how can I reduce it.
Any suggestions on how to optimize it?
Please find the attributesAttributes of the input parameters below:
prob.shape
Out[3]: (66, 66, 13)
width
Out[4]: 480
height
Out[5]: 360
Thank you.
prob.shape
Out[3]: (66, 66, 13)
width
Out[4]: 480
height
Out[5]: 360