Skip to content

myco.config

Stores configuration defaults for e.g. model architectures based on yaml file inputs

ArchitectureConfig

Bases: dict

Stores architecture parameters for deep learning models

Source code in myco/config/__init__.py
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
class ArchitectureConfig(dict):
    """Stores architecture parameters for deep learning models"""

    def __init__(self, config: Union[dict, str]):
        """Creates the architecture configuration object.

        Assumes that there's a one-level nesting of the configuration options,
            and all "architecture" attributes will be stored as attributes in the
            output ArchitectureConfig object.

        Args:
            config: the configuration options to pass to this object.
                If it's a string, it assumes a path to a yaml file.
                If it's a dictionary, it assumes the config was already read.

        Returns:
            ArchitectureConfig object with the yaml config options available as
                object attributes (so, config.block_structure)
        """
        if type(config) is str:
            configuration = read_yaml(config)
        else:
            configuration = config

        parameters = configuration["architecture"]
        super(ArchitectureConfig, self).__init__(**parameters)
        self.__dict__ = self

__init__(config)

Creates the architecture configuration object.

Assumes that there's a one-level nesting of the configuration options, and all "architecture" attributes will be stored as attributes in the output ArchitectureConfig object.

Parameters:

Name Type Description Default
config Union[dict, str]

the configuration options to pass to this object. If it's a string, it assumes a path to a yaml file. If it's a dictionary, it assumes the config was already read.

required

Returns:

Type Description

ArchitectureConfig object with the yaml config options available as object attributes (so, config.block_structure)

Source code in myco/config/__init__.py
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
def __init__(self, config: Union[dict, str]):
    """Creates the architecture configuration object.

    Assumes that there's a one-level nesting of the configuration options,
        and all "architecture" attributes will be stored as attributes in the
        output ArchitectureConfig object.

    Args:
        config: the configuration options to pass to this object.
            If it's a string, it assumes a path to a yaml file.
            If it's a dictionary, it assumes the config was already read.

    Returns:
        ArchitectureConfig object with the yaml config options available as
            object attributes (so, config.block_structure)
    """
    if type(config) is str:
        configuration = read_yaml(config)
    else:
        configuration = config

    parameters = configuration["architecture"]
    super(ArchitectureConfig, self).__init__(**parameters)
    self.__dict__ = self

SamplingConfig

Bases: dict

Stores data processing parameters for sample drawing

Source code in myco/config/__init__.py
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
class SamplingConfig(dict):
    """Stores data processing parameters for sample drawing"""

    def __init__(self, config: Union[dict, str]):
        """Creates the dataset configuration object.

        Args:
            config: the configuration options to pass to this object.
                If it's a string, it assumes a path to a yaml file.
                If it's a dictionary, it assumes the config was already read.

        Returns:
            DatasetConfig object with the yaml config options available as
                object attributes (so, config.nodata)
        """
        if type(config) is str:
            configuration = read_yaml(config)
        else:
            configuration = config

        super(SamplingConfig, self).__init__(**configuration)
        self.__dict__ = self

__init__(config)

Creates the dataset configuration object.

Parameters:

Name Type Description Default
config Union[dict, str]

the configuration options to pass to this object. If it's a string, it assumes a path to a yaml file. If it's a dictionary, it assumes the config was already read.

required

Returns:

Type Description

DatasetConfig object with the yaml config options available as object attributes (so, config.nodata)

Source code in myco/config/__init__.py
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
def __init__(self, config: Union[dict, str]):
    """Creates the dataset configuration object.

    Args:
        config: the configuration options to pass to this object.
            If it's a string, it assumes a path to a yaml file.
            If it's a dictionary, it assumes the config was already read.

    Returns:
        DatasetConfig object with the yaml config options available as
            object attributes (so, config.nodata)
    """
    if type(config) is str:
        configuration = read_yaml(config)
    else:
        configuration = config

    super(SamplingConfig, self).__init__(**configuration)
    self.__dict__ = self

get_best_model_path(model_path)

Constructs a file path to the best model output from an input model filepath.

Parameters:

Name Type Description Default
model_path str

file path to the default model path.

required

Returns:

Name Type Description
best_model_path str

uses model_path to define where the best model will be saved.

Source code in myco/config/__init__.py
140
141
142
143
144
145
146
147
148
149
150
151
def get_best_model_path(model_path: str) -> str:
    """Constructs a file path to the best model output from an input model filepath.

    Args:
        model_path: file path to the default model path.

    Returns:
        best_model_path: uses `model_path` to define where the best model will be saved.
    """
    base, ext = os.path.splitext(model_path.rstrip(os.path.sep))
    best_model_path = f"{base}.best{ext}"
    return best_model_path

get_model_config_names()

Return a list of valid model configuration names.

Source code in myco/config/__init__.py
122
123
124
def get_model_config_names() -> list:
    """Return a list of valid model configuration names."""
    return list(MODEL_CONFIGS.keys())

get_model_config_path(name)

Return the path to the default model configuration for a model type.

Parameters:

Name Type Description Default
name str

the model configuration type. Get available options from get_model_config_names().

required

Returns:

Type Description
dict

Default model training parameters as a dictionary.

Source code in myco/config/__init__.py
127
128
129
130
131
132
133
134
135
136
137
def get_model_config_path(name: str) -> dict:
    """Return the path to the default model configuration for a model type.

    Args:
        name: the model configuration type. Get available options from get_model_config_names().

    Returns:
        Default model training parameters as a dictionary.
    """
    assert name in get_model_config_names(), f"Invalid config type: {name}"
    return MODEL_CONFIGS[name]["path"]