keras中model.compile如何设置自己的loss及参数

keras如果不能自己设置loss函数仍旧是小白一个,所以肯定要自己尝试做所有可能的事。

keras官方中文文档中发现loss的定义是y_true和y_pred的函数,也就是直接按照它的这种模式定义即可,至于数据流是怎么来的,这个问题还需要再认真考虑下,因为我的模型中的input不包含y_true,而训练的结果是两个y_pred,如何让模型知道我的输出是什么呢?这是个问题。

1-首先定义我的loss,这个简单,就是基本的MSE,其实也可以直接用官方的mse,说的对,这一步可以省略。

2-怎么输入y_true,怎么告诉模型哪个tensor是我的y_pred?这个问题有点懵逼,或者说这个不是个问题?不应该成为一个问题?不不,作为一个想要有所发展的小菜鸟,必须清楚的知道这些玩意,必须正面应对,不能逃避。

问了下同事,告诉我看看这个玩意,我先看看是啥子。灵光一闪,是否可以把两个tensor整成一个,毕竟shape相同,大不了是某个维度不同罢了。concat下??举个例子如下:

Input :y1,y2 both shape=(batch,5,513) after concat y1y2's shape=(batch,10,513)

No No NO, must know a question,In the MSE,the y_true and y_pred are not as input  nor the output,they are mid data ???

Let's have a example,sorry a little forget about the keras regression,now the example is here,

You can see the feed data,for example 

model.fit(TRAIN_X, TRAIN_Y, epochs=35000, validation_data=(TEST_X, TEST_Y), batch_size=TRAIN_X.shape[0], verbose=False)

对于回归问题、分类问题,X都是输入数据,Y是标签(标签或者预测的结果,可以是tensor),Y就是y_true,but X's shape maybe and commonly not same as Y,this question must be known. SO in my project, the X's shape is (batch,5,513), and the Y's shape is (batch, 10,513),that is, X is mixed signals' STFT and the Y is the y1y2——concated STFT of y1 and y2

回家了,等我回来接着写,回家种地。我看不到明天北京的太阳了。再见。

另外有相关问题可以加入QQ群讨论,不设微信群

QQ群:868373192 

语音深度学习群

发布了240 篇原创文章 · 获赞 233 · 访问量 7万+

猜你喜欢

转载自blog.csdn.net/SPESEG/article/details/101829351