sugartensor.sg_main module

sugartensor.sg_main.sg_arg()[source]

Gets current command line options

Returns:
tf.sg_opt instance that is updated with current commandd line options.
sugartensor.sg_main.sg_arg_def(**kwargs)[source]

Defines command line options

Args:
**kwargs:
key: A name for the option. value : Default value or a tuple of (default value, description).
Returns:
None

For example,

``` # Either of the following two lines will define –n_epoch command line argument and set its default value as 1.

tf.sg_arg_def(n_epoch=1) tf.sg_arg_def(n_epoch=(1, ‘total number of epochs’)) ```

sugartensor.sg_main.sg_context(**kwargs)[source]

Context helper for computational graph building. Makes all elements within the with Block share the parameters.

For example, in the following example, the default value of parameter bn will be set to True in the all layers within the with block.

``` with tf.sg_context(bn=True):

```

Args:
**kwargs:

in_dim: An integer. The size of input dimension, which is set to the last one by default. dim: An integer. The size of output dimension. Has the same value as in_dim by default. 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.. bias: Boolean. If True (Default), biases are added. name: A name for the layer. By default, the function name is assigned. act: A name of activation function. e.g., sigmoid, tanh, etc. reuse: True or None; if True, we go into reuse mode for this layer scope

as well as all sub-scopes; if None, we just inherit the parent scope reuse.
Returns:
None
sugartensor.sg_main.sg_global_step()[source]

Gets global step count

Returns:
A 0-D Tensor.
sugartensor.sg_main.sg_inject(path, mod_name)[source]

Converts all functions in the given Python module to sugar functions so that they can be used in a chainable manner.

Args:
path: A string. Path to the Python module mod_name: A string. The name of the Python module to inject.
Returns:
None
sugartensor.sg_main.sg_inject_func(func)[source]

Converts the function func to a sugar function so that it can be used in a chainable manner.

Args:
func: A function to inject.
Returns:
None
sugartensor.sg_main.sg_input(shape=None, dtype=tf.float32, name=None)[source]

Creates a placeholder.

Args:
shape: A tuple/list of integers. If an integers is given, it will turn to a list. dtype: A data type. Default is float32. name: A name for the placeholder.
Returns:
A wrapped placeholder Tensor.
sugartensor.sg_main.sg_layer_func(func)[source]

Decorates a function func as a sg_layer function.

Args:
func: function to decorate
sugartensor.sg_main.sg_phase()[source]

Gets current training phase

Returns:
A boolean Tensor. If True, it is in the training phase, otherwise inference phase.
sugartensor.sg_main.sg_queue_context(sess=None)[source]

Context helper for queue routines.

Args:
sess: A session to open queues. If not specified, a new session is created.
Returns:
None
sugartensor.sg_main.sg_reuse(tensor, **opt)[source]

Reconstruct computational graph of tensor so all the parameters can be reused and replace its input tensor with opt.input.

Args:

tensor: A Tensor (automatically given by chaining). **opt:

input: A Tensor that will replace the original input tensor.
Returns:
Reconstructed tensor nodes.
sugartensor.sg_main.sg_rnn_layer_func(func)[source]

Decorates function as sg_rnn_layer functions. Args:

func: function to decorate
sugartensor.sg_main.sg_set_infer(sess)[source]

Sets current phase as inference mode

Args:
sess: session to work
Returns:
None
sugartensor.sg_main.sg_set_train(sess)[source]

Set current phase as training mode

Args:
sess: session to work
Returns:
None
sugartensor.sg_main.sg_sugar_func(func)[source]

Decorates a function func so that it can be a sugar function. Sugar function can be used in a chainable manner.

Args:
func: function to decorate
Returns:
A sugar function.