简体   繁体   English

Keras张量流怪异损失精度

[英]Keras tensorflow weird loss accuracy

I developed a cnn + lstm network which take in input a vector (audio track) and each track has a specific emotional label called arousal and valence. 我开发了一个cnn + lstm网络,该网络输入一个矢量(音频轨道),每个轨道都有一个特定的情感标签,称为唤醒和化合价。
I must use a custom loss function called Concordance correlation coefficient, when I evaluate the loss value between the predictions and the test value I obtain about 99% value, but if I plot the signals they are too disagree. 我必须使用一个称为Concordance相关系数的自定义损耗函数,当我评估预测值和测试值之间的损耗值时,我获得了大约99%的值,但是如果我绘制信号,则它们太不一致了。

Below there is part of code, I take one audio track and for each of them I take a segment to train the model. 在下面的代码部分中,我采用了一个音轨,对于每个音轨都采用了一段代码来训练模型。 Each segment has a specific arousal-valence labels. 每个段都有一个特定的唤醒价标签。

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)  

Here there are the loss value (percent) 这里有损失值(百分比)

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
************

And here the plot, for example, prediction and arousal test of one audio track 这里是情节,例如,一个音轨的预测和唤醒测试

在此处输入图片说明

UPDATE: 更新:

It's always odd... 总是很奇怪...

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
************

and the new plot 和新情节

在此处输入图片说明

You are using covariance where it should be correlation. 您在应该相关的地方使用协方差。 Try simply: 简单尝试:

numerator = 2 * cov 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM