keras limiting output min max value

北城余情 提交于 2019-12-11 16:57:53

问题


My question is simple.

How do I make keras output to be limited with boundaries - min and max?

Some people suggest me to make a custom activation function to converts the output to transform in min and max values. I want it to be my last option.

I thought kernel_constraint and bias_constraint on Dense layer with min_max_norm will work but it turns out to be not working.


回答1:


If you can sacrifice the linearity of the activation function, then this is easy, you can use Sigmoid to get between 0 and 1 and then simply rescale your output, you will need to solve some equations to find the rescaling parameter which will be in the form

y_in_range = (y_pred + addConst)*multConst

And after a little bit of maths you will find that addConst = min/(max-min) and multConst = (max-min)

But remember you loose the linearity of your final activation layer, if you want it to be linear you have to make the entire function, I know this is also a sort of custom activation, but I believe this is the closest you will get to using an inbuilt keras function.



来源:https://stackoverflow.com/questions/54435998/keras-limiting-output-min-max-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!