在自定义Keras丢失(TF后端)中截断y_true

时间:2018-04-29 21:40:20

标签: python tensorflow keras

我想在学习方面消除填充的必要性对我的序列的影响,所以我试图在计算MSE之前删除序列可能具有的尾随零。对于稳定性来说,停止这种方式的渐变似乎比尝试提供不同长度的序列更好。

但是,我的代码会针对不同的方法抛出不同的错误。对于这种对我来说最有希望的方法,AttributeError: 'NoneType' object has no attribute 'dtype' K.update_sub(i,1)抛出def truncated_MSE(y_true, y_pred): i = K.int_shape(y_true)[0] i = K.update_sub(i,1) while y_true[i][0] == 0 and y_pred[i][1] == 0: i = K.update_sub(i,1) y_true = y_true[:i] y_pred = y_pred[:i] return K.mean(K.square(y_pred - y_true), axis=-1)

if (newsStory.ToShortDateString() == DateTime.Today.ToShortDateString())
                return "Todtay";
PS:如果这是一个糟糕的python编码风格,我很乐意学习!

1 个答案:

答案 0 :(得分:0)

错误来自于在常规整数上应用Keras后端函数而不是Tensor对象。

i = K.int_shape(y_true)[0]

此行生成一个int,因此不能在K.update_sub调用中使用。但是,您可以在其上使用普通的python整数计算。

相关问题