| 17 | |
| 18 | |
| 19 | class EMADetectionCheckpointer(DetectionCheckpointer): |
| 20 | def resume_or_load(self, path: str, *, resume: bool = True) -> Dict[str, Any]: |
| 21 | """ |
| 22 | If `resume` is True, this method attempts to resume from the last |
| 23 | checkpoint, if exists. Otherwise, load checkpoint from the given path. |
| 24 | This is useful when restarting an interrupted training job. |
| 25 | |
| 26 | Args: |
| 27 | path (str): path to the checkpoint. |
| 28 | resume (bool): if True, resume from the last checkpoint if it exists |
| 29 | and load the model together with all the checkpointables. Otherwise |
| 30 | only load the model without loading any checkpointables. |
| 31 | |
| 32 | Returns: |
| 33 | same as :meth:`load`. |
| 34 | """ |
| 35 | if resume and self.has_checkpoint(): |
| 36 | path = self.get_checkpoint_file() |
| 37 | return self.load(path) |
| 38 | else: |
| 39 | # workaround `self.load` |
| 40 | return self.load(path, checkpointables=None) # modify |
| 41 | |
| 42 | |
| 43 | class EMAState(object): |