Base Model

[source]

BaseModel

polyaxon.models.base.BaseModel(mode, model_type, graph_fn, loss_config, optimizer_config=None, eval_metrics_config=None, summaries='all', clip_gradients=0.5, clip_embed_gradients=0.1, name='Model')

Base class for models.

  • Args:

    • mode: str, Specifies if this training, evaluation or prediction. See Modes.
    • model_type: str, the type of this model. Possible values: Regressor, Classifier, Generator, 'RL'
    • graph_fn: Graph function. Follows the signature:
      • Args:
      • mode: Specifies if this training, evaluation or prediction. See Modes.
      • inputs: the feature inputs.
    • loss_config: An instance of LossConfig.
    • optimizer_config: An instance of OptimizerConfig. Default value Adam.
    • eval_metrics_config: a list of MetricConfig instances.
    • summaries: str or list. The verbosity of the tensorboard visualization. Possible values: all, activations, loss, learning_rate, variables, gradients
    • clip_gradients: float. Gradients clipping by global norm.
    • clip_embed_gradients: float. Embedding gradients clipping to a specified value.
    • name: str, the name of this model, everything will be encapsulated inside this scope.
  • Returns: EstimatorSpec

  • Raises: - TypeError: if the mode does not correspond to the model_type.


_clip_gradients_fn

_clip_gradients_fn(self, grads_and_vars)

Clips gradients by global norm.


_build_optimizer

_build_optimizer(self)

Creates the optimizer


_build_summary_op

_build_summary_op(self, results=None, features=None, labels=None)

Builds summaries for this model.

The summaries are one value (or more) of: * (ACTIVATIONS, VARIABLES, GRADIENTS, LOSS, LEARNING_RATE)


_build_loss

_build_loss(self, results, features, labels)

Creates the loss operation

  • Returns: tuple (losses, loss): losses are the per-batch losses. loss is a single scalar tensor to minimize.

_build_eval_metrics

_build_eval_metrics(self, results, features, labels)

Creates the loss operation

Returns a tuple (losses, loss): losses are the per-batch losses. loss is a single scalar tensor to minimize.


_build_train_op

_build_train_op(self, loss)

Creates the training operation


_preprocess

_preprocess(self, features, labels)

Model specific preprocessing.


_build_predictions

_build_predictions(self, results, features, labels)

Creates the dictionary of predictions that is returned by the model.


_build

_build(self, features, labels, params=None, config=None)

Build the different operation of the model.


batch_size

batch_size(features, labels)

Returns the batch size of the current batch based on the passed features.

  • Args:
    • features: The features.
    • labels: The labels