I am experimenting replacing the Keras sigmoid function with a piecewise linear function defined as:
def custom_activation_4(x):
if x < -6:
return 0
elif x >= -6 and x < -4:
return (0.0078*x + 0.049)
elif x >= -4 and x < 0:
return (0.1205*x + 0.5)
elif x >= 0 and x < 4:
return (0.1205*x + 0.5)
elif x >= 4 and x < 6:
return (0.0078*x + 0.951)
else:
return 1;
When I try to run this as:
classifier_4.add(Dense(output_dim = 18, init = 'uniform', activation = custom_activation_4, input_dim = 9))
The compiler throws an error saying:
Using a `tf.Tensor` as a Python `bool` is not allowed.
I researched this and learned that, I am treating the variable x as a simple python variable whereas it is a tensor. That is the reason it cannot be treated like a simple boolean variable. I also tried using the tensorflow cond method. How to treat and use x as tensor here? Thanks a ton in advance for all the help.