# tf.contrib.layers.spatial_softmax

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/contrib/layers/python/layers/layers.py#L2913-L3007) |

Computes the spatial softmax of a convolutional feature map.

    tf.contrib.layers.spatial_softmax(
        features, temperature=None, name=None, variables_collections=None,
        trainable=True, data_format='NHWC'
    )

First computes the softmax over the spatial extent of each channel of a
convolutional feature map. Then computes the expected 2D position of the
points of maximal activation for each channel, resulting in a set of
feature keypoints \[i1, j1, ... iN, jN\] for all N channels.

#### Read more here:

"Learning visual feature spaces for robotic manipulation with
deep spatial autoencoders." Finn et al., <http://arxiv.org/abs/1509.06113>

<br />

<br />

<br />

| ## Args ||
|---|---|
| `features` | A `Tensor` of size \[batch_size, W, H, num_channels\]; the convolutional feature map. |
| `temperature` | Softmax temperature (optional). If None, a learnable temperature is created. |
| `name` | A name for this operation (optional). |
| `variables_collections` | Collections for the temperature variable. |
| `trainable` | If `True` also add variables to the graph collection `GraphKeys.TRAINABLE_VARIABLES` (see [`tf.Variable`](https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/Variable)). |
| `data_format` | A string. `NHWC` (default) and `NCHW` are supported. |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| `feature_keypoints` | A `Tensor` with size \[batch_size, num_channels \* 2\]; the expected 2D locations of each channel's feature keypoint (normalized to the range (-1,1)). The inner dimension is arranged as \[i1, j1, ... iN, jN\]. |

<br />

<br />

<br />

<br />

| ## Raises ||
|---|---|
| `ValueError` | If unexpected data_format specified. |
| `ValueError` | If num_channels dimension is unspecified. |

<br />