我有以下问题:
我在 Keras 中有一个自动编码器,并对其进行了几个时期的训练。训练概览显示验证 MAE 为 0.0422,MSE 为 0.0024。但是,如果我随后调用 network.predict 并手动计算验证错误,我会得到 0.035 和 0.0024。
人们会认为我对 MAE 的手动计算完全不正确,但奇怪的是,如果我使用恒等模型(仅输出您输入的内容)并使用它来评估预测值,则会返回与我的手工计算。代码如下:
input = Input(shape=(X_train.shape[1], ))
encoded = Dense(50, activation='relu', activity_regularizer=regularizers.l1(10e-5))(input)
encoded = Dense(50, activation='relu', activity_regularizer=regularizers.l1(10e-5))(encoded)
encoded = Dense(50, activation='relu', activity_regularizer=regularizers.l1(10e-5))(encoded)
decoded = Dense(50, activation='relu', activity_regularizer=regularizers.l1(10e-5))(encoded)
decoded = Dense(50, activation='relu', activity_regularizer=regularizers.l1(10e-5))(decoded)
decoded = Dense(X_train.shape[1], activation='sigmoid')(decoded)
network = Model(input, decoded)
# sgd = SGD(lr=8, decay=1e-6)
# network.compile(loss='mean_squared_error', optimizer='adam')
network.compile(loss='mean_absolute_error', optimizer='adam', metrics=['mse'])
# Fitting the data
network.fit(X_train, X_train, epochs=2, batch_size=1, shuffle=True, validation_data=(X_valid, X_valid),
callbacks=[EarlyStopping(monitor='val_loss', min_delta=0.00001, patience=20, verbose=0, …Run Code Online (Sandbox Code Playgroud)