torch.hub¶
- 
torch.hub.load(repo_or_dir, model, *args, **kwargs)[source]¶ Load a model from a github repo or a local directory.
Note: Loading a model is the typical use case, but this can also be used to for loading other objects such as tokenizers, loss functions, etc.
If
sourceis'github',repo_or_diris expected to be of the formrepo_owner/repo_name[:tag_name]with an optional tag/branch.If
sourceis'local',repo_or_diris expected to be a path to a local directory.- Parameters
 repo_or_dir (string) – repo name (
repo_owner/repo_name[:tag_name]), ifsource = 'github'; or a path to a local directory, ifsource = 'local'.model (string) – the name of a callable (entrypoint) defined in the repo/dir’s
hubconf.py.*args (optional) – the corresponding args for callable
model.source (string, optional) –
'github'|'local'. Specifies howrepo_or_diris to be interpreted. Default is'github'.force_reload (bool, optional) – whether to force a fresh download of the github repo unconditionally. Does not have any effect if
source = 'local'. Default isFalse.verbose (bool, optional) – If
False, mute messages about hitting local caches. Note that the message about first download cannot be muted. Does not have any effect ifsource = 'local'. Default isTrue.**kwargs (optional) – the corresponding kwargs for callable
model.
- Returns
 The output of the
modelcallable when called with the given*argsand**kwargs.
Example
>>> # from a github repo >>> repo = 'pytorch/vision' >>> model = torch.hub.load(repo, 'resnet50', pretrained=True) >>> # from a local directory >>> path = '/some/local/path/pytorch/vision' >>> model = torch.hub.load(path, 'resnet50', pretrained=True)