MCPcopy Create free account
hub / github.com/Oneflow-Inc/oneflow / _load_local

Function _load_local

python/oneflow/hub.py:634–664  ·  view source on GitHub ↗

Load a model from a local directory with a ``hubconf.py``. Args: hubconf_dir (str): path to a local directory that contains a ``hubconf.py``. model (str): name of an entrypoint defined in the directory's ``hubconf.py``. *args (optional):

(hubconf_dir, model, *args, **kwargs)

Source from the content-addressed store, hash-verified

632
633
634def _load_local(hubconf_dir, model, *args, **kwargs):
635 """
636 Load a model from a local directory with a ``hubconf.py``.
637
638 Args:
639 hubconf_dir (str): path to a local directory that contains a
640 ``hubconf.py``.
641 model (str): name of an entrypoint defined in the directory's
642 ``hubconf.py``.
643 *args (optional): the corresponding args for callable ``model``.
644 **kwargs (optional): the corresponding kwargs for callable ``model``.
645
646 Returns:
647 a single model with corresponding pretrained weights.
648
649 For example:
650 >>> # xdoctest: +SKIP("stub local path")
651 >>> path = '/some/local/path/oneflow/vision'
652 >>> model = _load_local(path, 'resnet50', weights='ResNet50_Weights.IMAGENET1K_V1')
653 """
654 sys.path.insert(0, hubconf_dir)
655
656 hubconf_path = os.path.join(hubconf_dir, MODULE_HUBCONF)
657 hub_module = _import_module(MODULE_HUBCONF, hubconf_path)
658
659 entry = _load_entry_from_hubconf(hub_module, model)
660 model = entry(*args, **kwargs)
661
662 sys.path.remove(hubconf_dir)
663
664 return model
665
666
667def download_url_to_file(url, dst, hash_prefix=None, progress=True):

Callers 1

loadFunction · 0.85

Calls 5

_import_moduleFunction · 0.85
_load_entry_from_hubconfFunction · 0.85
insertMethod · 0.80
joinMethod · 0.80
removeMethod · 0.45

Tested by

no test coverage detected