Reputation: 21
Good afternoon, I have a convolutional neural network to perform pixelwise classification with 6 classes of a batch of images. I would like to apply superpixel algorithm (the one in opencv) to the output of the network. Actually, the superpixels would be calculated from the input images, and then for every of these superpixel locations in the network output, I would compute the mode of the output classes, in order to have the same output class for every superpixel of the input image. Since the output of the network during a feedforward pass is a [batch, w, h, 6] size tensor, I was thinking to reshape the tensor to [batch*w, h, 6] and then to iterate for every class (for i in range(6)) and compute the mode of that class for every superpixel and then reshape back to the original size.
What I would code in a numpy-based script should be something like:
for i in range ( number of superpixels):
for j in range(number of classes=6):
mask = superpixel_location[i]
net_new_output[:,:,j][mask] = mode(net_output[:,:,j][mask])
Although this is definitely easy to code in numpy, I am having issues trying to executing it in tensorflow, since I do not know how to implement for loops or how to manage them.
Can you help me out?
Thank you,
MC
Upvotes: 1
Views: 285