Skip to content

Commit 2e16505

Browse files
committed
Merge pull request opencv#17624 from dkurt:dnn_optimize_mish
2 parents 8cc8b0d + 1491934 commit 2e16505

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

modules/dnn/src/layers/elementwise_layers.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -667,8 +667,11 @@ struct MishFunctor : public BaseFunctor
667667
{
668668
for( int i = 0; i < len; i++ )
669669
{
670+
// Use fast approximation introduced in https://github.com/opencv/opencv/pull/17200
670671
float x = srcptr[i];
671-
dstptr[i] = x * tanh(log(1.0f + exp(x)));
672+
float eX = exp(std::min(x, 20.f));
673+
float n = (eX + 2) * eX;
674+
dstptr[i] = (x * n) / (n + 2);
672675
}
673676
}
674677
}

0 commit comments

Comments
 (0)