【问题标题】:Feature Normalization/Standard Scalar in KerasKeras 中的特征归一化/标准标量
【发布时间】:2020-12-12 08:43:42
【问题描述】:

我正在使用 Sequential Keras 模型,并试图找出进行特征缩放的最佳方法。

model = Sequential()
model.add(Masking(mask_value=-50, input_shape=(None,10)))
model.add(LayerNormalization(axis=-1))
model.add(LSTM(100, input_shape=(None,10)))
model.add(Dense(100, activation='relu'))
model.add(Dense(3, activation='softmax'))
print(model.summary()) 

在第 3 行,我有一个 LayerNormalization 层,根据文档,它可以缩放为均值和标准差。但是,我也遇到过批量标准化和tf.keras.layers.experimental.preprocessing.Normalization。我的问题是这种方法类似于 Sklearn 的StandardScalar() 还是我可以使用另一种方法来在模型中显示比例?

【问题讨论】:

    标签: python tensorflow keras


    【解决方案1】:

    这应该可行。它使用 UpSampling 层进行简单的基于 5x5 图像的输入:

    # define model
    model = Sequential()
    # define input shape, output enough activations for for 128 5x5 image
    model.add(Dense(128 * 5 * 5, input_dim=100))
    # reshape vector of activations into 128 feature maps with 5x5
    model.add(Reshape((5, 5, 128)))
    # double input from 128 5x5 to 1 10x10 feature map
    model.add(UpSampling2D())
    # fill in detail in the upsampled feature maps and output a single image
    model.add(Conv2D(1, (3,3), padding='same'))
    # summarize model
    model.summary()
    

    但您也可以使用 Conv2DTranspose 层,它将 UpSampling2D 和 Conv2D 层合并为一层。

    在 LSTM 的情况下,TimeDistributed 层会有所帮助。 Refer

    【讨论】:

      猜你喜欢
      • 2021-05-24
      • 2017-10-21
      • 2022-10-19
      • 2013-12-28
      • 1970-01-01
      • 1970-01-01
      • 2017-10-13
      • 2019-08-21
      • 2019-10-26
      相关资源
      最近更新 更多