Safemotion Lib
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Protected Attributes | List of all members
fastreid.engine.train_loop.TrainerBase Class Reference
Inheritance diagram for fastreid.engine.train_loop.TrainerBase:
fastreid.engine.train_loop.SimpleTrainer fastreid.engine.defaults.DefaultTrainer

Public Member Functions

 __init__ (self)
 
 register_hooks (self, hooks)
 
 train (self, int start_iter, int max_iter)
 
 before_train (self)
 
 after_train (self)
 
 before_step (self)
 
 after_step (self)
 
 run_step (self)
 

Public Attributes

 iter
 
 max_iter
 

Protected Attributes

 _hooks
 

Detailed Description

Base class for iterative trainer with hooks.
The only assumption we made here is: the training runs in a loop.
A subclass can implement what the loop is.
We made no assumptions about the existence of dataloader, optimizer, model, etc.
Attributes:
    iter(int): the current iteration.
    start_iter(int): The iteration to start with.
        By convention the minimum possible value is 0.
    max_iter(int): The iteration to end training.
    storage(EventStorage): An EventStorage that's opened during the course of training.

Definition at line 75 of file train_loop.py.

Constructor & Destructor Documentation

◆ __init__()

fastreid.engine.train_loop.TrainerBase.__init__ ( self)

Reimplemented in fastreid.engine.defaults.DefaultTrainer, and fastreid.engine.train_loop.SimpleTrainer.

Definition at line 89 of file train_loop.py.

89 def __init__(self):
90 self._hooks = []
91

Member Function Documentation

◆ after_step()

fastreid.engine.train_loop.TrainerBase.after_step ( self)

Definition at line 144 of file train_loop.py.

144 def after_step(self):
145 for h in self._hooks:
146 h.after_step()
147 # this guarantees, that in each hook's after_step, storage.iter == trainer.iter
148 self.storage.step()
149

◆ after_train()

fastreid.engine.train_loop.TrainerBase.after_train ( self)

Definition at line 136 of file train_loop.py.

136 def after_train(self):
137 for h in self._hooks:
138 h.after_train()
139

◆ before_step()

fastreid.engine.train_loop.TrainerBase.before_step ( self)

Definition at line 140 of file train_loop.py.

140 def before_step(self):
141 for h in self._hooks:
142 h.before_step()
143

◆ before_train()

fastreid.engine.train_loop.TrainerBase.before_train ( self)

Definition at line 132 of file train_loop.py.

132 def before_train(self):
133 for h in self._hooks:
134 h.before_train()
135

◆ register_hooks()

fastreid.engine.train_loop.TrainerBase.register_hooks ( self,
hooks )
Register hooks to the trainer. The hooks are executed in the order
they are registered.
Args:
    hooks (list[Optional[HookBase]]): list of hooks

Definition at line 92 of file train_loop.py.

92 def register_hooks(self, hooks):
93 """
94 Register hooks to the trainer. The hooks are executed in the order
95 they are registered.
96 Args:
97 hooks (list[Optional[HookBase]]): list of hooks
98 """
99 hooks = [h for h in hooks if h is not None]
100 for h in hooks:
101 assert isinstance(h, HookBase)
102 # To avoid circular reference, hooks and trainer cannot own each other.
103 # This normally does not matter, but will cause memory leak if the
104 # involved objects contain __del__:
105 # See http://engineering.hearsaysocial.com/2013/06/16/circular-references-in-python/
106 h.trainer = weakref.proxy(self)
107 self._hooks.extend(hooks)
108

◆ run_step()

fastreid.engine.train_loop.TrainerBase.run_step ( self)

Reimplemented in fastreid.engine.train_loop.SimpleTrainer.

Definition at line 150 of file train_loop.py.

150 def run_step(self):
151 raise NotImplementedError
152
153

◆ train()

fastreid.engine.train_loop.TrainerBase.train ( self,
int start_iter,
int max_iter )
Args:
    start_iter, max_iter (int): See docs above

Reimplemented in fastreid.engine.defaults.DefaultTrainer.

Definition at line 109 of file train_loop.py.

109 def train(self, start_iter: int, max_iter: int):
110 """
111 Args:
112 start_iter, max_iter (int): See docs above
113 """
114 logger = logging.getLogger(__name__)
115 logger.info("Starting training from iteration {}".format(start_iter))
116
117 self.iter = self.start_iter = start_iter
118 self.max_iter = max_iter
119
120 with EventStorage(start_iter) as self.storage:
121 try:
122 self.before_train()
123 for self.iter in range(start_iter, max_iter):
124 self.before_step()
125 self.run_step()
126 self.after_step()
127 except Exception:
128 logger.exception("Exception during training:")
129 finally:
130 self.after_train()
131

Member Data Documentation

◆ _hooks

fastreid.engine.train_loop.TrainerBase._hooks
protected

Definition at line 90 of file train_loop.py.

◆ iter

fastreid.engine.train_loop.TrainerBase.iter

Definition at line 117 of file train_loop.py.

◆ max_iter

fastreid.engine.train_loop.TrainerBase.max_iter

Definition at line 118 of file train_loop.py.


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