<Neck_2>change Concat to WeightedAdd
This commit is contained in:
1 parent
e10e5dd65a
commit
8241503580
4 files changed
+69
-20
No files matched your search
@@ -1121,3 +1121,23 @@ class Classify(nn.Module):
|
||||
if isinstance(x, list):
|
||||
x = torch.cat(x, 1)
|
||||
return self.linear(self.drop(self.pool(self.conv(x)).flatten(1)))
|
||||
|
||||
# 以下是我自己添加的
|
||||
class WeightedAdd(nn.Module):
|
||||
"""
|
||||
Weighted feature fusion (BiFPN-style)
|
||||
inputs: list of feature maps with same shape
|
||||
"""
|
||||
def __init__(self, n_inputs, eps=1e-4):
|
||||
super().__init__()
|
||||
self.eps = eps
|
||||
self.w = nn.Parameter(torch.ones(n_inputs), requires_grad=True)
|
||||
|
||||
def forward(self, x):
|
||||
# x: list of tensors
|
||||
w = torch.relu(self.w)
|
||||
w = w / (w.sum() + self.eps)
|
||||
out = 0
|
||||
for i in range(len(x)):
|
||||
out += w[i] * x[i]
|
||||
return out
|
||||
Reference in new issue
Block a user