restorer

Primitive Restorer, can be used standalone.

Classes

Restorer Restorer provide a way to restore objects from tf.train.Checkpoint.

Exceptions

ModelNotConstructedError Exception raised while restoring sub-classed Model before having called it on data.
exception ashpy.restorers.restorer.ModelNotConstructedError[source]

Bases: Exception

Exception raised while restoring sub-classed Model before having called it on data.

Warning

When restoring a tf.keras.Model object from checkpoint assure that the model has been correctly built and instantiated by firstly calling it on some sample inputs. In the case of a model built with either the Sequential or Functional API an exception will be raised; for a model built with the Chainer API it will fail silently, restoration will be “successful” but no values will actually be restored since there are no valid placeholder as the model has not be built yet.

class ashpy.restorers.restorer.Restorer(logdir=PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/ashpy/checkouts/master/docs/source/log'), ckpts_dir='ckpts', expect_partial=True)[source]

Bases: object

Restorer provide a way to restore objects from tf.train.Checkpoint.

Can be standalone.

__init__(logdir=PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/ashpy/checkouts/master/docs/source/log'), ckpts_dir='ckpts', expect_partial=True)[source]

Initialize the Restorer.

Parameters:
  • logdir (str) – Path to the directory with the logs.
  • ckpts_dir (str) – Name of the directory with the checkpoints to restore.
  • expect_partial (bool) – Whether to expect partial restoring or not. Default to true. For more information see the docs for tf.train.Checkpoint.restore().
Return type:

None

static _check_model_construction(restored_model)[source]

Optimistically check that the model.weights property returns a non empty-list.

The underlying assumption is that Models created via the sub-classing API, when restored without being properly constructed AKA called on some input, will have empty lists as layers.weights.

TODO: add docs for the exception. TODO: add test case for the Sequential without input shape

Return type:bool
_restore_checkpoint(checkpoint, partial=True)[source]

Restore or initialize the persistence layer (checkpoint).

checkpoint_map

Get the map of the ids in the checkpoint.

Map is a Dict where keys are the ids in the checkpoint and the values are the
string representation of the types.
Return type:Optional[Dict[str, str]]
Returns:Dict if the map is found, else None.
get_global_step()[source]

Return the restored global_step.

Return type:Variable
get_steps_per_epoch()[source]

Return the restored global_step.

Return type:Variable
restore_callback(callback, callback_ckpt_id)[source]

Return the restored callbacks.

Return type:List[Callback]
restore_object(placeholder, object_ckpt_id)[source]

Restore a placeholder from a checkpoint using the specified id.

Warning

When restoring a tf.keras.Model object from checkpoint assure that the model has been correctly built and instantiated by firstly calling it on some sample inputs. In the case of a model built with either the Sequential or Functional API an exception will be raised; for a model built with the Chainer API it will fail silently, restoration will be “successful” but no values will actually be restored since there are no valid placeholder as the model has not be built yet.

TODO: Args TODO: Example