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
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 force_reload: bool = False#

Force reload of module definition.

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 type_hint: Literal['external-module'] = 'external-module'#
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
  • save_dir (str, optional) – The module def will be saved here.

  • hubconf_dir (str, optional) – Path to existing definition. If provided, the definition will not be fetched from the external source but instead from this dir. Defaults to None.

  • ddp_rank (Optional[int]) –

Returns

The module loaded via torch.hub.

Return type

Any

validator check_either_uri_or_repo  »  all fields[source]#
Parameters

values (dict) –

Return type

dict

classmethod from_file(uri: str) Config#

Deserialize a Config from a JSON file, upgrading if possible.

Parameters

uri (str) – URI to load from.

Return type

Config

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.

Parameters
  • uri (str) – URI to save to.

  • with_rv_metadata (bool) – If True, inject Raster Vision metadata such as plugin_versions, so that the config can be upgraded when loaded.

Return type

None

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.

validate_list(field: str, valid_options: List[str])#

Validate a list field.

Parameters
  • field (str) – name of field to validate

  • valid_options (List[str]) – values that field is allowed to take

Raises

ConfigError – if field is invalid