admin管理员组文章数量:1334686
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?
本文标签: deep learningCan I add my own function in nnSequentialStack Overflow
版权声明:本文标题:deep learning - Can I add my own function in nn.Sequential? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742365526a2461192.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论