Beispiel #1
0
    def __init__(self,
                 root,
                 window_size,
                 audio_loader,
                 examples_per_file=8,
                 blacklist_patterns=None,
                 loaded_files_buffer=10,
                 file_usages=10):
        assert (isinstance(root, str))
        if blacklist_patterns is None:
            blacklist_patterns = []

        self.root = root
        self._window_size = window_size
        self._audio_loader = audio_loader
        self._loaded_files_buffer = loaded_files_buffer
        self._file_usages = file_usages

        self._index = 0
        self.filenames = []
        for ext in ['*.wav', '*.mp3']:
            self.filenames.extend(
                [filename for filename in Path(root).rglob(ext)])

        for pattern in blacklist_patterns:
            self.filenames = self.blacklist(self.filenames, pattern)

        self._loaded_files = dict()
        Worker.call(self._populateLoadedFiles).asDaemon.start()

        np.random.shuffle(self.filenames)
        self._examples_per_file = examples_per_file
Beispiel #2
0
    def _selectFile(self):
        loaded_files = list(self._loaded_files.keys())
        while len(list(self._loaded_files.keys())) == 0:
            self._loadNewFile()
            Worker.call(self._populateLoadedFiles).asDaemon.start()
            loaded_files = list(self._loaded_files.keys())

        return np.random.choice(loaded_files)
Beispiel #3
0
 def _usedFilename(self, filename):
     self._loaded_files[filename][0] = self._loaded_files[filename][0] + 1
     if self._loaded_files[filename][0] >= self._file_usages:
         del self._loaded_files[filename]
         Worker.call(self._loadNewFile).asDaemon.start()