写一个神经网络进行图像分类,在读取数据的部分报错如下
(1)numpy.core._exceptions.UFuncTypeError: Cannot cast ufunc ‘subtract’ output from dtype(‘float64’) to dtype(‘uint8’) with casting rule ‘same_kind’
however,发现如果把报错的那句A-=B 改为 A=A-B,这个报错就解决了
#X_trian=X_train-mean_image 改
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()
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