Densefuse: 成功解决ValueError: cannot reshape array of size xxx into shape (xxx,xxx,xxx)

最近在复现图像融合Densefuse时,出现报错:

ValueError: cannot reshape array of size 97200 into shape (256,256,1)

在网上查了下,说是输入的尺寸不对,我的输入图片是270 X 360 =97200 不等于256 X 256 =65536。

但是输入的图片尺寸肯定是不同的,那么就是在reshape前面resize部分出了问题。由于scipy版本问题,scipy>=1.2不再包含函数imresize,所以在之前我就按网上的方法将

image = imresize(image, [height, width], interp='nearest')

调用numpy库:

import numpy as np

原句改为了:

np.array(Image.fromarray(image).resize((height, width)))

上述改动就是导致resize不起作用的原因,于是我采用了另外的改法,将调用的

from scipy.misc import imresize

注释掉或者删掉,选择调用skimage库:

from skimage.transform import resize as imresize

原句改为:

image = imresize(image, [height, width])

采用第二种改动,成功起到了作用,输入的图片resize后就能正常进行reshape了。

来源:kakalt6

物联沃分享整理
物联沃-IOTWORD物联网 » Densefuse: 成功解决ValueError: cannot reshape array of size xxx into shape (xxx,xxx,xxx)

发表评论