deep learning - Can I add my own function in nn.Sequential? - Stack Overflow

I'm a beginner in machine learning. Recently, I'm trying to use CGAN for image generation and

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?

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742365526a4430218.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信