Safemotion Lib
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Protected Attributes | List of all members
fastreid.utils.events.CommonMetricPrinter Class Reference
Inheritance diagram for fastreid.utils.events.CommonMetricPrinter:
fastreid.utils.events.EventWriter

Public Member Functions

 __init__ (self, max_iter)
 
 write (self)
 
- Public Member Functions inherited from fastreid.utils.events.EventWriter
 close (self)
 

Public Attributes

 logger
 

Protected Attributes

 _max_iter
 
 _last_write
 

Detailed Description

Print **common** metrics to the terminal, including
iteration time, ETA, memory, all losses, and the learning rate.
It also applies smoothing using a window of 20 elements.
It's meant to print common metrics in common ways.
To print something in more customized ways, please implement a similar printer by yourself.

Definition at line 173 of file events.py.

Constructor & Destructor Documentation

◆ __init__()

fastreid.utils.events.CommonMetricPrinter.__init__ ( self,
max_iter )
Args:
    max_iter (int): the maximum number of iterations to train.
        Used to compute ETA.

Definition at line 182 of file events.py.

182 def __init__(self, max_iter):
183 """
184 Args:
185 max_iter (int): the maximum number of iterations to train.
186 Used to compute ETA.
187 """
188 self.logger = logging.getLogger(__name__)
189 self._max_iter = max_iter
190 self._last_write = None
191

Member Function Documentation

◆ write()

fastreid.utils.events.CommonMetricPrinter.write ( self)

Reimplemented from fastreid.utils.events.EventWriter.

Definition at line 192 of file events.py.

192 def write(self):
193 storage = get_event_storage()
194 iteration = storage.iter
195
196 try:
197 data_time = storage.history("data_time").avg(20)
198 except KeyError:
199 # they may not exist in the first few iterations (due to warmup)
200 # or when SimpleTrainer is not used
201 data_time = None
202
203 eta_string = None
204 try:
205 iter_time = storage.history("time").global_avg()
206 eta_seconds = storage.history("time").median(1000) * (self._max_iter - iteration)
207 storage.put_scalar("eta_seconds", eta_seconds, smoothing_hint=False)
208 eta_string = str(datetime.timedelta(seconds=int(eta_seconds)))
209 except KeyError:
210 iter_time = None
211 # estimate eta on our own - more noisy
212 if self._last_write is not None:
213 estimate_iter_time = (time.perf_counter() - self._last_write[1]) / (
214 iteration - self._last_write[0]
215 )
216 eta_seconds = estimate_iter_time * (self._max_iter - iteration)
217 eta_string = str(datetime.timedelta(seconds=int(eta_seconds)))
218 self._last_write = (iteration, time.perf_counter())
219
220 try:
221 lr = "{:.2e}".format(storage.history("lr").latest())
222 except KeyError:
223 lr = "N/A"
224
225 if torch.cuda.is_available():
226 max_mem_mb = torch.cuda.max_memory_allocated() / 1024.0 / 1024.0
227 else:
228 max_mem_mb = None
229
230 # NOTE: max_mem is parsed by grep in "dev/parse_results.sh"
231 self.logger.info(
232 " {eta}iter: {iter} {losses} {time}{data_time}lr: {lr} {memory}".format(
233 eta=f"eta: {eta_string} " if eta_string else "",
234 iter=iteration,
235 losses=" ".join(
236 [
237 "{}: {:.4g}".format(k, v.median(20))
238 for k, v in storage.histories().items()
239 if "loss" in k
240 ]
241 ),
242 time="time: {:.4f} ".format(iter_time) if iter_time is not None else "",
243 data_time="data_time: {:.4f} ".format(data_time) if data_time is not None else "",
244 lr=lr,
245 memory="max_mem: {:.0f}M".format(max_mem_mb) if max_mem_mb is not None else "",
246 )
247 )
248
249

Member Data Documentation

◆ _last_write

fastreid.utils.events.CommonMetricPrinter._last_write
protected

Definition at line 190 of file events.py.

◆ _max_iter

fastreid.utils.events.CommonMetricPrinter._max_iter
protected

Definition at line 189 of file events.py.

◆ logger

fastreid.utils.events.CommonMetricPrinter.logger

Definition at line 188 of file events.py.


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