Class CheckpointListener
- java.lang.Object
-
- org.nd4j.autodiff.listeners.BaseListener
-
- org.nd4j.autodiff.listeners.checkpoint.CheckpointListener
-
- All Implemented Interfaces:
Serializable
,Listener
public class CheckpointListener extends BaseListener implements Serializable
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
CheckpointListener.Builder
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description List<Checkpoint>
availableCheckpoints()
List all available checkpoints.static List<Checkpoint>
availableCheckpoints(File directory)
List all available checkpoints.static CheckpointListener.Builder
builder(@NonNull File rootDir)
ListenerResponse
epochEnd(SameDiff sameDiff, At at, LossCurve lossCurve, long epochTimeMillis)
Called at the end of every epoch, when fitting from an iteratorFile
getFileForCheckpoint(int checkpointNum)
Get the model file for the given checkpoint number.static File
getFileForCheckpoint(File rootDir, int checkpointNum)
File
getFileForCheckpoint(Checkpoint checkpoint)
Get the model file for the given checkpoint.boolean
isActive(Operation operation)
Returns whether this listener is active during the given operation.void
iterationDone(SameDiff sd, At at, MultiDataSet dataSet, Loss loss)
Called at the end of every iteration, after all operations (including updating parameters) has been completedCheckpoint
lastCheckpoint()
Return the most recent checkpoint, if one exists - otherwise returns nullstatic Checkpoint
lastCheckpoint(File rootDir)
Return the most recent checkpoint, if one exists - otherwise returns nullSameDiff
loadCheckpoint(int checkpointNum, boolean loadUpdaterState)
Load a given checkpoint numberstatic SameDiff
loadCheckpoint(File rootDir, int checkpointNum, boolean loadUpdaterState)
Load a SameDiff instance for the given checkpoint that resides in the specified root directorystatic SameDiff
loadLastCheckpoint(File rootDir, boolean loadUpdaterState)
Load the last (most recent) checkpoint from the specified root directory-
Methods inherited from class org.nd4j.autodiff.listeners.BaseListener
activationAvailable, epochStart, iterationStart, operationEnd, operationStart, opExecution, preOpExecution, preUpdate, requiredVariables, validationDone
-
-
-
-
Method Detail
-
epochEnd
public ListenerResponse epochEnd(SameDiff sameDiff, At at, LossCurve lossCurve, long epochTimeMillis)
Description copied from interface:Listener
Called at the end of every epoch, when fitting from an iterator- Specified by:
epochEnd
in interfaceListener
- Overrides:
epochEnd
in classBaseListener
- Parameters:
sameDiff
- The SameDiff instanceat
- Current iteration/epoch etclossCurve
- The losses so farepochTimeMillis
- How long this epoch took- Returns:
- ListenerResponse.STOP to stop training, CONTINUE or null to continue
-
isActive
public boolean isActive(Operation operation)
Description copied from interface:Listener
Returns whether this listener is active during the given operation. If this returns false for the given operation, those listener methods will not be called.
-
iterationDone
public void iterationDone(SameDiff sd, At at, MultiDataSet dataSet, Loss loss)
Description copied from interface:Listener
Called at the end of every iteration, after all operations (including updating parameters) has been completed- Specified by:
iterationDone
in interfaceListener
- Overrides:
iterationDone
in classBaseListener
- Parameters:
sd
- The SameDiff instanceat
- Current iteration/epoch etcdataSet
- The current dataset (minibatch) used for trainingloss
- The loss value for the current minibatch. Will be null except for during training
-
availableCheckpoints
public List<Checkpoint> availableCheckpoints()
List all available checkpoints. A checkpoint is 'available' if the file can be loaded. Any checkpoint files that have been automatically deleted (given the configuration) will not be returned here.- Returns:
- List of checkpoint files that can be loaded
-
availableCheckpoints
public static List<Checkpoint> availableCheckpoints(File directory)
List all available checkpoints. A checkpoint is 'available' if the file can be loaded. Any checkpoint files that have been automatically deleted (given the configuration) will not be returned here. Note that the checkpointInfo.txt file must exist, as this stores checkpoint information- Returns:
- List of checkpoint files that can be loaded from the specified directory
-
lastCheckpoint
public Checkpoint lastCheckpoint()
Return the most recent checkpoint, if one exists - otherwise returns null- Returns:
- Checkpoint
-
lastCheckpoint
public static Checkpoint lastCheckpoint(File rootDir)
Return the most recent checkpoint, if one exists - otherwise returns null- Parameters:
rootDir
- Root direcotry for the checkpoint files- Returns:
- Checkpoint
-
getFileForCheckpoint
public File getFileForCheckpoint(Checkpoint checkpoint)
Get the model file for the given checkpoint. Checkpoint model file must exist- Parameters:
checkpoint
- Checkpoint to get the model file for- Returns:
- Model file for the checkpoint
-
getFileForCheckpoint
public File getFileForCheckpoint(int checkpointNum)
Get the model file for the given checkpoint number. Checkpoint model file must exist- Parameters:
checkpointNum
- Checkpoint number to get the model file for- Returns:
- Model file for the checkpoint
-
loadCheckpoint
public SameDiff loadCheckpoint(int checkpointNum, boolean loadUpdaterState)
Load a given checkpoint number- Parameters:
loadUpdaterState
- If true: load the updater state. SeeSameDiff.load(File, boolean)
for more details
-
loadCheckpoint
public static SameDiff loadCheckpoint(File rootDir, int checkpointNum, boolean loadUpdaterState)
Load a SameDiff instance for the given checkpoint that resides in the specified root directory- Parameters:
rootDir
- Directory that the checkpoint resides incheckpointNum
- Checkpoint model number to loadloadUpdaterState
- If true: load the updater state. SeeSameDiff.load(File, boolean)
for more details- Returns:
- The loaded model
-
loadLastCheckpoint
public static SameDiff loadLastCheckpoint(File rootDir, boolean loadUpdaterState)
Load the last (most recent) checkpoint from the specified root directory- Parameters:
rootDir
- Root directory to load checpoint from- Returns:
- ComputationGraph for last checkpoint
-
builder
public static CheckpointListener.Builder builder(@NonNull @NonNull File rootDir)
-
-