1. featurewise_center:布爾值,使輸入數據集去中心化(均值爲0), 按feature執行。
2. samplewise_center:布爾值,使輸入數據的每個樣本均值爲0。
3. featurewise_std_normalization:布爾值,將輸入除以數據集的標準差以完成標準化, 按feature執行。
4. samplewise_std_normalization:布爾值,將輸入的每個樣本除以其自身的標準差。
從源碼來解讀:
if self.samplewise_center:
x -= np.mean(x, keepdims=True) #減去每個批次feature的平均值實現0中心化
if self.samplewise_std_normalization:
x /= (np.std(x, keepdims=True) + K.epsilon()) #除以每個批次feature的標準差
if self.featurewise_center:
self.mean = np.mean(x, axis=(0, self.row_axis, self.col_axis)) #在底層爲tendorflow時這裏#self.row_axis=1,self.col_axis=2,即axis(0,1,2)。因爲x是一個4維np,最後一維即圖像的通道數,所
#以這裏計算機的每一通道的像素平均值。
broadcast_shape = [1, 1, 1]
broadcast_shape[self.channel_axis - 1] = x.shape[self.channel_axis]
self.mean = np.reshape(self.mean, broadcast_shape) #對應mean的shape
x -= self.mean #對每批次的數據減對應通道像素的均值
if self.featurewise_std_normalization:
self.std = np.std(x, axis=(0, self.row_axis, self.col_axis))
broadcast_shape = [1, 1, 1]
broadcast_shape[self.channel_axis - 1] = x.shape[self.channel_axis]
self.std = np.reshape(self.std, broadcast_shape)
x /= (self.std + K.epsilon()) #對每批次的數據除以對應通道像素的標準差
使用說明:
ImageDataGenerator(
featurewise_center=True, #均值爲0
featurewise_std_normalization=True,#標準化處理
samplewise_center=False,
samplewise_std_normalization=False,
)