【发布时间】:2020-08-24 15:07:59
【问题描述】:
我有以下 sn-p 代码,我正在尝试在训练我的 CNN 之前对数据进行标准化/规范化。
X = [] # Image data
y = [] # Labels
datagen = ImageDataGenerator(samplewise_center=True)
Loops through imagepaths to load images and labels into arrays
for path in imagepaths:
img = cv2.imread(path) # Reads image and returns np.array
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
img = cv2.resize(img, (200, 200))
img = datagen.standardize(img) #ERROR POINTING HERE
X.append(img)
....
但是,在运行此程序时,我收到以下错误提示,指向我在上面评论过的行:
UFuncTypeError: Cannot cast ufunc 'subtract' output from dtype('float64') to dtype('uint8') with casting rule 'same_kind'
知道我在标准化方面哪里出错了吗?或者有没有更简单的方法让我标准化?我看到了一些人们除以 255 的解决方案,但我不确定如何实现。谢谢!
【问题讨论】:
标签: python tensorflow deep-learning conv-neural-network normalization