Per pixel softmax for full convolution network

I am trying to implement something like a fully convolutional network where the last convolution layer uses a 1x1 filter size and displays the 'score' tensor. The rating tensor has the form [Lot, height, width, num_classes].

My question is which function in tensorflow can apply the softmax operation for each pixel, regardless of the other pixels. The tf.nn.softmax operations do not seem to be for this purpose.

If there are no such options, I think I should write it myself.

Thanks!

UPDATE: if I need to realize myself, I think I may need to change the input tensor to [N, num_claees], where N = Batch x width x height, and apply tf.nn.softmax and then change it back, Does it make sense ?

+7
tensorflow image-segmentation softmax
source share
2 answers

Changing the shape to 2d and then changing the shape back, you guessed it, is the right approach.

+3
source share

You can use this function.

I found it by doing a GitHub search.

import tensorflow as tf """ Multi dimensional softmax, refer to https://github.com/tensorflow/tensorflow/issues/210 compute softmax along the dimension of target the native softmax only supports batch_size x dimension """ def softmax(target, axis, name=None): with tf.name_scope(name, 'softmax', values=[target]): max_axis = tf.reduce_max(target, axis, keep_dims=True) target_exp = tf.exp(target-max_axis) normalize = tf.reduce_sum(target_exp, axis, keep_dims=True) softmax = target_exp / normalize return softmax 
+1
source share

All Articles