答案 0 :(得分:1)
我创建了一个自定义回调来实现
class MergeMetrics(Callback):
def __init__(self,**kargs):
super(MergeMetrics,self).__init__(**kargs)
def on_epoch_begin(self,epoch, logs={}):
return
def on_epoch_end(self, epoch, logs={}):
logs['merge_mse'] = np.mean([logs[m] for m in logs.keys() if 'mse' in m])
logs['merge_mae'] = np.mean([logs[m] for m in logs.keys() if 'mae' in m])
我使用此回调合并来自2个不同输出的2个指标。例如,我使用一个简单的问题,但是您可以轻松地将其集成到您的问题中,并将其与验证集集成
这是虚拟示例,其中我使用mse和mae作为指标
X = np.random.uniform(0,1, (1000,10))
y1 = np.random.uniform(0,1, 1000)
y2 = np.random.uniform(0,1, 1000)
inp = Input((10,))
x = Dense(32, activation='relu')(inp)
out1 = Dense(1, name='y1')(x)
out2 = Dense(1, name='y2')(x)
m = Model(inp, [out1,out2])
m.compile('adam','mae', metrics=['mse','mae'])
checkpoint = MergeMetrics()
m.fit(X, [y1,y2], epochs=10, callbacks=[checkpoint])
打印输出为:
loss: ... - y1_mse: 0.2227 - y1_mae: 0.3884 - y2_mse: 0.1163 - y2_mae: 0.2805 - merge_mse: 0.1695 - merge_mae: 0.3345