LossTrainer

class tfsnippet.LossTrainer(**kwargs)

Bases: tfsnippet.trainer.trainer.Trainer

A subclass of BaseTrainer, which optimizes a single loss.

Attributes Summary

data_flow Get the training data flow.
events Get the event source object.
feed_dict Get the feed dict for training.
inputs Get the input placeholders.
loop Get the training loop object.
loss Get the training loss.
metric_name Get the metric name for collecting training loss.
metrics Get the metrics to be computed along with train_op.
summaries Get the summaries to be computed along with train_op.
train_op Get the training operation.

Methods Summary

anneal_after(value[, epochs, steps]) Add an annealing hook to run after every few epochs or steps.
anneal_after_epochs(value, freq) Add an annealing hook to run after every few epochs.
anneal_after_steps(value, freq) Add an annealing hook to run after every few steps.
evaluate_after(evaluator[, epochs, steps]) Add an evaluation hook to run after every few epochs or steps.
evaluate_after_epochs(evaluator, freq) Add an evaluation hook to run after every few epochs.
evaluate_after_steps(evaluator, freq) Add an evaluation hook to run after every few steps.
log_after([epochs, steps]) Add a logging hook to run after every few epochs or steps.
log_after_epochs(freq) Add a logging hook to run after every few epochs.
log_after_steps(freq) Add a logging hook to run after every few steps.
remove_annealing_hooks() Remove annealing hooks from all lists.
remove_evaluation_hooks() Remove evaluation hooks from all lists.
remove_log_hooks() Remove logging hooks from all lists.
remove_validation_hooks() Remove evaluation hooks from all lists.
run(**kwargs) Run training loop.
validate_after(evaluator[, epochs, steps]) Add an evaluation hook to run after every few epochs or steps.
validate_after_epochs(evaluator, freq) Add an evaluation hook to run after every few epochs.
validate_after_steps(evaluator, freq) Add an evaluation hook to run after every few steps.

Attributes Documentation

data_flow

Get the training data flow.

Returns:The training data flow.
Return type:DataFlow
events

Get the event source object.

Returns:The event source object.
Return type:EventSource
feed_dict

Get the feed dict for training.

Returns:The feed dict for training.
Return type:dict[tf.Tensor, any]
inputs

Get the input placeholders.

Returns:The input placeholders.
Return type:list[tf.Tensor]
loop

Get the training loop object.

Returns:The training loop object.
Return type:TrainLoop
loss

Get the training loss.

metric_name

Get the metric name for collecting training loss.

metrics

Get the metrics to be computed along with train_op.

summaries

Get the summaries to be computed along with train_op.

train_op

Get the training operation.

Methods Documentation

anneal_after(value, epochs=None, steps=None)

Add an annealing hook to run after every few epochs or steps.

Parameters:
  • value (AnnealingVariable or () -> any) – An annealing variable (which has .anneal()), or any callable object.
  • epochs (None or int) – Run validation after every this few epochs.
  • steps (None or int) – Run validation after every this few steps.
Raises:

ValueError – If both epochs and steps are specified, or neither is specified.

anneal_after_epochs(value, freq)

Add an annealing hook to run after every few epochs.

Parameters:
  • value (AnnealingVariable or () -> any) – An annealing variable (which has .anneal()), or any callable object.
  • freq (int) – The frequency for this annealing hook to run.
anneal_after_steps(value, freq)

Add an annealing hook to run after every few steps.

Parameters:
  • value (AnnealingVariable or () -> any) – An annealing variable (which has .anneal()), or any callable object.
  • freq (int) – The frequency for this annealing hook to run.
evaluate_after(evaluator, epochs=None, steps=None)

Add an evaluation hook to run after every few epochs or steps.

Parameters:
  • evaluator (Evaluator or () -> any) – A evaluator object (which has .run()), or any callable object.
  • epochs (None or int) – Run validation after every this few epochs.
  • steps (None or int) – Run validation after every this few steps.
Raises:

ValueError – If both epochs and steps are specified, or neither is specified.

evaluate_after_epochs(evaluator, freq)

Add an evaluation hook to run after every few epochs.

Parameters:
  • evaluator (Evaluator or () -> any) – A evaluator object (which has .run()), or any callable object.
  • freq (int) – The frequency for this evaluation hook to run.
evaluate_after_steps(evaluator, freq)

Add an evaluation hook to run after every few steps.

Parameters:
  • evaluator (Evaluator or () -> any) – A evaluator object (which has .run()), or any callable object.
  • freq (int) – The frequency for this evaluation hook to run.
log_after(epochs=None, steps=None)

Add a logging hook to run after every few epochs or steps.

Parameters:
  • epochs (None or int) – Run validation after every this few epochs.
  • steps (None or int) – Run validation after every this few steps.
Raises:

ValueError – If both epochs and steps are specified, or neither is specified.

log_after_epochs(freq)

Add a logging hook to run after every few epochs.

Parameters:freq (int) – The frequency for this logging hook to run.
log_after_steps(freq)

Add a logging hook to run after every few steps.

Parameters:freq (int) – The frequency for this logging hook to run.
remove_annealing_hooks()

Remove annealing hooks from all lists.

Returns:The number of removed hooks.
Return type:int
remove_evaluation_hooks()

Remove evaluation hooks from all lists.

Returns:The number of removed hooks.
Return type:int
remove_log_hooks()

Remove logging hooks from all lists.

Returns:The number of removed hooks.
Return type:int
remove_validation_hooks()

Remove evaluation hooks from all lists.

Returns:The number of removed hooks.
Return type:int
run(**kwargs)

Run training loop.

Parameters:feed_dict – DEPRECATED. The extra feed dict to be merged with the already configured dict. (default None)
validate_after(evaluator, epochs=None, steps=None)

Add an evaluation hook to run after every few epochs or steps.

Parameters:
  • evaluator (Evaluator or () -> any) – A evaluator object (which has .run()), or any callable object.
  • epochs (None or int) – Run validation after every this few epochs.
  • steps (None or int) – Run validation after every this few steps.
Raises:

ValueError – If both epochs and steps are specified, or neither is specified.

validate_after_epochs(evaluator, freq)

Add an evaluation hook to run after every few epochs.

Parameters:
  • evaluator (Evaluator or () -> any) – A evaluator object (which has .run()), or any callable object.
  • freq (int) – The frequency for this evaluation hook to run.
validate_after_steps(evaluator, freq)

Add an evaluation hook to run after every few steps.

Parameters:
  • evaluator (Evaluator or () -> any) – A evaluator object (which has .run()), or any callable object.
  • freq (int) – The frequency for this evaluation hook to run.