From 114939c1db199607c9c1f6df0d23e5c23b2915f2 Mon Sep 17 00:00:00 2001 From: Francois Fleuret Date: Sat, 3 Apr 2021 12:55:50 +0200 Subject: [PATCH] Simplified calls to superclass constructors. --- attentiontoy1d.py | 2 +- causal-autoregression.py | 6 +++--- hallu.py | 2 +- lazy_linear.py | 4 ++-- mi_estimator.py | 6 +++--- miniflow.py | 2 +- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/attentiontoy1d.py b/attentiontoy1d.py index d389f0c..b463340 100755 --- a/attentiontoy1d.py +++ b/attentiontoy1d.py @@ -181,7 +181,7 @@ def save_sequence_images(filename, sequences, tr = None, bx = None): class AttentionLayer(nn.Module): def __init__(self, in_channels, out_channels, key_channels): - super(AttentionLayer, self).__init__() + super().__init__() self.conv_Q = nn.Conv1d(in_channels, key_channels, kernel_size = 1, bias = False) self.conv_K = nn.Conv1d(in_channels, key_channels, kernel_size = 1, bias = False) self.conv_V = nn.Conv1d(in_channels, out_channels, kernel_size = 1, bias = False) diff --git a/causal-autoregression.py b/causal-autoregression.py index c2f6161..7754265 100755 --- a/causal-autoregression.py +++ b/causal-autoregression.py @@ -85,7 +85,7 @@ else: class NetToy1d(nn.Module): def __init__(self, nb_classes, ks = 2, nc = 32): - super(NetToy1d, self).__init__() + super().__init__() self.pad = (ks - 1, 0) self.conv0 = nn.Conv1d(1, nc, kernel_size = 1) self.conv1 = nn.Conv1d(nc, nc, kernel_size = ks) @@ -105,7 +105,7 @@ class NetToy1d(nn.Module): class NetToy1dWithDilation(nn.Module): def __init__(self, nb_classes, ks = 2, nc = 32): - super(NetToy1dWithDilation, self).__init__() + super().__init__() self.conv0 = nn.Conv1d(1, nc, kernel_size = 1) self.pad1 = ((ks-1) * 2, 0) self.conv1 = nn.Conv1d(nc, nc, kernel_size = ks, dilation = 2) @@ -130,7 +130,7 @@ class NetToy1dWithDilation(nn.Module): class PixelCNN(nn.Module): def __init__(self, nb_classes, in_channels = 1, ks = 5): - super(PixelCNN, self).__init__() + super().__init__() self.hpad = (ks//2, ks//2, ks//2, 0) self.vpad = (ks//2, 0, 0, 0) diff --git a/hallu.py b/hallu.py index b738b52..de25188 100755 --- a/hallu.py +++ b/hallu.py @@ -14,7 +14,7 @@ from torch.nn import functional as F class MultiScaleEdgeEnergy(torch.nn.Module): def __init__(self): - super(MultiScaleEdgeEnergy, self).__init__() + super().__init__() k = torch.exp(- torch.tensor([[-2., -1., 0., 1., 2.]])**2 / 2) k = (k.t() @ k).view(1, 1, 5, 5) self.gaussian_5x5 = torch.nn.Parameter(k / k.sum()).requires_grad_(False) diff --git a/lazy_linear.py b/lazy_linear.py index 2fa6a29..97530ef 100755 --- a/lazy_linear.py +++ b/lazy_linear.py @@ -12,7 +12,7 @@ from torch import nn, Tensor class LazyLinear(nn.Module): def __init__(self, out_dim, bias = True): - super(LazyLinear, self).__init__() + super().__init__() self.out_dim = out_dim self.bias = bias self.core = None @@ -30,7 +30,7 @@ class LazyLinear(nn.Module): def named_parameters(self, memo=None, prefix=''): assert self.core is not None, 'Parameters not yet defined' - return super(LazyLinear, self).named_parameters(memo, prefix) + return super().named_parameters(memo, prefix) ###################################################################### diff --git a/mi_estimator.py b/mi_estimator.py index 68fd51f..47381ef 100755 --- a/mi_estimator.py +++ b/mi_estimator.py @@ -226,7 +226,7 @@ def create_sequences_pairs(train = False): class NetForImagePair(nn.Module): def __init__(self): - super(NetForImagePair, self).__init__() + super().__init__() self.features_a = nn.Sequential( nn.Conv2d(1, 16, kernel_size = 5), nn.MaxPool2d(3), nn.ReLU(), @@ -257,7 +257,7 @@ class NetForImagePair(nn.Module): class NetForImageValuesPair(nn.Module): def __init__(self): - super(NetForImageValuesPair, self).__init__() + super().__init__() self.features_a = nn.Sequential( nn.Conv2d(1, 16, kernel_size = 5), nn.MaxPool2d(3), nn.ReLU(), @@ -306,7 +306,7 @@ class NetForSequencePair(nn.Module): ) def __init__(self): - super(NetForSequencePair, self).__init__() + super().__init__() self.nc = 32 self.nh = 256 diff --git a/miniflow.py b/miniflow.py index b5c8cb4..eb2d4c7 100755 --- a/miniflow.py +++ b/miniflow.py @@ -44,7 +44,7 @@ def LogProba(x, ldj): # START_MODEL class PiecewiseLinear(nn.Module): def __init__(self, nb, xmin, xmax): - super(PiecewiseLinear, self).__init__() + super().__init__() self.xmin = xmin self.xmax = xmax self.nb = nb -- 2.39.5