2017-03-29 44 views
2

我想剪辑值,我该怎么做?Keras回归剪辑值

我尝试使用这样的:

from keras.backend.tensorflow_backend import clip 
from keras.layers.core import Lambda 

... 
model.add(Dense(1)) 
model.add(Activation('linear')) 
model.add(Lambda(lambda x: clip(x, min_value=200, max_value=1000))) 

不过没关系,我把我的λ+夹的,它不会影响什么吗?

+0

你能打印出'model.summary()'?而且 - 通过剪辑不会影响任何你认为值不被剪切的东西,是的? –

回答

2

它实际上必须在model.compile步骤中作为损失实施。

from keras import backend as K 

def clipped_mse(y_true, y_pred): 
    return K.mean(K.square(K.clip(y_pred, 0., 1900.) - K.clip(y_true, 0., 1900.)), axis=-1) 

model.compile(loss=clipped_mse)