How Can I Clip The Values Returned By A Layer In Keras?
How can I clip the values returned by the Lambda layer? I tried using this: from keras.backend.tensorflow_backend import clip from keras.layers.core import Lambda ... model.add(De
Solution 1:
It actually has to be implemented as loss, at the model.compile step.
from keras import backend as K
defclipped_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)
EDIT: Actually, now in hindsight I think that this might not be the right approach. This actually means we do not add penalty for going over too high of a values - it's in a way the opposite of what we want.
Post a Comment for "How Can I Clip The Values Returned By A Layer In Keras?"