def fill_cache(self, repair_incorrect: bool = False) -> None:
with Pool(processes=multiprocessing.cpu_count()) as pool:
total = len(self.labeled_spectrograms)
not_yet_cached = [s for s in self.labeled_spectrograms if not s.is_cached()]
to_calculate = self.labeled_spectrograms if repair_incorrect else not_yet_cached
log("Filling cache with {} spectrograms: {} already cached, {} to calculate.".format(
total, total - len(not_yet_cached), len(to_calculate)))
for index, labeled_spectrogram in enumerate(to_calculate):
pool.apply_async(_repair_cached_spectrogram_if_incorrect if repair_incorrect else _cache_spectrogram,
(labeled_spectrogram,))
pool.close()
pool.join()
评论列表
文章目录