last_conv_w, last_conv_h, n_channels = last_conv_output.shape
upscaled_h = last_conv_h * height_factor
upscaled_w = last_conv_w * width_factor
upsampled_last_conv_output = np.zeros((upscaled_h, upscaled_w, n_channels))
for x in range(0, n_channels, 512):
upsampled_last_conv_output[:, :, x:x+512] = cv2.resize(last_conv_output[:, :, x:x+512], (upscaled_w, upscaled_h), cv2.INTER_CUBIC)
upsampled_last_conv_output.shape
This code right here adds a resized image matrix last_conv_output which initial shape was (7, 7, 2048). What I thought was possible was just to do this operation:
upsampled_last_conv_output = cv2.resize(last_conv_output, (upscaled_w, upscaled_h), cv2.INTER_CUBIC)
But the problem with this is that cv2.resize() can only deal at max with 512 channels. to tackle this I have created a for loop which basically loops every 512 channels at once and adds it to an array upsampled_last_conv_output. For me personally this approach takes ~2.5 s to complete.
Before I came up with the for loop solution I have also tried this method:
upsampled_last_conv_output_1 = cv2.resize(last_conv_output[:, :, :512], (upscaled_w, upscaled_h), cv2.INTER_CUBIC)
upsampled_last_conv_output_2 = cv2.resize(last_conv_output[:, :, 512:1024], (upscaled_w, upscaled_h), cv2.INTER_CUBIC)
upsampled_last_conv_output_3 = cv2.resize(last_conv_output[:, :, 1024:1536], (upscaled_w, upscaled_h), cv2.INTER_CUBIC)
upsampled_last_conv_output_4 = cv2.resize(last_conv_output[:, :, 1536:2048], (upscaled_w, upscaled_h), cv2.INTER_CUBIC)
upsampled_last_conv_output = np.concatenate((upsampled_last_conv_output_1,
upsampled_last_conv_output_2,
upsampled_last_conv_output_3,
upsampled_last_conv_output_4),
axis=2)
This approach takes about ~0.9 s to complete which is way faster than the previous one, but this method looks very not python friendly (because what if we had like 1 mln channels or something like that).
So my question is: Is there a way how could I sort of combine the speed of the second method with the python like approach of the first method, or is there an even better way to deal with this problem?