Keras tensorflow奇怪的损失准确性

时间:2018-02-15 10:32:04

标签: python tensorflow keras

我开发了一个cnn + lstm网络,它输入一个矢量(音频轨道),每个轨道都有一个特定的情感标签,叫做唤醒和效价。
我必须使用称为一致性相关系数的自定义损失函数,当我评估预测值和测试值之间的损失值时,我获得了大约99%的值,但是如果我绘制信号它们太不一致了。

下面是代码的一部分,我带了一个音轨,每个音轨都采用一段来训练模型。每个细分都有特定的唤醒 - 效价标签。

for t in range(0, train_set.shape[0]):
    print('Traccia audio: ' + str(t+1))
    track = np.expand_dims(train_set[t], axis=2) # shape: (50, 96000, 1) 
    label_arousal = strided_app(train_arousal[t], 96000, 96000) # shape: (50, 96000)
    label_valence = strided_app(train_valence[t], 96000, 96000)
    for s in range(0, track.shape[0]):
        sub_track = np.expand_dims(track[s], axis=0) # shape: (1, 96000, 1)
        sub_arousal = np.expand_dims(label_arousal[s], axis=0) # shape: (1, 96000)
        sub_valence = np.expand_dims(label_valence[s], axis=0)
        model.fit(sub_track, [sub_arousal, sub_valence], batch_size=50, epochs=10, verbose=0)  

这里有损失值(百分比)

def ccc(x,y):

    x_mean = np.mean(x)
    y_mean = np.mean(y)

    x_var = np.var(x)
    y_var = np.var(y)

    x_std = np.std(x)
    y_std = np.std(y)

    cov = np.mean((x - x_mean) * (y - y_mean))

    numerator = 2 * cov * x_std * y_std

    denominator = x_var + y_var + (x_mean - y_mean) ** 2

    return (1 - numerator / denominator) * 100

for i in range(0, test_predictions_arousal.shape[0]):
    print('Traccia: ' + str(i+1))
    print('Arousal: ' + str(ccc(test_predictions_arousal[i], test_arousal[i])))
    print('Valence: ' + str(ccc(test_predictions_valence[i], test_valence[i])))
    print('************')

Traccia: 1
Arousal: 99.80387506604289
Valence: 99.99019742174045
************
Traccia: 2
Arousal: 99.90842777974784
Valence: 99.9833303193375
************
Traccia: 3
Arousal: 99.76175122350213
Valence: 99.91642446964116
************
Traccia: 4
Arousal: 99.69400971227803
Valence: 99.891768388332
************
Traccia: 5
Arousal: 99.64917025899855
Valence: 99.969865063012
************
Traccia: 6
Arousal: 100.31583120034135
Valence: 99.98139694474082
************
Traccia: 7
Arousal: 100.16018557121733
Valence: 99.98091831524982
************
Traccia: 8
Arousal: 99.9220169028413
Valence: 99.92336499923937
************
Traccia: 9
Arousal: 99.77060632255042
Valence: 100.03949036228647
************
Traccia: 10
Arousal: 100.0516664130463
Valence: 99.97031137929211
************
Traccia: 11
Arousal: 99.87796570089475
Valence: 99.98977148177909
************
Traccia: 12
Arousal: 99.40358994929626
Valence: 99.95646624327337
************

这里的情节,例如,一个音轨的预测和唤醒测试

enter image description here

更新:

总是很奇怪......

Traccia: 1
Arousal: 99.32691103454766
Valence: 99.30587783543801
************
Traccia: 2
Arousal: 99.63365628935205
Valence: 100.80776034855722
************
Traccia: 3
Arousal: 100.03581897568333
Valence: 99.54317949248193
************
Traccia: 4
Arousal: 99.64728586766705
Valence: 100.4571474364673
************
Traccia: 5
Arousal: 98.83308475135347
Valence: 100.00826448944555
************
Traccia: 6
Arousal: 99.23057248056854
Valence: 99.35969107562337
************
Traccia: 7
Arousal: 102.02497484030464
Valence: 99.9984707880692
************
Traccia: 8
Arousal: 99.81442313624571
Valence: 99.73086051788052
************
Traccia: 9
Arousal: 99.94000790770609
Valence: 99.54597275339133
************
Traccia: 10
Arousal: 99.32234708421316
Valence: 100.11396967864196
************
Traccia: 11
Arousal: 98.9037260945822
Valence: 99.67784995505049
************
Traccia: 12
Arousal: 100.17597068985451
Valence: 100.06106830968153
************

和新情节

enter image description here

1 个答案:

答案 0 :(得分:0)

您正在使用协方差,它应该是相关性。 试试吧:

numerator = 2 * cov