Add custom activation function (Swish)
See original GitHub issueTensorFlow.js version
1.1.0
Browser version
Chrome 75
Feature request
Add the Swish activation function (https://arxiv.org/abs/1710.05941). I tried implementing it by adding a custom layer, but I couldn’t get it to work. I looked into the source at activations.ts and it seems pretty easy to add Swish. Here’s my example code:
export class Swish extends Activation {
/** @nocollapse */
static readonly className = 'Swish';
/**
* Calculate the activation function.
*
* @param x: Input.
* @param alpha: Scaling factor for the sigmoid function.
* @return Output of the Swish activation.
*/
apply(x: Tensor, alpha = 1): Tensor {
return K.sigmoid(x.mul(alpha)).mul(x);
}
}
serialization.registerClass(Swish);
Sadly, I don’t know the whole process of contributing (Are there any other source file to change? What about testing?), so I’d like for someone else to implement this change.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Implementing Swish Activation Function in Keras
Let us do a quick recap just to make sure we know why we might want a custom one. Activation functions are quite...
Read more >How to create custom Activation functions in Keras ...
First you need to define a function using backend functions. As an example, here is how I implemented the swish activation function:
Read more >Using Custom Activation Functions in Keras - Sefik Ilkin Serengil
All you need is to create your custom activation function. In this case, I'll consume swish which is x times sigmoid.
Read more >Custom activation in tensorflow.js (Swish) - Stack Overflow
1 - Create a new file called hardTanh. · 2 - Start with these imports, we are going to need them · 3...
Read more >The Swish Activation Function - Paperspace Blog
The best discovered activation function, which we call Swish, is f(x)=x⋅sigmoid(βx) f ( x ) = x · s i g m o...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@harangp thank you added to activation config
While the swish activation is there in the codebase, unfortunately it is not exposed, so we can’t use it in a native way (I mean, adding an activation layer, and setting the activation to ‘swish’). ActivationConfig is missing the ‘swish’ literal. Could you add it too, please? Thx.