(directory, epoch=None)
| 22 | |
| 23 | |
| 24 | def load_model(directory, epoch=None): |
| 25 | if not directory: |
| 26 | print("Note that load_model() is skipped as no pretrained model is given") |
| 27 | return |
| 28 | |
| 29 | names = self.get_model_names() |
| 30 | |
| 31 | # By default, the best model is loaded |
| 32 | model_file = "model-best.pth.tar" |
| 33 | |
| 34 | if epoch is not None: |
| 35 | model_file = "model.pth.tar-" + str(epoch) |
| 36 | |
| 37 | for name in names: |
| 38 | model_path = osp.join(directory, name, model_file) |
| 39 | |
| 40 | if not osp.exists(model_path): |
| 41 | raise FileNotFoundError('Model not found at "{}"'.format(model_path)) |
| 42 | |
| 43 | checkpoint = load_checkpoint(model_path) |
| 44 | state_dict = checkpoint["state_dict"] |
| 45 | epoch = checkpoint["epoch"] |
| 46 | |
| 47 | # Ignore fixed token vectors |
| 48 | if "token_prefix" in state_dict: |
| 49 | del state_dict["token_prefix"] |
| 50 | |
| 51 | if "token_suffix" in state_dict: |
| 52 | del state_dict["token_suffix"] |
| 53 | |
| 54 | print("Loading weights to {} " 'from "{}" (epoch = {})'.format(name, model_path, epoch)) |
| 55 | # set strict=False |
| 56 | self._models[name].load_state_dict(state_dict, strict=False) |
| 57 | |
| 58 | class TextEncoder(nn.Module): |
| 59 | def __init__(self, clip_model): |
nothing calls this directly
no outgoing calls
no test coverage detected