vis4d.engine.parser

Parser for config files that can be used with absl flags.

Functions

DEFINE_config_file(name[, default, ...])

Registers a new flag for a config file.

pprints_config(data)

Converts a Config Dict into a string with a .yaml like structure.

Classes

ConfigFileParser(name[, lock_config, ...])

Parser for config files.

class ConfigFileParser(name, lock_config=True, method_name='get_config')[source]

Parser for config files.

Initializes the parser.

Parameters:
  • name (str) – The name of the flag (e.g. config for –config flag)

  • lock_config (bool, optional) – Whether or not to lock the config. Defaults to True.

  • method_name (str, optional) – Name of the method to call in the config. Defaults to “get_config”.

flag_type()[source]

Returns the type of the flag.

Return type:

str

parse(path)[source]

Loads a config module from path and returns the method_name().

This implementation is based on the original ml_collections and modified to allow for a custom method name.

If a colon is present in path, everything to the right of the first colon is passed to method_name as an argument. This allows the structure of what is returned to be modified, which is useful when performing complex hyperparameter sweeps.

Parameters:

path (str) – string, path pointing to the config file to execute. May also contain a config_string argument, e.g. be of the form “config.py:some_configuration”.

Return type:

ConfigDict | _ErrorConfig

Returns:

Result of calling method_name in the specified module.

DEFINE_config_file(name, default=None, help_string='path to config file [.py |.yaml].', lock_config=False, method_name='get_config')[source]

Registers a new flag for a config file.

Parameters:
  • name (str) – The name of the flag (e.g. config for –config flag)

  • default (str | None, optional) – Default Value. Defaults to None.

  • help_string (str, optional) – Help String. Defaults to “path to config file.”.

  • lock_config (bool, optional) – Whether or note to lock the returned config. Defaults to False.

  • method_name (str, optional) – Name of the method to call in the config.

Returns:

Flag holder instance.

Return type:

flags.FlagHolder

pprints_config(data)[source]

Converts a Config Dict into a string with a .yaml like structure.

This function differs from __repr__ of ConfigDict in that it will not encode python classes using binary formats but just prints the __repr__ of these classes.

Parameters:

data (ConfigDict) – Configuration dict to convert to string

Returns:

A string representation of the ConfigDict

Return type:

str