Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/Restorer/Cond_NAF.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,12 @@ def forward(self, x):


class ConditionedChannelAttention(nn.Module):
def __init__(self, dims, cat_dims):
def __init__(self, dims, cat_dims, out_dim=0):
super().__init__()
in_dim = dims + cat_dims
self.mlp = nn.Sequential(nn.Linear(in_dim, dims))
if not out_dim:
out_dim = dims
self.mlp = nn.Sequential(nn.Linear(in_dim, out_dim))
self.pool = nn.AdaptiveAvgPool2d(1)

def forward(self, x, conditioning):
Expand Down Expand Up @@ -95,7 +97,7 @@ def forward(self, x):
class CondFuser(nn.Module):
def __init__(self, chan, cond_chan=1):
super().__init__()
self.cca = ConditionedChannelAttention(chan * 2, cond_chan)
self.cca = ConditionedChannelAttention(chan * 2, cond_chan, out_dim=chan)
self.sig = nn.Sigmoid()

self.sa = nn.Sequential(
Expand All @@ -107,7 +109,7 @@ def __init__(self, chan, cond_chan=1):

def forward(self, x1, x2, cond):
x = torch.cat([x1, x2], dim=1)
x2 = 1 * self.sig(self.cca(x)) * self.sa(x) * x2
x2 = 1 * self.sig(self.cca(x, cond)) * self.sa(x) * x2
return x1 + x2


Expand Down
Loading