Skip to content

Instantly share code, notes, and snippets.

@Blaizzy
Last active May 3, 2020 18:55
Show Gist options
  • Select an option

  • Save Blaizzy/bbdc7da99c94e51e7cf5650e7fbf2459 to your computer and use it in GitHub Desktop.

Select an option

Save Blaizzy/bbdc7da99c94e51e7cf5650e7fbf2459 to your computer and use it in GitHub Desktop.
def conv(ni, nf, kernel_size = 3, actn=True):
layers = [nn.Conv2d(ni, nf, kernel_size, padding=kernel_size//2)]
if actn: layers.append(nn.ReLU(True))
return nn.Sequential(*layers)
#----------------------
class ResSequential(nn.Module):
def __init__(self, layers, res_scale=1.0):
super().__init__()
self.res_scale = res_scale # A factor less than 1.0 will help stabelize training
self.layers = nn.Sequential(*layers)
def forward(self, x): return x + self.layers(x) * self.res_scale
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment