Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
keras-team
GitHub Repository: keras-team/keras-io
Path: blob/master/templates/api/layers/activations.md
3297 views

Layer activation functions

Usage of activations

Activations can either be used through an Activation layer, or through the activation argument supported by all forward layers:

model.add(layers.Dense(64, activation=activations.relu))

This is equivalent to:

from keras import layers from keras import activations model.add(layers.Dense(64)) model.add(layers.Activation(activations.relu))

All built-in activations may also be passed via their string identifier:

model.add(layers.Dense(64, activation='relu'))

Available activations

{{autogenerated}}


Creating custom activations

You can also use a callable as an activation (in this case it should take a tensor and return a tensor of the same shape and dtype):

model.add(layers.Dense(64, activation=keras.ops.tanh))

About "advanced activation" layers

Activations that are more complex than a simple function (eg. learnable activations, which maintain a state) are available as Advanced Activation layers.