测试 SciPy 时出错 [英] Error when testing SciPy

查看:44
本文介绍了测试 SciPy 时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 scipy.test() 使用鼻子包测试 scipy 时,在安装了所有 vanilla 包的 Ubuntu 12.04 下测试失败.我是否需要担心,如果是,我该如何解决?

When testing scipy using the nose package using scipy.test(), the test fails under Ubuntu 12.04 with all the vanilla packages installed. Do I have to worry, and if yes how can I fix this?

In [8]: scipy.test()
Running unit tests for scipy
NumPy version 1.5.1
NumPy is installed in /usr/lib/python2.7/dist-packages/numpy
SciPy version 0.9.0
SciPy is installed in /usr/lib/python2.7/dist-packages/scipy
Python version 2.7.2+ (default, Jan 21 2012, 23:31:34) [GCC 4.6.2]
nose version 1.1.2

[................]

======================================================================
FAIL: test_io.test_imread
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File "/usr/lib/python2.7/dist-packages/numpy/testing/decorators.py", line 146, in skipper_func
    return f(*args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/scipy/ndimage/tests/test_io.py", line 16, in test_imread
    assert_array_equal(img.shape, (300, 420, 3))
  File "/usr/lib/python2.7/dist-packages/numpy/testing/utils.py", line 686, in assert_array_equal
    verbose=verbose, header='Arrays are not equal')
  File "/usr/lib/python2.7/dist-packages/numpy/testing/utils.py", line 579, in assert_array_compare
    raise AssertionError(msg)
AssertionError: 
Arrays are not equal

(shapes (2,), (3,) mismatch)
 x: array([300, 420])
 y: array([300, 420,   3])

----------------------------------------------------------------------
Ran 3780 tests in 32.328s

FAILED (KNOWNFAIL=11, SKIP=20, failures=1)

推荐答案

如果你看看里面 /usr/lib/python2.7/dist-packages/scipy/ndimage/tests/test_io.py你应该看到:

If you take a look inside /usr/lib/python2.7/dist-packages/scipy/ndimage/tests/test_io.py you should see:

def test_imread():
    lp = os.path.join(os.path.dirname(__file__), 'dots.png')
    img = ndi.imread(lp)
    assert_array_equal(img.shape, (300, 420, 3))

    img = ndi.imread(lp, flatten=True)
    assert_array_equal(img.shape, (300, 420))

这个测试似乎是在测试 flatten=True 是否将 RGB 图像转换为 1 位灰度图像.

This test seems to be testing if flatten=True converts an RGB image into a 1-bit greyscale image.

然而,在我的 Ubuntu 11.10 系统上,dots.png 已经是一个 1 位图像文件:

On my Ubuntu 11.10 system, however, dots.png is already a 1-bit image file:

% file /usr/share/pyshared/scipy/ndimage/tests/dots.png
/usr/share/pyshared/scipy/ndimage/tests/dots.png: PNG image data, 420 x 300, 1-bit colormap, non-interlaced

如果我对 RGBA 图像执行测试(手动),则测试有效:

If I perform the test (manually) on a RGBA image, then the test works:

In [18]: z = ndi.imread('image.png')

In [20]: z.shape
Out[20]: (250, 250, 4)

In [24]: w = ndi.imread('image.png', flatten = True)

In [25]: w.shape
Out[25]: (250, 250)

所以我不认为这里有什么严重的错误,只是可能发送的 dots.png 文件应该是 RGB 图像而不是灰度图像.

So I don't think there is anything seriously wrong here, just that perhaps the dots.png file that was shipped should have been an RGB image instead of a greyscale one.

这篇关于测试 SciPy 时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆