Shortcuts

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 source is 'github', repo_or_dir is expected to be of the form repo_owner/repo_name[:tag_name] with an optional tag/branch.

If source is 'local', repo_or_dir is expected to be a path to a local directory.

Parameters
  • repo_or_dir (string) – repo name (repo_owner/repo_name[:tag_name]), if source = 'github'; or a path to a local directory, if source = '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 how repo_or_dir is 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 is False.

  • 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 if source = 'local'. Default is True.

  • **kwargs (optional) – the corresponding kwargs for callable model.

Returns

The output of the model callable when called with the given *args and **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)
torch.hub.set_dir(d)[source]

Optionally set the Torch Hub directory used to save downloaded models & weights.

Parameters

d (string) – path to a local folder to save downloaded models & weights.

Docs

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources