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)
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)
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)
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)
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)
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
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)
######################################################################
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(),
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(),
)
def __init__(self):
- super(NetForSequencePair, self).__init__()
+ super().__init__()
self.nc = 32
self.nh = 256
# 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