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)
| 632 | |
| 633 | |
| 634 | def _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 | |
| 667 | def download_url_to_file(url, dst, hash_prefix=None, progress=True): |
no test coverage detected