ExternalModuleConfig#
Note
All Configs are derived from rastervision.pipeline.config.Config
, which itself is a pydantic Model.
- pydantic model ExternalModuleConfig[source]#
Config describing an object to be loaded via Torch Hub.
Show JSON schema
{ "title": "ExternalModuleConfig", "description": "Config describing an object to be loaded via Torch Hub.", "type": "object", "properties": { "uri": { "title": "Uri", "description": "Local uri of a zip file, or local uri of a directory,or remote uri of zip file.", "minLength": 1, "type": "string" }, "github_repo": { "title": "Github Repo", "description": "<repo-owner>/<repo-name>[:tag]", "pattern": ".+/.+", "type": "string" }, "name": { "title": "Name", "description": "Name of the folder in which to extract/copy the definition files.", "minLength": 1, "type": "string" }, "entrypoint": { "title": "Entrypoint", "description": "Name of a callable present in hubconf.py. See docs for torch.hub for details.", "minLength": 1, "type": "string" }, "entrypoint_args": { "title": "Entrypoint Args", "description": "Args to pass to the entrypoint. Must be serializable.", "default": [], "type": "array", "items": {} }, "entrypoint_kwargs": { "title": "Entrypoint Kwargs", "description": "Keyword args to pass to the entrypoint. Must be serializable.", "default": {}, "type": "object" }, "force_reload": { "title": "Force Reload", "description": "Force reload of module definition.", "default": false, "type": "boolean" }, "type_hint": { "title": "Type Hint", "default": "external-module", "enum": [ "external-module" ], "type": "string" } }, "required": [ "entrypoint" ], "additionalProperties": false }
- Config
extra: str = forbid
validate_assignment: bool = True
- Fields
entrypoint (rastervision.pytorch_learner.learner_config.ConstrainedStrValue)
github_repo (Optional[rastervision.pytorch_learner.learner_config.ConstrainedStrValue])
name (Optional[rastervision.pytorch_learner.learner_config.ConstrainedStrValue])
uri (Optional[rastervision.pytorch_learner.learner_config.ConstrainedStrValue])
- field entrypoint: ConstrainedStrValue [Required]#
Name of a callable present in hubconf.py. See docs for torch.hub for details.
- Constraints
minLength = 1
- Validated by
- field entrypoint_args: list = []#
Args to pass to the entrypoint. Must be serializable.
- Validated by
- field entrypoint_kwargs: dict = {}#
Keyword args to pass to the entrypoint. Must be serializable.
- Validated by
- field github_repo: Optional[ConstrainedStrValue] = None#
<repo-owner>/<repo-name>[:tag]
- Constraints
pattern = .+/.+
- Validated by
- field name: Optional[ConstrainedStrValue] = None#
Name of the folder in which to extract/copy the definition files.
- Constraints
minLength = 1
- Validated by
- field uri: Optional[ConstrainedStrValue] = None#
Local uri of a zip file, or local uri of a directory,or remote uri of zip file.
- Constraints
minLength = 1
- Validated by
- build(save_dir: str, hubconf_dir: Optional[str] = None, ddp_rank: Optional[int] = None) Any [source]#
Load an external module via torch.hub.
Note: Loading a PyTorch module is the typical use case, but there are no type restrictions on the object loaded through torch.hub.
- Parameters
- Returns
The module loaded via torch.hub.
- Return type
- classmethod deserialize(inp: str | dict | Config) Self #
Deserialize Config from a JSON file or dict, upgrading if possible.
If
inp
is already aConfig
, it is returned as is.
- dict(with_rv_metadata: bool = False, **kwargs) dict #
Generate a dictionary representation of the model, optionally specifying which fields to include or exclude.
- classmethod from_dict(cfg_dict: dict) Self #
Deserialize Config from a dict.
- Parameters
cfg_dict (dict) – Dict to deserialize.
- Return type
Self
- classmethod from_file(uri: str) Self #
Deserialize Config from a JSON file, upgrading if possible.
- Parameters
uri (str) – URI to load from.
- Return type
Self
- recursive_validate_config()#
Recursively validate hierarchies of Configs.
This uses reflection to call validate_config on a hierarchy of Configs using a depth-first pre-order traversal.
- revalidate()#
Re-validate an instantiated Config.
Runs all Pydantic validators plus self.validate_config().
Adapted from: https://github.com/samuelcolvin/pydantic/issues/1864#issuecomment-679044432
- to_file(uri: str, with_rv_metadata: bool = True) None #
Save a Config to a JSON file, optionally with RV metadata.
- update(*args, **kwargs)#
Update any fields before validation.
Subclasses should override this to provide complex default behavior, for example, setting default values as a function of the values of other fields. The arguments to this method will vary depending on the type of Config.
- validate_config()#
Validate fields that should be checked after update is called.
This is to complement the builtin validation that Pydantic performs at the time of object construction.