深度学习语音活动检测训练报错:'CacheManager'无'cachedir'属性
问题解决:AttributeError: 'CacheManager' object has no attribute 'cachedir'
我在基于深度学习开展语音活动检测工作时,运行Python脚本train.py出现如下错误:
AttributeError: 'CacheManager' object has no attribute 'cachedir'
已尝试搜索相关解决方案但未找到有效结果,报错代码来自\site-packages\librosa\cache.py,具体代码如下:
#!/usr/bin/env python # -*- coding: utf-8 -*- """Function caching""" import os import sys from joblib import Memory class CacheManager(Memory): '''The librosa cache manager class extends joblib.Memory with a __call__ attribute, so that it may act as a function. This allows us to override the librosa.cache module's __call__ field, thereby allowing librosa.cache to act as a decorator function. ''' def __init__(self, cachedir, level=10, **kwargs): super(CacheManager, self).__init__(cachedir, **kwargs) # The level parameter controls which data we cache # smaller numbers mean less caching self.level = level def __call__(self, level): '''Example usage: @cache(level=2) def semi_important_function(some_arguments): ... ''' def wrapper(function): '''Decorator function. Adds an input/output cache to the specified function.''' from decorator import FunctionMaker def decorator_apply(dec, func): """Decorate a function by preserving the signature even if dec is not a signature-preserving decorator. This recipe is derived from http://micheles.googlecode.com/hg/decorator/documentation.html#id14 """ return FunctionMaker.create( func, 'return decorated(%(signature)s)', dict(decorated=dec(func)), __wrapped__=func) if self.cachedir is not None and self.level >= level: return decorator_apply(self.cache, function) else: return function return wrapper # Instantiate the cache from the environment CACHE = CacheManager(os.environ.get('LIBROSA_CACHE_DIR', None), mmap_mode=os.environ.get('LIBROSA_CACHE_MMAP', None), compress=os.environ.get('LIBROSA_CACHE_COMPRESS', False), verbose=int(os.environ.get('LIBROSA_CACHE_VERBOSE', 0)), level=int(os.environ.get('LIBROSA_CACHE_LEVEL', 10))) # Override the module's __call__ attribute sys.modules[__name__] = CACHE
报错发生在第49行:if self.cachedir is not None and self.level >= level:
问题原因
这个错误是由于joblib版本兼容性问题导致的:joblib的Memory类在新版本中将属性cachedir改名为location,但当前使用的librosa版本仍在引用旧属性名self.cachedir,因此触发属性找不到的错误。
解决方案
提供三种可行的解决办法,任选其一即可:
降级joblib到兼容版本
执行以下命令安装与当前librosa版本兼容的joblib版本:pip install joblib==0.16.0修改librosa的cache.py代码
找到site-packages/librosa/cache.py文件,将第49行的self.cachedir替换为self.location,修改后该行代码变为:if self.location is not None and self.level >= level:升级librosa到最新版本
新版本的librosa已经修复了这个兼容性问题,执行升级命令:pip install --upgrade librosa
内容的提问来源于stack exchange,提问作者Aisyah Robi
相关产品推荐
相关产品推荐

