Hi all!
I keep getting this error:
RuntimeError: Calculated padded input size per channel: (3). Kernel size: (4). Kernel size can’t be greater than actual input size
I understand the error. I did all the calculations of the convolutions and transpose convolutions. There cannot be any input size channel 3. I don’t understand.
Here is my code:
class Discriminator(nn.Module):
def init(self, channels_img, features_d):
super(Discriminator, self).init()
self.disc = nn.Sequential(
# input: 1x1x4096
nn.Conv1d(1, 32, kernel_size=4, stride=2, padding=1), # 1x32x2048
nn.LeakyReLU(0.2),
# _block(in_channels, out_channels, kernel_size, stride, padding)
self._block(32, 64, 4, 2, 1), # 1x64x1024
self._block(64, 128, 4, 2, 1), # 1x128x512
self._block(128, 256, 4, 2, 1), # 1x256x256
nn.Conv1d(256, 1, kernel_size=256, stride=1, padding=0), # 1x1x1
)def _block(self, in_channels, out_channels, kernel_size, stride, padding): return nn.Sequential( nn.Conv1d( in_channels, out_channels, kernel_size, stride, padding, bias=False, ), nn.InstanceNorm1d(out_channels, affine=True), nn.LeakyReLU(0.2), ) def forward(self, x): return self.disc(x)
class Generator(nn.Module):
def init(self, channels_noise, channels_img, features_g):
super(Generator, self).init()
self.net = nn.Sequential(
# Input: 1x1x256
self._block(256, 256, 256, 1, 0), # 1x256x256
self._block(256, 128, 4, 2, 1), # 1x128x512
self._block(128, 64, 4, 2, 1), # 1x64x1024
self._block(64, 32, 4, 2, 1), # 1x32x2048
nn.ConvTranspose1d(32, 1, kernel_size=4, stride=2, padding=1),
# Output: 1x1x4096
nn.Tanh())def _block(self, in_channels, out_channels, kernel_size, stride, padding): return nn.Sequential( nn.ConvTranspose1d( in_channels, out_channels, kernel_size, stride, padding, bias=False, ), nn.BatchNorm1d(out_channels), nn.ReLU(), ) def forward(self, x): return self.net(x)
Thank you!!