axes don‘t match array

axis don’t match array的问题

写一个神经网络进行图像分类,在 读取数据的部分报错如下

(1)numpy.core._exceptions.UFuncTypeError: Cannot cast ufunc ‘subtract’ output from dtype(‘float64’) to dtype(‘uint8’) with casting rule ‘same_kind’

axes don‘t match array
however,发现如果把报错的那句A-=B 改为 A=A-B,这个报错就解决了

X_trian=X_train-mean_image

有人说原因是:

It may be a numpy/broadcasting issue in python

(2)原代码中,上面的命令下面还有命令如下,这时又报错
axes don’t match array

 X_train = X_train.transpose(0, 3, 1, 2).copy()

axes don‘t match array
搜了很多,有一个说法是:你的数据集中有灰度图

PIL Image will give you 2 dimension output if it is grayscale image. (e.g. (64, 64, 1) -> (64, 64))

所以解决办法:
(1)将 X_train 进行reshape为和输入一样格式,我用了这个方法有效

    X_train=X_train.reshape(-1,3,32,32)

(2)转换读图模式image.open(filename) .convert(‘RGB’)
我没试过,可以试试

参考:
开源项目问答

https://github.com/statsmodels/statsmodels/issues/3504

Original: https://blog.csdn.net/gsgs1234/article/details/116061234
Author: 暮已深
Title: axes don‘t match array

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/690734/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球