`LinAlgError:当尝试使用`skimage.transform.rescale`

2024-06-12 03:34:47 发布

您现在位置:Python中文网/ 问答频道 /正文

我想用0.5的因子重新缩放一个4D数组的MNIST数据。使用skimage.transform.rescale时出错:

LinAlgError: SVD did not converge

我有一种感觉,它可能与图像维度有关,但是文档中没有提到图像维度。在

^{pr2}$

Tags: 数据文档图像nottransform数组因子svd
1条回答
网友
1楼 · 发布于 2024-06-12 03:34:47

来自the documentation

skimage.transform.rescale(image, scale, order=1, mode='constant', cval=0, clip=True, preserve_range=False)[source]

Scale image by a certain factor.

Performs interpolation to upscale or down-scale images. For down-sampling N-dimensional images with integer factors by applying the arithmetic sum or mean, see skimage.measure.local_sum and skimage.transform.downscale_local_mean, respectively. ...

scale : {float, tuple of floats}

Scale factors. Separate scale factors can be defined as (row_scale, col_scale).

我的解释是skimage.measure.rescale只支持2D图像。快速尝试为每个维度传递单独的比例因子似乎可以证实这一点:

In [1]: data = np.random.randn(500, 1, 28, 28)

In [2]: rescaled = transform.rescale(data, (0.5, 0.5, 0.5, 0.5))
                                     -
ValueError                                Traceback (most recent call last)
<ipython-input-2-638fc58c2154> in <module>()
  > 1 rescaled = transform.rescale(data, (0.5, 0.5, 0.5, 0.5))

/home/alistair/.venvs/rfmap/lib/python2.7/site-packages/skimage/transform/_warps.pyc in rescale(image, scale, order, mode, cval, clip, preserve_range)
    164 
    165     try:
 > 166         row_scale, col_scale = scale
    167     except TypeError:
    168         row_scale = col_scale = scale

ValueError: too many values to unpack

如文档所述,您可以使用skimage.transform.local_sumskimage.downscale_local_mean,前提是您只需要减少一个整数因子(在您的例子中是2)。在

另一种支持对非整数缩放因子使用插值的方法是^{}

^{pr2}$

相关问题 更多 >