# tf.contrib.layers.stack

<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#L3010-L3062) |

Builds a stack of layers by applying layer repeatedly using stack_args.

    tf.contrib.layers.stack(
        inputs, layer, stack_args, **kwargs
    )

`stack` allows you to repeatedly apply the same operation with different
arguments `stack_args[i]`. For each application of the layer, `stack` creates
a new scope appended with an increasing number. For example:

      y = stack(x, fully_connected, [32, 64, 128], scope='fc')
      # It is equivalent to:

      x = fully_connected(x, 32, scope='fc/fc_1')
      x = fully_connected(x, 64, scope='fc/fc_2')
      y = fully_connected(x, 128, scope='fc/fc_3')

If the `scope` argument is not given in `kwargs`, it is set to
`layer.__name__`, or `layer.func.__name__` (for `functools.partial`
objects). If neither `__name__` nor `func.__name__` is available, the
layers are called with `scope='stack'`.

<br />

<br />

<br />

| ## Args ||
|---|---|
| `inputs` | A `Tensor` suitable for layer. |
| `layer` | A layer with arguments `(inputs, *args, **kwargs)` |
| `stack_args` | A list/tuple of parameters for each call of layer. |
| `**kwargs` | Extra kwargs for the layer. |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| A `Tensor` result of applying the stacked layers. ||

<br />

<br />

<br />

<br />

| ## Raises ||
|---|---|
| `ValueError` | If the op is unknown or wrong. |

<br />