Skip to content

simet.parser.feature_extractor

simet.parser.feature_extractor

FeatureExtractorParser

Factory wrapper that builds feature extractors from config dicts.

Converts a user/config value (e.g., from YAML/JSON) into a :class:FeatureExtractorType and delegates construction to :meth:FeatureExtractorType.get_feature_extractor.

parse_feature_extractor staticmethod

parse_feature_extractor(feature_extractor_data)

Parse config and return a concrete feature extractor instance.

Parameters:

Name Type Description Default
feature_extractor_data dict

Mapping that must include the key "type" with a value matching a :class:FeatureExtractorType (e.g., "InceptionFeatureExtractor").

required

Returns:

Name Type Description
FeatureExtractor FeatureExtractor

An instance of the requested extractor

FeatureExtractor

(currently :class:InceptionFeatureExtractor).

Raises:

Type Description
KeyError

If "type" is missing from feature_extractor_data.

ValueError

If the "type" value is unknown/unsupported.

Example

cfg = {"type": "InceptionFeatureExtractor"} fe = FeatureExtractorParser.parse_feature_extractor(cfg) fe.class.name 'InceptionFeatureExtractor'

Source code in simet/parser/feature_extractor.py
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
@staticmethod
def parse_feature_extractor(feature_extractor_data: dict) -> FeatureExtractor:
    """Parse config and return a concrete feature extractor instance.

    Args:
        feature_extractor_data (dict):
            Mapping that must include the key `"type"` with a value matching
            a :class:`FeatureExtractorType` (e.g., `"InceptionFeatureExtractor"`).

    Returns:
        FeatureExtractor: An instance of the requested extractor
        (currently :class:`InceptionFeatureExtractor`).

    Raises:
        KeyError: If `"type"` is missing from `feature_extractor_data`.
        ValueError: If the `"type"` value is unknown/unsupported.

    Example:
        >>> cfg = {"type": "InceptionFeatureExtractor"}
        >>> fe = FeatureExtractorParser.parse_feature_extractor(cfg)
        >>> fe.__class__.__name__
        'InceptionFeatureExtractor'
    """
    feature_extractor_type = FeatureExtractorType(feature_extractor_data["type"])
    return FeatureExtractorType.get_feature_extractor(feature_extractor_type)

FeatureExtractorType

Bases: StrEnum

Enum of supported feature extractor identifiers (string-valued).

get_feature_extractor staticmethod

get_feature_extractor(feature_extractor_type)

Construct a feature extractor for the given enum value.

Parameters:

Name Type Description Default
feature_extractor_type FeatureExtractorType

Enum member indicating which extractor to instantiate.

required

Returns:

Name Type Description
FeatureExtractor FeatureExtractor

Concrete extractor instance.

Raises:

Type Description
ValueError

If the type is unknown (logged and re-raised).

Notes
  • Extend this match with additional cases as new extractors are added.
Source code in simet/parser/feature_extractor.py
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
@staticmethod
def get_feature_extractor(feature_extractor_type: "FeatureExtractorType") -> FeatureExtractor:
    """Construct a feature extractor for the given enum value.

    Args:
        feature_extractor_type (FeatureExtractorType):
            Enum member indicating which extractor to instantiate.

    Returns:
        FeatureExtractor: Concrete extractor instance.

    Raises:
        ValueError: If the type is unknown (logged and re-raised).

    Notes:
        - Extend this `match` with additional cases as new extractors are added.
    """
    try:
        match feature_extractor_type:
            case FeatureExtractorType.INCEPTION:
                return InceptionFeatureExtractor()
    except ValueError as e:
        logger.error(f"Unknown feature extractor type: {feature_extractor_type}")
        raise ValueError(
            f"Unknown feature extractor type: {feature_extractor_type}"
        ) from e