コード例 #1
0
ファイル: containers.py プロジェクト: mic2zar/dcase_util
    def __init__(self, *args, **kwargs):
        # Run ContainerMixin init
        ContainerMixin.__init__(self, *args, **kwargs)

        # Run FileMixin init
        FileMixin.__init__(self, *args, **kwargs)

        super(ObjectContainer, self).__init__(*args, **kwargs)
コード例 #2
0
ファイル: containers.py プロジェクト: mic2zar/dcase_util
    def __init__(self, *args, **kwargs):
        # Run ContainerMixin init
        ContainerMixin.__init__(self, *args, **kwargs)

        # Run FileMixin init
        FileMixin.__init__(self, *args, **kwargs)

        super(DictContainer, self).__init__(*args)

        self.non_hashable_fields = [
            '_hash',
            'verbose',
        ]
        if kwargs.get('non_hashable_fields'):
            self.non_hashable_fields.update(kwargs.get('non_hashable_fields'))
コード例 #3
0
ファイル: containers.py プロジェクト: mic2zar/dcase_util
    def __init__(self, *args, **kwargs):
        """Constructor

        Parameters
        ----------
        filename : str, optional
            File path
        """

        # Run ContainerMixin init
        ContainerMixin.__init__(self, *args, **kwargs)

        # Run FileMixin init
        FileMixin.__init__(self, *args, **kwargs)

        # Run list init
        list.__init__(self, *args)
コード例 #4
0
ファイル: containers.py プロジェクト: mic2zar/dcase_util
    def __init__(self, *args, **kwargs):
        """Constructor

        Parameters
        ----------
        filename : str, optional
            File path
        """

        # Run ContainerMixin init
        ContainerMixin.__init__(self, *args, **kwargs)

        # Run FileMixin init
        FileMixin.__init__(self, *args, **kwargs)

        # Run list init
        list.__init__(self, *args)

        # Convert list items to DictContainers
        for item_id, item in enumerate(self):
            self[item_id] = DictContainer(item)
コード例 #5
0
ファイル: data.py プロジェクト: rxhmdia/dcase_util
        def __init__(self,
                     item_list=None,
                     batch_size=64,
                     buffer_size=None,
                     data_processing_chain=None,
                     meta_processing_chain=None,
                     data_processing_chain_callback_on_epoch_end=None,
                     meta_processing_chain_callback_on_epoch_end=None,
                     transformer_callbacks=None,
                     refresh_buffer_on_epoch=False,
                     data_format='channels_last',
                     target_format='single_target_per_sequence',
                     **kwargs):
            """Constructor

            Parameters
            ----------
            item_list : list or dict
                Items in the data sequence. List containing multi-level dictionary with first level key
                'data' and 'meta'. Second level should contain parameters for process method in the processing chain.
                Default value None

            batch_size : int
                Batch size (item count).
                Default value 64

            buffer_size : int
                Internal buffer size (item count). By setting this sufficiently high, data sequence generator can
                possibly fit all sequence items into internal buffer and can fetch without loading from disk.
                Set to None, if no internal buffer used.
                Default value None

            data_processing_chain : ProcessingChain
                Data processing chain.
                Default value None

            meta_processing_chain : ProcessingChain
                Meta processing chain.
                Default value None

            data_processing_chain_callback_on_epoch_end : list of dict
                Can be used to call methods with parameters for processing chain at the end of epoch. This can be
                used to control processing chain's internal status (e.g. roll the data).
                Default value None

            meta_processing_chain_callback_on_epoch_end : list of dict
                Can be used to call methods with parameters for processing chain at the end of epoch. This can be
                used to control processing chain's internal status (e.g. roll the data).
                Default value None

            transformer_callbacks : list of func
                Transformer callbacks to jointly process data and meta. This can be used for local data modification and
                data augmentation.
                Default value None

            refresh_buffer_on_epoch : bool
                In case internal data buffer is used, force data and meta refresh at the end of each epoch. Use this if
                data is modified/augmented differently for each epoch.
                In case data_processing_chain_callback_on_epoch_end or meta_processing_chain_callback_on_epoch_end is
                used, this parameter is automatically set to True.
                Default value False

            data_format : str
                Keras like data format, controls where channel should be added.
                Possible values ['channels_first', 'channels_last']
                Default value 'channels_last'

            target_format : str
                Meta data interpretation in the relation to the data items.
                Default value 'single_target_per_segment'

            """

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

            self._data_shape = None
            self._data_axis = None

            self.item_list = copy.copy(item_list)

            self.batch_size = batch_size

            self.buffer_size = buffer_size
            self.data_refresh_on_epoch = refresh_buffer_on_epoch

            if data_format is None:
                data_format = 'channels_last'

            self.data_format = data_format
            if self.data_format not in ['channels_first', 'channels_last']:
                message = '{name}: Unknown data_format [{data_format}].'.format(
                    name=self.__class__.__name__, data_format=self.data_format)
                self.logger.exception(message)
                raise NotImplementedError(message)

            if target_format is None:
                target_format = 'single_target_per_sequence'

            self.target_format = target_format
            if self.target_format not in [
                    'same', 'single_target_per_sequence'
            ]:
                message = '{name}: Unknown target_format [{target_format}].'.format(
                    name=self.__class__.__name__,
                    target_format=self.target_format)
                self.logger.exception(message)
                raise NotImplementedError(message)

            if data_processing_chain_callback_on_epoch_end is None:
                data_processing_chain_callback_on_epoch_end = []

            self.data_processing_chain_callback_on_epoch_end = data_processing_chain_callback_on_epoch_end

            if self.data_processing_chain_callback_on_epoch_end:
                self.data_refresh_on_epoch = True

            if meta_processing_chain_callback_on_epoch_end is None:
                meta_processing_chain_callback_on_epoch_end = []

            self.meta_processing_chain_callback_on_epoch_end = meta_processing_chain_callback_on_epoch_end

            if transformer_callbacks is None:
                transformer_callbacks = []

            self.transformer_callbacks = transformer_callbacks

            # Processing chains
            self.data_processing_chain = data_processing_chain
            self.meta_processing_chain = meta_processing_chain

            if self.buffer_size is not None:
                # Initialize data buffer
                self.data_buffer = DataBuffer(size=self.buffer_size)

            else:
                self.data_buffer = None
コード例 #6
0
ファイル: features.py プロジェクト: turpaultn/dcase_util
    def __init__(self,
                 fs=44100,
                 win_length_samples=None,
                 hop_length_samples=None,
                 win_length_seconds=0.04,
                 hop_length_seconds=0.02,
                 **kwargs):
        """Constructor

        Parameters
        ----------
        fs : int
            Sampling rate of the incoming signal

        win_length_samples : int
            Window length in samples

        hop_length_samples : int
            Hop length in samples

        win_length_seconds : float
            Window length in seconds

        hop_length_seconds : float
            Hop length in seconds

        """

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

        self.eps = numpy.spacing(1)
        if fs is not None:
            self.fs = fs

        else:
            message = '{name}: No fs set'.format(name=self.__class__.__name__)
            self.logger.exception(message)
            raise ValueError(message)

        self.win_length_samples = win_length_samples
        self.hop_length_samples = hop_length_samples

        self.win_length_seconds = win_length_seconds
        self.hop_length_seconds = hop_length_seconds

        if not self.win_length_samples and self.win_length_seconds and self.fs:
            self.win_length_samples = int(self.fs * self.win_length_seconds)

        if not self.hop_length_samples and self.hop_length_seconds and self.fs:
            self.hop_length_samples = int(self.fs * self.hop_length_seconds)

        if self.win_length_samples is None:
            message = '{name}: No win_length_samples set'.format(
                name=self.__class__.__name__)
            self.logger.exception(message)
            raise ValueError(message)

        if self.hop_length_samples is None:
            message = '{name}: No hop_length_samples set'.format(
                name=self.__class__.__name__)
            self.logger.exception(message)
            raise ValueError(message)