sugartensor.sg_layer module¶
-
sugartensor.sg_layer.
sg_aconv
(tensor, opt)[source]¶ Applies a 2-D atrous (or dilated) convolution.
- Args:
tensor: A 4-D Tensor (automatically passed by decorator). opt:
- size: A tuple/list of positive integers of length 2 representing [kernel height, kernel width].
- Can be an integer if both values are the same. If not specified, (3, 3) is set automatically.
- rate: A positive integer. The stride with which we sample input values across
- the height and width dimensions. Default is 2.
in_dim: A positive integer. The size of input dimension. dim: A positive integer. The size of output dimension. pad: Either SAME (Default) or VALID. bias: Boolean. If True, biases are added.
- Returns:
- A Tensor with the same type as tensor.
-
sugartensor.sg_layer.
sg_aconv1d
(tensor, opt)[source]¶ Applies 1-D atrous (or dilated) convolution.
- Args:
tensor: A 3-D Tensor (automatically passed by decorator). opt:
- causal: Boolean. If True, zeros are padded before the time axis such that
- each activation unit doesn’t have receptive neurons beyond the equivalent time step.
- size: A positive integer representing [kernel width]. As a default it is set to 2
- if causal is True, 3 otherwise.
- rate: A positive integer. The stride with which we sample input values across
- the height and width dimensions. Default is 1.
in_dim: A positive integer. The size of input dimension. dim: A positive integer. The size of output dimension. pad: Either SAME (Default) or VALID. bias: Boolean. If True, biases are added.
- Returns:
- A Tensor with the same type as tensor.
-
sugartensor.sg_layer.
sg_bypass
(tensor, opt)[source]¶ Returns the input tensor itself.
- Args:
tensor: A Tensor (automatically passed by decorator). opt:
bn: Boolean. If True, batch normalization is applied. ln: Boolean. If True, layer normalization is applied. dout: A float of range [0, 100). A dropout rate. Default is 0. act: A name of activation function. e.g., sigmoid, tanh, etc.- Returns:
- The same tensor as tensor.
-
sugartensor.sg_layer.
sg_conv
(tensor, opt)[source]¶ Applies a 2-D convolution.
- Args:
tensor: A 4-D Tensor (automatically passed by decorator). opt:
- size: A tuple/list of positive integers of length 2 representing [kernel height, kernel width].
- Can be an integer if both values are the same. If not specified, (3, 3) is set implicitly.
- stride: A tuple/list of positive 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 integer. If the length is a, the stride is [1, a, a, 1]. Default value is [1, 1, 1, 1].
in_dim: A positive integer. The size of input dimension. dim: A positive integer. The size of output dimension. pad: Either SAME (Default) or VALID. bias: Boolean. If True, biases are added.
- Returns:
- A Tensor with the same type as tensor.
-
sugartensor.sg_layer.
sg_conv1d
(tensor, opt)[source]¶ Applies a 1-D convolution.
- Args:
tensor: A 3-D Tensor (automatically passed by decorator). opt:
- size: A positive integer representing [kernel width].
- If not specified, 2 is set implicitly.
- stride: A positive integer. The number of entries by which
- the filter is moved right at each step.
in_dim: A positive integer. The size of input dimension. dim: A positive integer. The size of output dimension. pad: Either SAME (Default) or VALID. bias: Boolean. If True, biases are added.
- Returns:
- A Tensor with the same type as tensor.
-
sugartensor.sg_layer.
sg_dense
(tensor, opt)[source]¶ Applies a full connection.
- Args:
tensor: A 2-D tensor (automatically passed by decorator). opt:
in_dim: An integer. The size of input dimension. dim: An integer. The size of output dimension. bias: Boolean. If True, biases are added.- Returns:
- A Tensor with the same type as tensor.
-
sugartensor.sg_layer.
sg_emb
(**kwargs)[source]¶ Returns a look-up table for embedding.
- kwargs:
name: A name for the layer. emb: A 2-D array (optional).
If None, the resulting tensor should have the shape of [vocabulary size, embedding dimension size]. Note that its first row is filled with 0’s associated with padding.in_dim: A positive integer. The size of input dimension. dim: A positive integer. The size of output dimension. voca_size: A positive integer. The size of vocabulary.
- Returns:
- A 2-D Tensor of float32.
-
sugartensor.sg_layer.
sg_espcn
(tensor, opt)[source]¶ - Applies a 2-D efficient sub pixel convolution.
- (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 4-D Tensor (automatically passed by decorator). opt:
- size: A tuple/list of positive integers of length 2 representing [kernel height, kernel width].
- Can be an integer if both values are the same. If not specified, (3, 3) is set implicitly.
- stride: A tuple/list of positive 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 integer. If the length is a, the stride is [1, a, a, 1]. Default value is [1, 1, 1, 1].
in_dim: A positive integer. The size of input dimension. dim: A positive integer. The size of output dimension. pad: Either SAME (Default) or VALID. bias: Boolean. If True, biases are added. factor: factor to multiply shape by. Default is 2.
- Returns:
- A Tensor with the same type as tensor.
-
sugartensor.sg_layer.
sg_gru
(tensor, opt)[source]¶ Applies a GRU.
- Args:
tensor: A 3-D Tensor (automatically passed by decorator). opt:
in_dim: A positive integer. The size of input dimension. dim: A positive integer. The size of output dimension. bias: Boolean. If True, biases are added. ln: Boolean. If True, layer normalization is applied. init_state: A 2-D Tensor. If None, the initial state is set to zeros. last_only: Boolean. If True, the outputs in the last time step are returned.- Returns:
- A Tensor. If last_only is True, the output tensor has shape [batch size, dim]. Otherwise, [batch size, time steps, dim].
-
sugartensor.sg_layer.
sg_lstm
(tensor, opt)[source]¶ Applies an LSTM.
- Args:
tensor: A 3-D Tensor (automatically passed by decorator). opt:
in_dim: A positive integer. The size of input dimension. dim: A positive integer. The size of output dimension. bias: Boolean. If True, biases are added. ln: Boolean. If True, layer normalization is applied. init_state: A 2-D Tensor. If None, the initial state is set to zeros. last_only: Boolean. If True, the outputs in the last time step are returned.- Returns:
- A Tensor. If last_only is True, the output tensor has shape [batch size, dim]. Otherwise, [batch size, time steps, dim].
-
sugartensor.sg_layer.
sg_rnn
(tensor, opt)[source]¶ Applies a simple rnn.
- Args:
tensor: A 3-D Tensor (automatically passed by decorator). opt:
in_dim: A positive integer. The size of input dimension. dim: A positive integer. The size of output dimension. bias: Boolean. If True, biases are added. ln: Boolean. If True, layer normalization is applied. init_state: A 2-D Tensor. If None, the initial state is set to zeros. last_only: Boolean. If True, the outputs in the last time step are returned.- Returns:
- A Tensor. If last_only is True, the output tensor has shape [batch size, dim]. Otherwise, [batch size, time steps, dim].
-
sugartensor.sg_layer.
sg_upconv
(tensor, opt)[source]¶ Applies a up convolution (or convolution transpose).
- Args:
tensor: A 4-D Tensor (automatically passed by decorator). opt:
- size: A tuple/list of integers of length 2 representing [kernel height, kernel width].
- Can be an integer if both values are the same. If not specified, (4, 4) is set implicitly. Default value is [1, 2, 2, 1].
- stride: A tuple/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 integer. If the length is a, the stride is [1, a, a, 1].
in_dim: A positive integer. The size of input dimension. dim: A positive integer. The size of output dimension. pad: Either SAME (Default) or VALID. bias: Boolean. If True, biases are added.
- Returns:
- A Tensor with the same type as tensor.
-
sugartensor.sg_layer.
sg_upconv1d
(tensor, opt)[source]¶ Applies 1-D a up convolution (or convolution transpose).
- Args:
tensor: A 3-D Tensor (automatically passed by decorator). opt:
size: A positive integer representing [kernel width]. As a default it is set to 4 stride: A positive integer representing stride dimension. As a default it is set to 2 in_dim: A positive integer. The size of input dimension. dim: A positive integer. The size of output dimension. pad: Either SAME (Default) or VALID. bias: Boolean. If True, biases are added.- Returns:
- A Tensor with the same type as tensor.