mmedit.models.base_archs.wrapper¶
Module Contents¶
Classes¶
Wrapper for models from HuggingFace Diffusers. This wrapper will be set |
- class mmedit.models.base_archs.wrapper.DiffusersWrapper(from_pretrained: Optional[Union[str, os.PathLike]] = None, from_config: Optional[Union[str, os.PathLike]] = None, init_cfg: Union[dict, List[dict], None] = None, *args, **kwargs)[源代码]¶
Bases:
mmengine.model.BaseModuleWrapper for models from HuggingFace Diffusers. This wrapper will be set a attribute called _module_cls by wrapping function and will be used to initialize the model structure.
Example: >>> 1. Load pretrained model from HuggingFace Space. >>> config = dict( >>> type=’ControlNetModel’, # has been registered in MODELS >>> from_pretrained=’lllyasviel/sd-controlnet-canny’, >>> torch_dtype=torch.float16) >>> controlnet = MODELS.build(config)
>>> 2. Initialize model with pre-defined configs. >>> config = dict( >>> type='ControlNetModel', # has been registered in `MODELS` >>> from_config='lllyasviel/sd-controlnet-canny', >>> cache_dir='~/.cache/OpenMMLab') >>> controlnet = MODELS.build(config)
>>> 3. Initialize model with own defined arguments >>> config = dict( >>> type='ControlNetModel', # has been registered in `MODELS` >>> in_channels=3, >>> down_block_types=['DownBlock2D'], >>> block_out_channels=(32, ), >>> conditioning_embedding_out_channels=(16, )) >>> controlnet = MODELS.build(config)
- 参数
from_pretrained (Union[str, os.PathLike], optional) – The model id of a pretrained model or a path to a directory containing model weights and config. Please refers to diffusers.model.modeling_utils.ModelMixin.from_pretrained for more detail. Defaults to None.
from_config (Union[str, os.PathLike], optional) – The model id of a pretrained model or a path to a directory containing model weights and config. Please refers to diffusers.configuration_utils.ConfigMixin.load_config for more detail. Defaults to None.
init_cfg (dict or List[dict], optional) – Initialization config dict. Noted that, in DiffuserWrapper, if you want to load pretrained weight from HuggingFace space, please use from_pretrained argument instead of using init_cfg. Defaults to None.
*args – If from_pretrained is passed, *args and **kwargs will be passed to from_pretrained function. If from_config is passed, *args and **kwargs will be passed to load_config function. Otherwise, *args and **kwargs will be used to initialize the model by self._module_cls(*args, **kwargs).
**kwargs –
If from_pretrained is passed, *args and **kwargs will be passed to from_pretrained function. If from_config is passed, *args and **kwargs will be passed to load_config function. Otherwise, *args and **kwargs will be used to initialize the model by self._module_cls(*args, **kwargs).
- init_weights()[源代码]¶
Initialize the weights.
If type is ‘Pretrained’ but the model has be loaded from repo_id, a warning will be raised.