pub struct CheckpointMaker { /* private fields */ }
Expand description

This struct supports saving and restoring variables using Tensorflow checkpoints in SaveV2 format. First, the user creates a CheckpointMaker attached to an Scope indicating the list of variables to be saved/restored. The CheckpointMaker lazily modifies the graph creating the nodes needed for saving/restoring. When one wants to save/restore from or into a session, one calls the save/restore methods

Example

let mut scope = Scope::new_root_scope();
// add operations to define the graph
// ...
// let w and b the variables that we wish to save
let mut checkpoint_maker = CheckpointMaker::new(scope.new_sub_scope("checkpoint"),
            vec![w.clone(), b.clone()].into_boxed_slice(),
        );
let session = Session::new(&SessionOptions::new(), &scope.graph())?;
// run some training
// ...
// to save the training
checkpoint_maker.save(&session, "data/checkpoint")?;
// then we restore in a different session to continue there
let new_session = Session::new(&SessionOptions::new(), &scope.graph())?;
checkpoint_maker.restore(&new_session, "data/checkpoint")?;

Implementations§

source§

impl CheckpointMaker

source

pub fn new(scope: Scope, variables: Box<[Variable]>) -> CheckpointMaker

Creates a new CheckpointMaker for a Scope, with a list of variables to save/restore. The scope is used to modify the graph to add the save and restore ops.

In order to provide a scope for the CheckpointMaker one can use scope.new_sub_scope(“checkpoint”) in order to create the nodes with scoped names.

source

pub fn save( &mut self, session: &Session, backup_filename_base: &str ) -> Result<(), Status>

Save the variables listed in this CheckpointMaker to the checkpoint with base filename backup_filename_base.

source

pub fn restore( &mut self, session: &Session, path_base: &str ) -> Result<(), Status>

Restore into the session the variables listed in this CheckpointMaker from the checkpoint in path_base.

Trait Implementations§

source§

impl Debug for CheckpointMaker

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.