edflow.tf_util module

Summary

Functions:

make_exponential_var

Exponential from \((a, \alpha)\) to \((b, \beta)\) with decay rate decay.

make_linear_var

Linear from \((a, \alpha)\) to \((b, \beta)\), i.e.

make_periodic_step

Returns step within the unit period cycle specified

make_periodic_wrapper

A wrapper to wrap the step variable of a step function into a periodic step variable.

make_staircase_var

param step

\(x\)

make_var

Example

Reference

edflow.tf_util.make_linear_var(step, start, end, start_value, end_value, clip_min=None, clip_max=None, **kwargs)[source]

Linear from \((a, \alpha)\) to \((b, \beta)\), i.e. \(y = (\beta - \alpha)/(b - a) * (x - a) + \alpha\)

Parameters
  • step (tf.Tensor) – \(x\)

  • start (int) – \(a\)

  • end (int) – \(b\)

  • start_value (float) – \(\alpha\)

  • end_value (float) – \(\beta\)

  • clip_min (int) – Minimal value returned.

  • clip_max (int) – Maximum value returned.

Returns

:math:`y`

Return type

tf.Tensor

edflow.tf_util.make_periodic_step(step, start_step: int, period_duration_in_steps: int, **kwargs)[source]

Returns step within the unit period cycle specified

Parameters
  • step (tf.Tensor) – step variable

  • start_step (int) – an offset parameter specifying when the first period begins

  • period_duration_in_steps (int) – period duration of step

Returns

step within unit cycle period

Return type

unit_step

edflow.tf_util.make_exponential_var(step, start, end, start_value, end_value, decay, **kwargs)[source]

Exponential from \((a, \alpha)\) to \((b, \beta)\) with decay rate decay.

Parameters
  • step (tf.Tensor) – \(x\)

  • start (int) – \(a\)

  • end (int) – \(b\)

  • start_value (float) – \(\alpha\)

  • end_value (float) – \(\beta\)

  • decay (int) – Decay rate

Returns

:math:`y`

Return type

tf.Tensor

edflow.tf_util.make_staircase_var(step, start, start_value, step_size, stair_factor, clip_min=0.0, clip_max=1.0, **kwargs)[source]
Parameters
  • step (tf.Tensor) – \(x\)

  • start (int) – \(a\)

  • start_value (float) – \(\alpha\)

  • step_size (int) – after how many steps the value should be changed

  • stair_factor (float) – factor that the value is multiplied with at every ‘step_size’ steps

  • clip_min (int) – Minimal value returned.

  • clip_max (int) – Maximum value returned.

Returns

:math:`y`

Return type

tf.Tensor

edflow.tf_util.make_periodic_wrapper(step_function)[source]

A wrapper to wrap the step variable of a step function into a periodic step variable. :param step_function: the step function where to exchange the step variable with a periodic step variable :type step_function: callable

Returns

Return type

a function with periodic steps

edflow.tf_util.make_var(step, var_type, options)[source]

Example

usage within trainer

grad_weight = make_var(step=self.global_step,
var_type=self.config["grad_weight"]["var_type"],
options=self.config["grad_weight"]["options"])

within yaml file

grad_weight:
  var_type: linear
  options:
    start:      50000
    end:        60000
    start_value:  0.0
    end_value: 1.0
    clip_min: 1.0e-6
    clip_max: 1.0
Parameters
  • step (tf.Tensor) – scalar tensor variable

  • var_type (str) – a string from [“linear”, “exponential”, “staircase”]

  • options (dict) – keyword arguments passed to specific ‘make_xxx_var’ function

Returns

:math:`y`

Return type

tf.Tensor