MCPcopy Create free account
hub / github.com/TorchSSL/TorchSSL / set_epoch

Method set_epoch

custom_writer.py:51–68  ·  view source on GitHub ↗

Execute this function to update the step attribute and compute the cost time of one epoch in seconds. Recommend to run this function every step. This function MUST be executed before other custom writer functions. Parameters: ------------ step : int,

(self, epoch, mode)

Source from the content-addressed store, hash-verified

49 )
50
51 def set_epoch(self, epoch, mode):
52 '''
53 Execute this function to update the step attribute and compute the cost time of one epoch in seconds.
54 Recommend to run this function every step.
55 This function MUST be executed before other custom writer functions.
56 Parameters:
57 ------------
58 step : int, step number.
59 mode : str, 'train' or 'valid'
60 '''
61 if epoch == 0:
62 self.timer = datetime.datetime.now()
63 elif epoch != self.epoch:
64 duration = datetime.datetime.now() - self.timer
65 second_per_epoch = duration.total_seconds() / (epoch - self.epoch)
66 self.add_scalar(tag='second_per_epoch', data=second_per_epoch)
67 self.epoch = epoch
68 self.mode = mode
69
70 def get_epoch(self) -> int:
71 return self.epoch

Callers 1

updateMethod · 0.80

Calls 1

add_scalarMethod · 0.95

Tested by

no test coverage detected