sugartensor.sg_transform module

sugartensor.sg_transform.sg_all(tensor, opt)[source]

Computes the “logical and” of elements across axis of a tensor.

See tf.reduce_all() in tensorflow.

Args:

tensor: A Tensor (automatically given by chain). opt:

axis : A tuple/list of integers or an integer. The axis to reduce. keep_dims: If true, retains reduced dimensions with length 1. name: If provided, replace current tensor’s name.
Returns:
A Tensor.
sugartensor.sg_transform.sg_any(tensor, opt)[source]

Computes the “logical or” of elements across axis of a tensor.

See tf.reduce_any() in tensorflow.

Args:

tensor: A Tensor (automatically given by chain). opt:

axis : A tuple/list of integers or an integer. The axis to reduce. keep_dims: If true, retains reduced dimensions with length 1. name: If provided, replace current tensor’s name.
Returns:
A Tensor.
sugartensor.sg_transform.sg_argmax(tensor, opt)[source]

Returns the indices of the maximum values along the specified axis.

See tf.argmax() in tensorflow.

Args:

tensor: A Tensor (automatically given by chain). opt:

axis: Target axis. Default is the last one. name: If provided, replace current tensor’s name.
Returns:
A Tensor.
sugartensor.sg_transform.sg_argmin(tensor, opt)[source]

Returns the indices of the minimum values along the specified axis.

See tf.argin() in tensorflow.

Args:

tensor: A Tensor (automatically given by chain). opt:

axis: Target axis. Default is the last one. name: If provided, replace current tensor’s name.
Returns:
A Tensor.
sugartensor.sg_transform.sg_cast(tensor, opt)[source]

Casts a tensor to a new type.

See tf.cast() in tensorflow.

Args:

tensor: A Tensor or SparseTensor (automatically given by chain). opt:

dtype : The destination type. name : If provided, it replaces current tensor’s name
Returns:
A Tensor or SparseTensor with same shape as tensor.
sugartensor.sg_transform.sg_concat(tensor, opt)[source]

Concatenates tensors along a axis.

See tf.concat() in tensorflow.

Args:

tensor: A Tensor (automatically given by chain). opt:

target: A Tensor. Must have the same rank as tensor, and
all dimensions except opt.dim must be equal.

axis : Target axis. Default is the last one. name: If provided, replace current tensor’s name.

Returns:
A Tensor.
sugartensor.sg_transform.sg_expand_dims(tensor, opt)[source]

Inserts a new axis.

See tf.expand_dims() in tensorflow.

Args:

tensor: A Tensor (automatically given by chain). opt:

axis : Dimension to expand. Default is -1. name: If provided, it replaces current tensor’s name.
Returns:
A Tensor.
sugartensor.sg_transform.sg_flatten(tensor, opt)[source]

Reshapes a tensor to batch_size x -1.

See tf.reshape() in tensorflow.

Args:

tensor: A Tensor (automatically given by chain). opt:

name: If provided, it replaces current tensor’s name.
Returns:
A 2-D tensor.
sugartensor.sg_transform.sg_float(tensor, opt)[source]

Casts a tensor to floatx.

See tf.cast() in tensorflow.

Args:

tensor: A Tensor or SparseTensor (automatically given by chain). opt:

name : If provided, it replaces current tensor’s name
Returns:
A Tensor or SparseTensor with same shape as tensor.
sugartensor.sg_transform.sg_identity(tensor, opt)[source]

Returns the same tensor

Args:

tensor: A Tensor (automatically given by chain). opt:

name : If provided, it replaces current tensor’s name
Returns:
A Tensor. Has the same content as tensor.
sugartensor.sg_transform.sg_int(tensor, opt)[source]

Casts a tensor to intx.

See tf.cast() in tensorflow.

Args:

tensor: A Tensor or SparseTensor (automatically given by chain). opt:

name: If provided, it replaces current tensor’s name.
Returns:
A Tensor or SparseTensor with same shape as tensor.
sugartensor.sg_transform.sg_inverse_periodic_shuffle(tensor, opt)[source]
Inverse periodic shuffle transformation for SubPixel CNN.
(see [Shi et al. 2016](http://www.cv-foundation.org/openaccess/content_cvpr_2016/papers/Shi_Real-Time_Single_Image_CVPR_2016_paper.pdf)
Args:

tensor: A tensor (automatically given by chain). opt:

factor: factor to multiply shape by. Default is 2. name : If provided, it replaces current tensor’s name.
Returns:
A tensor
sugartensor.sg_transform.sg_lookup(tensor, opt)[source]

Looks up the tensor, which is the embedding matrix.

Args:

tensor: A tensor ( automatically given by chain ) opt:

emb: A 2-D Tensor. An embedding matrix. name: If provided, replace current tensor’s name.
Returns:
A Tensor.
sugartensor.sg_transform.sg_max(tensor, opt)[source]

Computes the maximum of elements across axis of a tensor.

See tf.reduce_max() in tensorflow.

Args:

tensor: A Tensor (automatically given by chain). opt:

axis : A tuple/list of integers or an integer. The axis to reduce. keep_dims: If true, retains reduced dimensions with length 1. name: If provided, replace current tensor’s name.
Returns:
A Tensor.
sugartensor.sg_transform.sg_mean(tensor, opt)[source]

Computes the mean of elements across axis of a tensor.

See tf.reduce_mean() in tensorflow.

Args:

tensor: A Tensor (automatically given by chain). opt:

axis : A tuple/list of integers or an integer. The axis to reduce. keep_dims: If true, retains reduced dimensions with length 1. name: If provided, replace current tensor’s name.
Returns:
A Tensor.
sugartensor.sg_transform.sg_min(tensor, opt)[source]

Computes the minimum of elements across axis of a tensor.

See tf.reduce_min() in tensorflow.

Args:

tensor: A Tensor (automatically given by chain). opt:

axis : A tuple/list of integers or an integer. The axis to reduce. keep_dims: If true, retains reduced dimensions with length 1. name: If provided, replace current tensor’s name.
Returns:
A Tensor.
sugartensor.sg_transform.sg_one_hot(tensor, opt)[source]

Converts a tensor into a one-hot tensor.

See tf.one_hot() in tensorflow.

Args:

tensor: A Tensor ( automatically given by chain ) opt:

depth: The number of classes. name: If provided, replace current tensor’s name.
Returns:
A Tensor.
sugartensor.sg_transform.sg_periodic_shuffle(tensor, opt)[source]
Periodic shuffle transformation for SubPixel CNN.
(see [Shi et al. 2016](http://www.cv-foundation.org/openaccess/content_cvpr_2016/papers/Shi_Real-Time_Single_Image_CVPR_2016_paper.pdf)
Args:

tensor: A tensor (automatically given by chain). opt:

factor: factor to multiply shape by. Default is 2. name : If provided, it replaces current tensor’s name.
Returns:
A tensor
sugartensor.sg_transform.sg_pool(tensor, opt)[source]

Performs the 2-D pooling on the tensor. Mostly used with sg_conv().

Args:

tensor: A 4-D Tensor (automatically given by chain). opt:

size: A tuple or list of integers of length 2 representing [kernel height, kernel width].
Can be an int if both values are the same. If not specified, (2, 2) is set implicitly.
stride: A tuple or list of integers of length 2 or 4 representing stride dimensions.
If the length is 2, i.e., (a, b), the stride is [1, a, b, 1]. If the length is 4, i.e., (a, b, c, d), the stride is [a, b, c, d]. Can be an int. If the length is an int, i.e., a, the stride is [1, a, a, 1]. The default value is [1, 1, 1, 1].

avg: Boolean. If True, average pooling is applied. Otherwise, max pooling. name: If provided, replace current tensor’s name.

Returns:
A Tensor. The max pooled output tensor.
sugartensor.sg_transform.sg_pool1d(tensor, opt)[source]

Performs the 1-D pooling on the tensor.

Args:

tensor: A 3-D Tensor (automatically passed by decorator). opt:

size: A positive integer representing [kernel width].
Default is 2.
stride: A positive integer. The number of entries by which
the filter is moved right at each step. Default is 2.

avg: Boolean. If True, average pooling is applied. Otherwise, max pooling. name: If provided, replace current tensor’s name.

Returns:
A tensor
sugartensor.sg_transform.sg_prod(tensor, opt)[source]

Computes the product of elements across axis of a tensor.

See tf.reduce_prod() in tensorflow.

Args:

tensor: A Tensor (automatically given by chain). opt:

axis : A tuple/list of integers or an integer. The axis to reduce. keep_dims: If true, retains reduced dimensions with length 1. name: If provided, replace current tensor’s name.
Returns:
A Tensor.
sugartensor.sg_transform.sg_reshape(tensor, opt)[source]

Reshapes a tensor.

See tf.reshape() in tensorflow.

Args:

tensor: A Tensor (automatically given by chain). opt:

shape: A tuple/list of integers. The destination shape. name: If provided, replace current tensor’s name.
Returns:
A Tensor.
sugartensor.sg_transform.sg_reverse_seq(tensor, opt)[source]

Reverses variable length slices.

Before applying the pure tensorflow function tf.reverse_sequence,
this function calculates sequence lengths by counting non-zeros.

For example,

``` tensor = [[1, 2, 3, 0, 0], [4, 5, 0, 0, 0]] tensor.sg_reverse_seq() => [[3 2 1 0 0]

[5 4 0 0 0]]

```

Args:

tensor: A 2-D Tensor (automatically given by chain). opt:

axis: Axis to reverse. Default is 1. name : If provided, it replaces current tensor’s name.
Returns:
A Tensor with the same shape and type as tensor.
sugartensor.sg_transform.sg_squeeze(tensor, opt)[source]

Removes axis of size 1 from the shape of a tensor.

See tf.squeeze() in tensorflow.

Args:

tensor: A Tensor (automatically given by chain). opt:

axis : A tuple/list of integers or an integer.
axis to remove. Default is -1.

name: If provided, it replaces current tensor’s name.

Returns:
A Tensor.
sugartensor.sg_transform.sg_sum(tensor, opt)[source]

Computes the sum of elements across axis of a tensor.

See tf.reduce_sum() in tensorflow.

Args:

tensor: A Tensor with zero-padding (automatically given by chain). opt:

axis: A tuple/list of integers or an integer. The axis to reduce. keep_dims: If true, retains reduced dimensions with length 1. name: If provided, replace current tensor’s name.
Returns:
A Tensor.
sugartensor.sg_transform.sg_to_sparse(tensor, opt)[source]

Converts a dense tensor into a sparse tensor.

See tf.SparseTensor() in tensorflow.

Args:

tensor: A Tensor with zero-padding (automatically given by chain). opt:

name: If provided, replace current tensor’s name.
Returns:
A SparseTensor.
sugartensor.sg_transform.sg_transpose(tensor, opt)[source]

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.