question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add custom activation function (Swish)

See original GitHub issue

TensorFlow.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:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
rthadurcommented, Mar 18, 2021

@harangp thank you added to activation config

0reactions
harangpcommented, Mar 18, 2021

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found