【问题标题】:Trying to standardize/normalize data to go into CNN, but having issues试图标准化/规范化数据以进入 CNN,但遇到问题
【发布时间】: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


    【解决方案1】:

    你需要申请img_to_array方法:

    from keras.preprocessing.image import img_to_array
    
    img = cv2.resize(img, (200, 200)) 
    img = img_to_array(img)
    img = datagen.standardize(img)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-11-29
      • 2011-11-04
      • 2015-11-26
      • 1970-01-01
      • 2018-01-27
      • 2010-10-31
      • 1970-01-01
      相关资源
      最近更新 更多