问题
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