def sg_transpose(tensor, opt):
    r"""Permutes the dimensions according to `opt.perm`.

    See `tf.transpose()` in tensorflow.

    Args:
      tensor: A `Tensor` (automatically given by chain).
      opt:
        perm: A permutation of the dimensions of `tensor`. The target shape.
        name: If provided, replace current tensor's name.

    Returns:
      A `Tensor`.
    """
    assert opt.perm is not None, 'perm is mandatory'
    return tf.transpose(tensor, opt.perm, name=opt.name)