Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do you create custom activation? I got an error. #4076

Closed
ritchieng opened this issue Oct 15, 2016 · 3 comments
Closed

How do you create custom activation? I got an error. #4076

ritchieng opened this issue Oct 15, 2016 · 3 comments

Comments

@ritchieng
Copy link

This is what I tried to do.

def custom_activation(x):
    return (K.sigmoid(x) * 5) - 1

layer_3 = Dense(1, activation='sigmoid', init=lambda shape, name: normal(shape, scale=1e-4, name=name))(layer_2)

I got the following error:
Exception: Invalid activation function: custom_activation

@abishekk92
Copy link
Contributor

Looks like you're setting activation='sigmoid' in layer_3. If you're using your custom_activation function in layer_2 can you please share how the function is being passed?

A common construct in Keras for using custom_functions is to just use them in the argument.
For example:

Dense(activation=custom_activation)

or

model.add(Activation(custom_activation))

@ritchieng
Copy link
Author

@abishekk92 Thanks. I actually put colons that prevented it from working well.

@SwapnilBorse123
Copy link

@ritchieng Where did you put colons? Even I am trying to use piecewise linear functions instead of sigmoid function as activation. I am stuck around the same issue. Thanks in advance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants