I'm a beginner in machine learning. Recently, I'm trying to use CGAN for image generation and lebelling. Currently, I'm manually doing circular padding in convolution operation as following.
def pad_dim(x, n=1):
x = torch.cat((x[:,:,:,-n:], x, x[:,:,:,:n]), axis=-1)
x = torch.cat((x[:,:,-n:,:], x, x[:,:,:n,:]), axis=-2)
return x
class pad_dim_x(nn.Module):
def forward(self, x):
#batch_size = x.shape[0]
return pad_dim(x, n=1)
...
class Generator(nn.Module):
...
self.main = nn.Sequential(
pad_dim_x(),
nn.ConvTranspose2d(ngf * 8, ngf * 4, 4, 2, 0, bias=False),
nn.BatchNorm2d(ngf * 4),
nn.ReLU(True),
...)
...
Some codes are omitted since they are common. My final goal is to integrate a custom function into nn.Sequential. Is my current approach correct?