| 31 | |
| 32 | #采用PixelShuffle进行上采样 |
| 33 | class UpsampleBlock(torch.nn.Module): |
| 34 | def __init__(self,in_channels,scale_factor): |
| 35 | super(UpsampleBlock, self).__init__() |
| 36 | self.conv = torch.nn.Conv2d(in_channels,in_channels*scale_factor**2,kernel_size = (3,3),stride = (1,1),padding=(1,1)) |
| 37 | #(in_channels * 4,H,W) => (in_channels,H*2,W*2) |
| 38 | self.ps = torch.nn.PixelShuffle(scale_factor) |
| 39 | self.act = torch.nn.PReLU(num_parameters=in_channels) |
| 40 | def forward(self,x): |
| 41 | out = self.act(self.ps(self.conv(x))) |
| 42 | return out |
| 43 | |
| 44 | |
| 45 | class ResidualBlock(torch.nn.Module): |