Skip to content

Add custom activation function (Swish) #1804

@msprengholz

Description

@msprengholz

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.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions