如果我不进行任何数据规范化,Keras 是否需要 datagen.fit?

数据挖掘 机器学习 Python 神经网络 深度学习 喀拉斯
2022-03-02 08:44:46

我使用 keras 来训练图像分类问题,如下所示:

datagen = ImageDataGenerator(
    featurewise_center=False,
    featurewise_std_normalization=False,
    rotation_range=20,
    width_shift_range=0.2,
    height_shift_range=0.2,
    horizontal_flip=True)

# compute quantities required for featurewise normalization
# (std, mean, and principal components if ZCA whitening is applied)
datagen.fit(x_train)


# alternative to model.fit_generator
for e in range(epochs):
    print('Epoch', e)
    batches = 0
    for x_batch, y_batch in datagen.flow(x_train, y_train, batch_size=32):
        model.fit(x_batch, y_batch)
        batches += 1
        if batches >= len(x_train) / 32:
            # we need to break the loop by hand because
            # the generator loops indefinitely
            break

datagen.fit如果我不应用任何数据规范化,我想知道是否需要?

1个回答

根据代码中文档的注释:

# compute quantities required for featurewise normalization
# (std, mean, and principal components if ZCA whitening is applied)
datagen.fit(x_train)

它进行归一化,减少均值并除以标准差,以及更多类似PCA. 所以看起来你不需要做标准化。该方法可以做到这一点,并且需要对特征进行归一化以加速训练过程并同样关心不同尺度的所有特征。