public class CheckpointListener extends BaseListener implements Serializable
#loadCheckpoint(File, int)
, #loadLastCheckpoint(File)
and #loadCheckpoint(int)
.
Checkpoints can be obtained using lastCheckpoint()
and availableCheckpoints()
CheckpointListener l = new CheckpointListener.Builder("/save/directory")
.keepAll() //Don't delete any models
.saveEveryNEpochs(2)
.build()
CheckpointListener l = new CheckpointListener.Builder(new File("/save/directory"))
.keepLast(3)
.saveEveryNIterations(1000)
.build();
CheckpointListener l = new CheckpointListener.Builder(new File("/save/directory"))
.keepLastAndEvery(3, 4)
.saveEvery(15, TimeUnit.MINUTES)
.build();
.saveEveryEpoch().saveEvery(15, TimeUnit.MINUTES)
.saveEveryEpoch().saveEvery(15, TimeUnit.MINUTES, true)
Modifier and Type | Class and Description |
---|---|
static class |
CheckpointListener.Builder |
Modifier and Type | Method and 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 iterator
|
File |
getFileForCheckpoint(Checkpoint checkpoint)
Get the model file for the given checkpoint.
|
static File |
getFileForCheckpoint(File rootDir,
int checkpointNum) |
File |
getFileForCheckpoint(int checkpointNum)
Get the model file for the given checkpoint number.
|
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 completed
|
Checkpoint |
lastCheckpoint()
Return the most recent checkpoint, if one exists - otherwise returns null
|
static Checkpoint |
lastCheckpoint(File rootDir)
Return the most recent checkpoint, if one exists - otherwise returns null
|
static SameDiff |
loadCheckpoint(File rootDir,
int checkpointNum,
boolean loadUpdaterState)
Load a SameDiff instance for the given checkpoint that resides in the specified root directory
|
SameDiff |
loadCheckpoint(int checkpointNum,
boolean loadUpdaterState)
Load a given checkpoint number
|
static SameDiff |
loadLastCheckpoint(File rootDir,
boolean loadUpdaterState)
Load the last (most recent) checkpoint from the specified root directory
|
activationAvailable, epochStart, iterationStart, operationEnd, operationStart, opExecution, preOpExecution, preUpdate, requiredVariables, validationDone
public ListenerResponse epochEnd(SameDiff sameDiff, At at, LossCurve lossCurve, long epochTimeMillis)
Listener
epochEnd
in interface Listener
epochEnd
in class BaseListener
sameDiff
- The SameDiff instanceat
- Current iteration/epoch etclossCurve
- The losses so farepochTimeMillis
- How long this epoch tookpublic boolean isActive(Operation operation)
Listener
public void iterationDone(SameDiff sd, At at, MultiDataSet dataSet, Loss loss)
Listener
iterationDone
in interface Listener
iterationDone
in class BaseListener
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 trainingpublic List<Checkpoint> availableCheckpoints()
public static List<Checkpoint> availableCheckpoints(File directory)
public Checkpoint lastCheckpoint()
public static Checkpoint lastCheckpoint(File rootDir)
rootDir
- Root direcotry for the checkpoint filespublic File getFileForCheckpoint(Checkpoint checkpoint)
checkpoint
- Checkpoint to get the model file forpublic File getFileForCheckpoint(int checkpointNum)
checkpointNum
- Checkpoint number to get the model file forpublic SameDiff loadCheckpoint(int checkpointNum, boolean loadUpdaterState)
loadUpdaterState
- If true: load the updater state. See SameDiff.load(File, boolean)
for more detailspublic static SameDiff loadCheckpoint(File rootDir, int checkpointNum, boolean loadUpdaterState)
rootDir
- Directory that the checkpoint resides incheckpointNum
- Checkpoint model number to loadloadUpdaterState
- If true: load the updater state. See SameDiff.load(File, boolean)
for more detailspublic static SameDiff loadLastCheckpoint(File rootDir, boolean loadUpdaterState)
rootDir
- Root directory to load checpoint frompublic static CheckpointListener.Builder builder(@NonNull @NonNull File rootDir)
Copyright © 2020. All rights reserved.