From 804773c169d1b3b3c59ef97c5f0020361660acf9 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Fri, 23 Apr 2021 01:10:10 +0200 Subject: [PATCH] ACON Activation batch-size 1 bug path This is not a great solution to https://github.com/nmaac/acon/issues/4 but it's all I could think of at the moment. WARNING: YOLOv5 models with MetaAconC() activations are incapable of running inference at batch-size 1 properly due to a known bug in https://github.com/nmaac/acon/issues/4 with no known solution. --- utils/activations.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/utils/activations.py b/utils/activations.py index 1d095c1cf0f1..c00a70725c4c 100644 --- a/utils/activations.py +++ b/utils/activations.py @@ -91,6 +91,9 @@ def __init__(self, c1, k=1, s=1, r=16): # ch_in, kernel, stride, r def forward(self, x): y = x.mean(dim=2, keepdims=True).mean(dim=3, keepdims=True) - beta = torch.sigmoid(self.bn2(self.fc2(self.bn1(self.fc1(y))))) + if x.shape[0] > 1: # batch-size 1 bug https://github.com/nmaac/acon/issues/4 + beta = torch.sigmoid(self.bn2(self.fc2(self.bn1(self.fc1(y))))) + else: + beta = torch.sigmoid(self.fc2(self.fc1(y))) dpx = (self.p1 - self.p2) * x return dpx * torch.sigmoid(beta * dpx) + self.p2 * x