Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore training conditionals for PLKSR, RealPLKSR, SPAN #276

Merged
merged 3 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
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
16 changes: 12 additions & 4 deletions libs/spandrel/spandrel/architectures/PLKSR/arch/PLKSR.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,19 @@ def __init__(self, dim, kernel_size, with_idt):
self.idx = dim

def forward(self, x: torch.Tensor) -> torch.Tensor:
if self.with_idt:
x[:, : self.idx] = x[:, : self.idx] + self.conv(x[:, : self.idx])
if self.training:
x1, x2 = torch.split(x, [self.idx, x.size(1) - self.idx], dim=1)
if self.with_idt:
x1 = self.conv(x1) + x1
else:
x1 = self.conv(x1)
return torch.cat([x1, x2], dim=1)
else:
x[:, : self.idx] = self.conv(x[:, : self.idx])
return x
if self.with_idt:
x[:, : self.idx] = x[:, : self.idx] + self.conv(x[:, : self.idx])
else:
x[:, : self.idx] = self.conv(x[:, : self.idx])
return x


class RectSparsePLKConv2d(nn.Module):
Expand Down
8 changes: 7 additions & 1 deletion libs/spandrel/spandrel/architectures/PLKSR/arch/RealPLKSR.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ def __init__(self, dim: int, kernel_size: int):
self.idx = dim

def forward(self, x: torch.Tensor) -> torch.Tensor:
if self.training:
x1, x2 = torch.split(x, [self.idx, x.size(1) - self.idx], dim=1)
x1 = self.conv(x1)
return torch.cat([x1, x2], dim=1)
x[:, : self.idx] = self.conv(x[:, : self.idx])
return x

Expand Down Expand Up @@ -109,7 +113,9 @@ def __init__(
dropout: float = 0,
):
super().__init__()
dropout = 0

if not self.training:
dropout = 0

self.feats = nn.Sequential(
*[nn.Conv2d(3, dim, 3, 1, 1)]
Expand Down
8 changes: 5 additions & 3 deletions libs/spandrel/spandrel/architectures/SPAN/arch/span.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,11 @@ def __init__(
stride=s,
bias=bias,
)
self.eval_conv.weight.requires_grad = False
self.eval_conv.bias.requires_grad = False # type: ignore
self.update_params()

if not self.training:
self.eval_conv.weight.requires_grad = False
self.eval_conv.bias.requires_grad = False # type: ignore
self.update_params()

def update_params(self):
w1 = self.conv[0].weight.data.clone().detach()
Expand Down
Loading