The Mish activation function is a smooth, non-monotonic activation defined as the input times the hyperbolic tangent of its softplus: \( f(x) = x \tanh(\ln(1 + e^{x})) \). It looks like ReLU for large positive inputs, lets small negative values through instead of zeroing them, and has no setting to tune. Enter any input below to get Mish, its derivative and the matching Swish and ReLU values, with every step shown.
What is the Mish activation function?
Mish was proposed by Diganta Misra in 2019 as a self-regularised, non-monotonic activation for deep networks. It is built from two pieces you may already know. First the softplus function, \( \mathrm{softplus}(x) = \ln(1 + e^{x}) \), a smooth version of ReLU. Then the tanh function, which squashes that result into the range 0 to 1 (softplus is always positive). Multiplying by \( x \) gives the formula:
\[ \mathrm{Mish}(x) = x \cdot \tanh\big(\ln(1 + e^{x})\big) \]
The tanh factor acts like a soft gate. For large positive \( x \) it is almost exactly 1, so Mish is close to \( x \), just like ReLU. For large negative \( x \) it is close to 0, so the output fades towards 0. In between, small negative inputs produce small negative outputs, with a minimum of about −0.309 near \( x \approx -1.19 \). The function is bounded below, unbounded above, smooth everywhere and not monotonic (it dips before it rises).
A handy algebraic shortcut: because \( \tanh(\ln s) = \frac{s^2 – 1}{s^2 + 1} \), the formula can also be written without logs as
\[ \mathrm{Mish}(x) = x \cdot \frac{e^{2x} + 2e^{x}}{e^{2x} + 2e^{x} + 2} \]
Worked example: Mish of 1 and −1
Take \( x = 1 \), the value loaded in the calculator.
- Softplus: \( e^{1} = 2.718282 \), so \( \ln(1 + 2.718282) = \ln(3.718282) = 1.313262 \).
- Tanh: \( \tanh(1.313262) = 0.865098 \).
- Multiply by x: \( 1 \times 0.865098 = 0.865098 \).
So \( \mathrm{Mish}(1) = 0.865098 \) (to ten places, 0.8650983883). Compare Swish, \( 1 \times \sigma(1) = 0.731059 \), and ReLU, which gives 1.
Now \( x = -1 \). Softplus is \( \ln(1 + 0.367879) = 0.313262 \), tanh of that is 0.303401, and multiplying by −1 gives \( \mathrm{Mish}(-1) = -0.303401 \). ReLU would output 0 here and pass no gradient. A few more values from the same function:
| x | Mish(x) | Swish(x) | ReLU(x) |
|---|---|---|---|
| −5 | −0.033576 | −0.033464 | 0 |
| −2 | −0.252501 | −0.238406 | 0 |
| −0.5 | −0.220744 | −0.188770 | 0 |
| 0.5 | 0.375245 | 0.311230 | 0.5 |
| 2 | 1.943959 | 1.761594 | 2 |
| 5 | 4.999552 | 4.966536 | 5 |
The derivative of Mish
To train a network with the Mish activation function you need its gradient. Using the product rule and the chain rule, with \( \mathrm{sp} = \ln(1+e^x) \) and the sigmoid \( \sigma(x) \) as the derivative of softplus:
\[ \mathrm{Mish}'(x) = \tanh(\mathrm{sp}) + x \,\mathrm{sech}^2(\mathrm{sp})\,\sigma(x) \]
At \( x = 1 \): \( \tanh(\mathrm{sp}) = 0.865098 \), \( \mathrm{sech}^2(\mathrm{sp}) = 1 – 0.865098^2 = 0.251605 \) and \( \sigma(1) = 0.731059 \), so the derivative is \( 0.865098 + 0.183938 = 1.049036 \). It is slightly above 1, a small overshoot that Swish shares. For negative inputs the gradient is small but not zero, which is the main argument for Mish over ReLU during backpropagation: units do not get stuck at exactly zero gradient.
When to use Mish, and when not to
Use the Mish activation function when you are training a deep convolutional network and want to try a smooth drop-in replacement for ReLU or Leaky ReLU. Its best-known use is the CSPDarknet53 backbone of the YOLOv4 object detector. The original paper reports small accuracy gains over Swish and ReLU on several image benchmarks; independent results vary by architecture and training setup, so treat it as one more option to test, not a guaranteed win.
Skip it when speed matters most. Mish needs an exponential, a log and a tanh per value, so it is noticeably more expensive than ReLU, and some inference runtimes have no fused kernel for it. It also does not remove the need for good initialisation or normalisation, and it will not fix a learning rate that is too high. For transformers, GELU remains the usual default. The activation functions guide covers the trade-offs across the whole family.
Mish vs Swish (and ReLU)
Swish (also called SiLU) is the nearest relative: \( \mathrm{Swish}(x) = x\,\sigma(x) \). Both multiply the input by a smooth gate between 0 and 1. Mish uses \( \tanh(\mathrm{softplus}(x)) \) as its gate, which rises a little faster, so Mish sits slightly above Swish for positive inputs and dips a little deeper for negative ones.
| Mish | Swish / SiLU | ReLU | |
|---|---|---|---|
| Formula | \( x \tanh(\ln(1+e^x)) \) | \( x\,\sigma(x) \) | \( \max(0, x) \) |
| Minimum value | about −0.309 at \( x \approx -1.19 \) | about −0.278 at \( x \approx -1.28 \) | 0 |
| Smooth at 0 | Yes | Yes | No (kink) |
| Gradient for negative x | Small, non-zero | Small, non-zero | Exactly 0 |
| Cost | Highest (exp, log, tanh) | Medium (one exp) | Lowest |
| PyTorch | nn.Mish | nn.SiLU | nn.ReLU |
In practice the Mish activation function and Swish behave very similarly; if Swish is already fast in your framework, the difference may not justify the extra cost. Both help with the vanishing gradient problem compared with sigmoid or tanh alone, because neither saturates for positive inputs.
Common mistakes
- Computing softplus naively. \( \ln(1 + e^{x}) \) overflows once \( e^{x} \) exceeds the float range (around \( x = 710 \) in 64-bit, much sooner in 16-bit). Use the stable form \( \max(x, 0) + \ln(1 + e^{-|x|}) \), as this calculator does.
- Confusing Mish with Swish. They have similar shapes but different formulas; \( \mathrm{Mish}(1) = 0.865 \) while \( \mathrm{Swish}(1) = 0.731 \).
- Using it on the output layer. Mish is a hidden-layer activation. For outputs, use sigmoid, softmax or a linear unit to match the loss.
- Expecting outputs of exactly zero. Unlike ReLU, Mish is never exactly 0 except at \( x = 0 \), so it does not give sparse activations.
- Comparing activations with one run. Differences between Mish, Swish and GELU are often smaller than run-to-run noise; repeat with several seeds before deciding.
Frequently asked questions
What is the formula of the Mish activation function?
Mish(x) = x · tanh(softplus(x)) = x · tanh(ln(1 + ex)). It needs no parameters.
What is the range of Mish?
From about −0.309 up to infinity. It is bounded below and unbounded above, like Swish.
Is Mish better than ReLU?
Sometimes. The paper and some later work report small gains in deep CNNs, but results depend on the model and data, and ReLU is much cheaper to compute. Test both on your own validation set.
How do I use Mish in PyTorch or Keras?
PyTorch has torch.nn.Mish and torch.nn.functional.mish. Recent Keras versions include a mish activation; older TensorFlow setups used the TensorFlow Addons package. You can also write it in one line from the formula.
Why is Mish called self-regularised?
The author used the term for the extra term in the derivative that behaves like a preconditioner and smooths the gradient. It is a description from the paper, not a replacement for regularisation such as dropout or weight decay.
Sources: Misra, Mish: A Self Regularized Non-Monotonic Activation Function (arXiv), and the PyTorch nn.Mish documentation.