Safemotion Lib
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | List of all members
fastreid.utils.checkpoint.PeriodicCheckpointer Class Reference

Public Member Functions

 __init__ (self, Any checkpointer, int period, int max_iter=None)
 
 step (self, int iteration, **Any kwargs)
 
 save (self, str name, **Any kwargs)
 

Public Attributes

 checkpointer
 
 period
 
 max_iter
 

Detailed Description

Save checkpoints periodically. When `.step(iteration)` is called, it will
execute `checkpointer.save` on the given checkpointer, if iteration is a
multiple of period or if `max_iter` is reached.

Definition at line 251 of file checkpoint.py.

Constructor & Destructor Documentation

◆ __init__()

fastreid.utils.checkpoint.PeriodicCheckpointer.__init__ ( self,
Any checkpointer,
int period,
int max_iter = None )
Args:
    checkpointer (Any): the checkpointer object used to save
    checkpoints.
    period (int): the period to save checkpoint.
    max_iter (int): maximum number of iterations. When it is reached,
        a checkpoint named "model_final" will be saved.

Definition at line 258 of file checkpoint.py.

258 def __init__(self, checkpointer: Any, period: int, max_iter: int = None):
259 """
260 Args:
261 checkpointer (Any): the checkpointer object used to save
262 checkpoints.
263 period (int): the period to save checkpoint.
264 max_iter (int): maximum number of iterations. When it is reached,
265 a checkpoint named "model_final" will be saved.
266 """
267 self.checkpointer = checkpointer
268 self.period = int(period)
269 self.max_iter = max_iter
270

Member Function Documentation

◆ save()

fastreid.utils.checkpoint.PeriodicCheckpointer.save ( self,
str name,
**Any kwargs )
Same argument as :meth:`Checkpointer.save`.
Use this method to manually save checkpoints outside the schedule.
Args:
    name (str): file name.
    kwargs (Any): extra data to save, same as in
        :meth:`Checkpointer.save`.

Definition at line 289 of file checkpoint.py.

289 def save(self, name: str, **kwargs: Any):
290 """
291 Same argument as :meth:`Checkpointer.save`.
292 Use this method to manually save checkpoints outside the schedule.
293 Args:
294 name (str): file name.
295 kwargs (Any): extra data to save, same as in
296 :meth:`Checkpointer.save`.
297 """
298 self.checkpointer.save(name, **kwargs)
299
300

◆ step()

fastreid.utils.checkpoint.PeriodicCheckpointer.step ( self,
int iteration,
**Any kwargs )
Perform the appropriate action at the given iteration.
Args:
    iteration (int): the current iteration, ranged in [0, max_iter-1].
    kwargs (Any): extra data to save, same as in
        :meth:`Checkpointer.save`.

Definition at line 271 of file checkpoint.py.

271 def step(self, iteration: int, **kwargs: Any):
272 """
273 Perform the appropriate action at the given iteration.
274 Args:
275 iteration (int): the current iteration, ranged in [0, max_iter-1].
276 kwargs (Any): extra data to save, same as in
277 :meth:`Checkpointer.save`.
278 """
279 iteration = int(iteration)
280 additional_state = {"iteration": iteration}
281 additional_state.update(kwargs)
282 if self.period > 0 and (iteration + 1) % self.period == 0:
283 self.checkpointer.save(
284 "model_{:07d}".format(iteration), **additional_state
285 )
286 if self.period > 0 and iteration >= self.max_iter - 1:
287 self.checkpointer.save("model_final", **additional_state)
288

Member Data Documentation

◆ checkpointer

fastreid.utils.checkpoint.PeriodicCheckpointer.checkpointer

Definition at line 267 of file checkpoint.py.

◆ max_iter

fastreid.utils.checkpoint.PeriodicCheckpointer.max_iter

Definition at line 269 of file checkpoint.py.

◆ period

fastreid.utils.checkpoint.PeriodicCheckpointer.period

Definition at line 268 of file checkpoint.py.


The documentation for this class was generated from the following file: