sugartensor.sg_train module¶
-
sugartensor.sg_train.
sg_init
(sess)[source]¶ Initializes session variables.
- Args:
- sess: Session to initialize.
-
sugartensor.sg_train.
sg_optim
(loss, **kwargs)[source]¶ Applies gradients to variables.
- Args:
loss: A 0-D Tensor containing the value to minimize. kwargs:
optim: A name for optimizer. ‘MaxProp’ (default), ‘AdaMax’, ‘Adam’, or ‘sgd’. lr: A Python Scalar (optional). Learning rate. Default is .001. beta1: A Python Scalar (optional). Default is .9. beta2: A Python Scalar (optional). Default is .99. category: A string or string list. Specifies the variables that should be trained (optional).
Only if the name of a trainable variable starts with category, it’s value is updated. Default is ‘’, which means all trainable variables are updated.
-
sugartensor.sg_train.
sg_print
(tensor_list)[source]¶ Simple tensor printing function for debugging. Prints the value, shape, and data type of each tensor in the list.
- Args:
- tensor_list: A list/tuple of tensors or a single tensor.
- Returns:
- The value of the tensors.
For example,
`python import sugartensor as tf a = tf.constant([1.]) b = tf.constant([2.]) out = tf.sg_print([a, b]) # Should print [ 1.] (1,) float32 # [ 2.] (1,) float32 print(out) # Should print [array([ 1.], dtype=float32), array([ 2.], dtype=float32)] `
-
sugartensor.sg_train.
sg_restore
(sess, save_path, category='')[source]¶ Restores previously saved variables.
- Args:
- sess: A Session to use to restore the parameters. save_path: Path where parameters were previously saved. category: A String to filter variables starts with given category.
Returns:
-
sugartensor.sg_train.
sg_train
(**kwargs)[source]¶ Trains the model.
- Args:
- **kwargs:
optim: A name for optimizer. ‘MaxProp’ (default), ‘AdaMax’, ‘Adam’, or ‘sgd’. loss: A 0-D Tensor containing the value to minimize. lr: A Python Scalar (optional). Learning rate. Default is .001. beta1: A Python Scalar (optional). Default is .9. beta2: A Python Scalar (optional). Default is .99.
eval_metric: A list of tensors containing the value to evaluate. Default is []. early_stop: Boolean. If True (default), the training should stop when the following two conditions are met.
- Current loss is less than .95 * previous loss.
- Current learning rate is less than 5e-6.
- lr_reset: Boolean. If True, learning rate is set to opt.lr. when training restarts.
- Otherwise (Default), the value of the stored _learning_rate is taken.
- save_dir: A string. The root path to which checkpoint and log files are saved.
- Default is asset/train.
max_ep: A positive integer. Maximum number of epochs. Default is 1000. ep_size: A positive integer. Number of Total batches in an epoch.
For proper display of log. Default is 1e5.- save_interval: A Python scalar. The interval of saving checkpoint files.
- By default, for every 600 seconds, a checkpoint file is written.
- log_interval: A Python scalar. The interval of recoding logs.
- By default, for every 60 seconds, logging is executed.
max_keep: A positive integer. Maximum number of recent checkpoints to keep. Default is 5. keep_interval: A Python scalar. How often to keep checkpoints. Default is 1 hour.
category: Scope name or list to train
tqdm: Boolean. If True (Default), progress bars are shown. console_log: Boolean. If True, a series of loss will be shown
on the console instead of tensorboard. Default is False.