コード例 #1
0
    def __init__(self, parameters=None, **kwargs):
        """Constructor

        Parameters
        ----------
        parameters : dict
            Extraction parameters, extractor label as key and parameters as value.

        """

        if parameters is None:
            parameters = {}

        kwargs.update(
            {
                'parameters': parameters
            }
        )

        # Run ProcessorMixin init
        ProcessorMixin.__init__(self, **kwargs)

        # Run super init to call init of mixins too
        super(RepositoryFeatureExtractorProcessor, self).__init__(**kwargs)

        self.parameters = kwargs.get('parameters', {})

        self.label_to_class = {}
        for processor in get_class_inheritors(FeatureExtractorProcessor):
            self.label_to_class[processor.label] = processor
コード例 #2
0
ファイル: features.py プロジェクト: turpaultn/dcase_util
def feature_extractor_factory(feature_extractor_label, **kwargs):
    """Function to get correct feature extractor class instance based on extractor label or class name.

    Parameters
    ----------
    feature_extractor_label : str
        Class name or extractor label

    Raises
    ------
    NameError
        Class does not exists

    Returns
    -------
    Feature extractor class instance

    """

    try:
        feature_extractor_class = None

        # Get all classes inherited from FeatureExtractor
        class_list = get_class_inheritors(FeatureExtractor)

        # Search correct feature extractor
        for item in class_list:
            if str(item.__name__) == feature_extractor_label:
                feature_extractor_class = getattr(
                    importlib.import_module(str(item.__module__)),
                    feature_extractor_label)
                break

            elif hasattr(
                    item, 'label'
            ) and item.label == feature_extractor_label and item.__name__.endswith(
                    'Extractor'):
                feature_extractor_class = getattr(
                    importlib.import_module(str(item.__module__)),
                    item.__name__)
                break

        # Valid feature extractor class not found, raise error
        if not feature_extractor_class:
            raise AttributeError

    except AttributeError:

        message = 'Invalid FeatureExtractor class name or extractor label given [{label}].'.format(
            label=feature_extractor_label)
        logger = logging.getLogger(__name__)
        if not logger.handlers:
            setup_logging()

        logger.exception(message)
        raise AttributeError(message)

    return feature_extractor_class(**dict(kwargs))
コード例 #3
0
    def __setstate__(self, d):
        self.parameters = d['parameters']

        self.label_to_class = {}
        for processor in get_class_inheritors(FeatureExtractorProcessor):
            self.label_to_class[processor.label] = processor