Load checkpoint from a file or URI. Args: model (Module): Module to load checkpoint. filename (str): Accept local filepath, URL, ``torchvision://xxx``, ``open-mmlab://xxx``. Please refer to ``docs/model_zoo.md`` for details. map_location (str): Sa
(model,
filename,
map_location='cpu',
strict=False,
logger=None,
revise_keys=[(r'^module\.', '')])
| 47 | |
| 48 | |
| 49 | def load_checkpoint(model, |
| 50 | filename, |
| 51 | map_location='cpu', |
| 52 | strict=False, |
| 53 | logger=None, |
| 54 | revise_keys=[(r'^module\.', '')]): |
| 55 | """Load checkpoint from a file or URI. |
| 56 | |
| 57 | Args: |
| 58 | model (Module): Module to load checkpoint. |
| 59 | filename (str): Accept local filepath, URL, ``torchvision://xxx``, |
| 60 | ``open-mmlab://xxx``. Please refer to ``docs/model_zoo.md`` for |
| 61 | details. |
| 62 | map_location (str): Same as :func:`torch.load`. |
| 63 | strict (bool): Whether to allow different params for the model and |
| 64 | checkpoint. |
| 65 | logger (:mod:`logging.Logger` or None): The logger for error message. |
| 66 | revise_keys (list): A list of customized keywords to modify the |
| 67 | state_dict in checkpoint. Each item is a (pattern, replacement) |
| 68 | pair of the regular expression operations. Default: strip |
| 69 | the prefix 'module.' by [(r'^module\\.', '')]. |
| 70 | |
| 71 | Returns: |
| 72 | dict or OrderedDict: The loaded checkpoint. |
| 73 | """ |
| 74 | filename = get_checkpoint(filename) |
| 75 | return mmcv_load_checkpoint( |
| 76 | model, |
| 77 | filename, |
| 78 | map_location=map_location, |
| 79 | strict=strict, |
| 80 | logger=logger, |
| 81 | revise_keys=revise_keys) |
| 82 | |
| 83 | |
| 84 | def save_checkpoint(model, filename, optimizer=None, meta=None): |