相关疑难解决方法(0)

Keras model.evaluate()和model.predict()有什么区别?

我使用Keras生物医学图像分割技术来分割脑神经元。我用model.evaluate()它给了我骰子系数:0.916。但是,当我使用时model.predict(),通过计算Dice系数遍历预测图像,Dice系数为0.82。为什么这两个值不同?

machine-learning neural-network image-segmentation deep-learning keras

9
推荐指数
4
解决办法
8151
查看次数

从 Keras model.evaluate 和 model.predict 得到不同的结果

我已经训练了模型中使用word2vec和使用keras的LSTM模型来预测主题类别,并有大约训练期间98%的准确率,我保存的模型,然后装到另一个文件试图在测试集,我用model.evaluatemodel.predict,结果非常不一样。

我使用 keras 和 tensorflow 作为后端,模型摘要是:

_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
lstm_1 (LSTM)                (None, 22)                19624     
_________________________________________________________________
dropout_1 (Dropout)          (None, 22)                0         
_________________________________________________________________
dense_1 (Dense)              (None, 40)                920       
_________________________________________________________________
activation_1 (Activation)    (None, 40)                0         
=================================================================
Total params: 20,544
Trainable params: 20,544
Non-trainable params: 0
_________________________________________________________________
None
Run Code Online (Sandbox Code Playgroud)

编码:

model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
model.load_weights(os.path.join('model', 'lstm_model_weights.hdf5'))
score, acc = model.evaluate(x_test, y_test, batch_size=batch_size)

print()
print('Score: %1.4f' % score)
print('Evaluation Accuracy: %1.2f%%' % (acc*100))

predicted = model.predict(x_test, batch_size=batch_size)
acc2 …
Run Code Online (Sandbox Code Playgroud)

python machine-learning predict deep-learning keras

8
推荐指数
1
解决办法
2452
查看次数

Keras 预测给出的误差与评估不同,损失与指标不同

我有以下问题:

我在 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)

validation metric loss keras tensorflow

3
推荐指数
1
解决办法
2096
查看次数