当需要(但不使用)cv2时,不可从joblib调用Nonetype



这个错误很奇怪,每当我在单元测试中使用n_jobs>1的sklearn的Kmeans时,以及当使用setuptools要求cv2时,都会导致joblib调用None。

最小故障示例:

设置.py

from setuptools import setup
setup(
    name = "libbla",
# Removing "cv2" resolves the issue :S
    install_requires = ["numpy", "scikit-learn", "cv2"],
    test_suite = 'tests'
)

测试/some_test.py

from sklearn.cluster import KMeans
# also fails without importing sklearn and cv2, just want them for the version numbers.
import unittest, numpy, sklearn, cv2
print("cv2", cv2.__version__)
print("np", numpy.__version__)
print("skl", sklearn.__version__)
class TestFeatureCreator(unittest.TestCase):
    def test_kmeans_2_features(self):
        KMeans(n_clusters = 2, n_jobs = 4).fit_predict(numpy.random.randn(360000, 3))

测试/__init__.py为空。

然后,每当我运行python2.7 setup.py test时,我都会得到以下输出:

$ python2.7 setup.py test
running test
Searching for cv2
Best match: cv2 1.0
Processing cv2-1.0-py2.7.egg
Using /home/herbert/Spyder/bla/.eggs/cv2-1.0-py2.7.egg
running egg_info
writing requirements to libbla.egg-info/requires.txt
writing libbla.egg-info/PKG-INFO
writing top-level names to libbla.egg-info/top_level.txt
writing dependency_links to libbla.egg-info/dependency_links.txt
reading manifest file 'libbla.egg-info/SOURCES.txt'
writing manifest file 'libbla.egg-info/SOURCES.txt'
running build_ext
('cv2', '3.0.0-dev')
('np', '1.10.1')
('skl', '0.16.1')
test_kmeans_2_features (tests.some_test.TestFeatureCreator) ... ok
----------------------------------------------------------------------
Ran 1 test in 1.156s
OK
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
  File "/usr/lib/python2.7/atexit.py", line 24, in _run_exitfuncs
    func(*targs, **kargs)
  File "/usr/lib/python2.7/dist-packages/joblib/pool.py", line 535, in <lambda>
    atexit.register(lambda: delete_folder(pool_folder))
TypeError: 'NoneType' object is not callable
Error in sys.exitfunc:
Traceback (most recent call last):
  File "/usr/lib/python2.7/atexit.py", line 24, in _run_exitfuncs
    func(*targs, **kargs)
  File "/usr/lib/python2.7/dist-packages/joblib/pool.py", line 535, in <lambda>
    atexit.register(lambda: delete_folder(pool_folder))
TypeError: 'NoneType' object is not callable
$

我不确定这是opencv2、sklearn还是numpy bug,这就是我来这里的原因。有人知道这里发生了什么吗?

一些特性:

  • install_requires中删除"cv2"将删除这两个错误
  • 不运行Kmeans的幂等
  • 对于不提供n_ jobs的Kmeans的幂等
  • 在错误之前打印atexit.registerdelete_folderpool_folder时,它们都不是None

当您无法重现错误时,也请发表评论:)

此问题的修复程序已合并到joblib master中(将包含在下一版本0.10中):

https://github.com/joblib/joblib/pull/329

相关内容

  • 没有找到相关文章

最新更新