glenn-jocher
commited on
Commit
•
9c7bb5a
1
Parent(s):
c0d3f80
ACON Activation batch-size 1 bug patch (#2901)
Browse files* 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.
* Update activations.py
* Update activations.py
* Update activations.py
* Update activations.py
- utils/activations.py +7 -5
utils/activations.py
CHANGED
@@ -84,13 +84,15 @@ class MetaAconC(nn.Module):
|
|
84 |
c2 = max(r, c1 // r)
|
85 |
self.p1 = nn.Parameter(torch.randn(1, c1, 1, 1))
|
86 |
self.p2 = nn.Parameter(torch.randn(1, c1, 1, 1))
|
87 |
-
self.fc1 = nn.Conv2d(c1, c2, k, s, bias=
|
88 |
-
self.
|
89 |
-
self.
|
90 |
-
self.bn2 = nn.BatchNorm2d(c1)
|
91 |
|
92 |
def forward(self, x):
|
93 |
y = x.mean(dim=2, keepdims=True).mean(dim=3, keepdims=True)
|
94 |
-
|
|
|
|
|
95 |
dpx = (self.p1 - self.p2) * x
|
96 |
return dpx * torch.sigmoid(beta * dpx) + self.p2 * x
|
|
|
84 |
c2 = max(r, c1 // r)
|
85 |
self.p1 = nn.Parameter(torch.randn(1, c1, 1, 1))
|
86 |
self.p2 = nn.Parameter(torch.randn(1, c1, 1, 1))
|
87 |
+
self.fc1 = nn.Conv2d(c1, c2, k, s, bias=True)
|
88 |
+
self.fc2 = nn.Conv2d(c2, c1, k, s, bias=True)
|
89 |
+
# self.bn1 = nn.BatchNorm2d(c2)
|
90 |
+
# self.bn2 = nn.BatchNorm2d(c1)
|
91 |
|
92 |
def forward(self, x):
|
93 |
y = x.mean(dim=2, keepdims=True).mean(dim=3, keepdims=True)
|
94 |
+
# batch-size 1 bug/instabilities https://github.com/ultralytics/yolov5/issues/2891
|
95 |
+
# beta = torch.sigmoid(self.bn2(self.fc2(self.bn1(self.fc1(y))))) # bug/unstable
|
96 |
+
beta = torch.sigmoid(self.fc2(self.fc1(y))) # bug patch BN layers removed
|
97 |
dpx = (self.p1 - self.p2) * x
|
98 |
return dpx * torch.sigmoid(beta * dpx) + self.p2 * x
|