|
import torch.nn as nn
|
|
class Decoder_MV(nn.Module):
|
|
def __init__(self, d_model=768, seq_input=False):
|
|
super(Decoder_MV, self).__init__()
|
|
self.d_model = d_model
|
|
self.seq_input = seq_input
|
|
self.decoder = nn.Sequential(
|
|
|
|
|
|
|
|
nn.ReflectionPad2d(1),
|
|
nn.Conv2d(int(self.d_model), 256, 3, 1, 0),
|
|
nn.ReLU(),
|
|
nn.Upsample(scale_factor=2, mode='nearest'),
|
|
nn.ReflectionPad2d(1),
|
|
nn.Conv2d(256, 256, 3, 1, 0),
|
|
nn.ReLU(),
|
|
nn.ReflectionPad2d(1),
|
|
nn.Conv2d(256, 256, 3, 1, 0),
|
|
nn.ReLU(),
|
|
nn.ReflectionPad2d(1),
|
|
nn.Conv2d(256, 256, 3, 1, 0),
|
|
nn.ReLU(),
|
|
|
|
|
|
nn.ReflectionPad2d(1),
|
|
nn.Conv2d(256, 128, 3, 1, 0),
|
|
nn.ReLU(),
|
|
nn.Upsample(scale_factor=2, mode='nearest'),
|
|
nn.ReflectionPad2d(1),
|
|
nn.Conv2d(128, 128, 3, 1, 0),
|
|
nn.ReLU(),
|
|
|
|
|
|
nn.ReflectionPad2d(1),
|
|
nn.Conv2d(128, 64, 3, 1, 0),
|
|
nn.ReLU(),
|
|
nn.Upsample(scale_factor=2, mode='nearest'),
|
|
nn.ReflectionPad2d(1),
|
|
nn.Conv2d(64, 64, 3, 1, 0),
|
|
nn.ReLU(),
|
|
|
|
|
|
nn.ReflectionPad2d(1),
|
|
nn.Conv2d(64, 3, 3, 1, 0),
|
|
)
|
|
|
|
def forward(self, x, input_resolution):
|
|
if self.seq_input == True:
|
|
B, N, C = x.size()
|
|
|
|
(H, W) = input_resolution
|
|
x = x.permute(0, 2, 1).reshape(B, C, H, W)
|
|
x = self.decoder(x)
|
|
return x
|
|
|
|
vgg_structures = nn.Sequential(
|
|
nn.Conv2d(3, 3, (1, 1)),
|
|
nn.ReflectionPad2d((1, 1, 1, 1)),
|
|
nn.Conv2d(3, 64, (3, 3)),
|
|
nn.ReLU(),
|
|
nn.ReflectionPad2d((1, 1, 1, 1)),
|
|
nn.Conv2d(64, 64, (3, 3)),
|
|
nn.ReLU(),
|
|
nn.MaxPool2d((2, 2), (2, 2), (0, 0), ceil_mode=True),
|
|
nn.ReflectionPad2d((1, 1, 1, 1)),
|
|
nn.Conv2d(64, 128, (3, 3)),
|
|
nn.ReLU(),
|
|
nn.ReflectionPad2d((1, 1, 1, 1)),
|
|
nn.Conv2d(128, 128, (3, 3)),
|
|
nn.ReLU(),
|
|
nn.MaxPool2d((2, 2), (2, 2), (0, 0), ceil_mode=True),
|
|
nn.ReflectionPad2d((1, 1, 1, 1)),
|
|
nn.Conv2d(128, 256, (3, 3)),
|
|
nn.ReLU(),
|
|
nn.ReflectionPad2d((1, 1, 1, 1)),
|
|
nn.Conv2d(256, 256, (3, 3)),
|
|
nn.ReLU(),
|
|
nn.ReflectionPad2d((1, 1, 1, 1)),
|
|
nn.Conv2d(256, 256, (3, 3)),
|
|
nn.ReLU(),
|
|
nn.ReflectionPad2d((1, 1, 1, 1)),
|
|
nn.Conv2d(256, 256, (3, 3)),
|
|
nn.ReLU(),
|
|
nn.MaxPool2d((2, 2), (2, 2), (0, 0), ceil_mode=True),
|
|
nn.ReflectionPad2d((1, 1, 1, 1)),
|
|
nn.Conv2d(256, 512, (3, 3)),
|
|
nn.ReLU(),
|
|
nn.ReflectionPad2d((1, 1, 1, 1)),
|
|
nn.Conv2d(512, 512, (3, 3)),
|
|
nn.ReLU(),
|
|
nn.ReflectionPad2d((1, 1, 1, 1)),
|
|
nn.Conv2d(512, 512, (3, 3)),
|
|
nn.ReLU(),
|
|
nn.ReflectionPad2d((1, 1, 1, 1)),
|
|
nn.Conv2d(512, 512, (3, 3)),
|
|
nn.ReLU(),
|
|
nn.MaxPool2d((2, 2), (2, 2), (0, 0), ceil_mode=True),
|
|
nn.ReflectionPad2d((1, 1, 1, 1)),
|
|
nn.Conv2d(512, 512, (3, 3)),
|
|
nn.ReLU(),
|
|
nn.ReflectionPad2d((1, 1, 1, 1)),
|
|
nn.Conv2d(512, 512, (3, 3)),
|
|
nn.ReLU(),
|
|
nn.ReflectionPad2d((1, 1, 1, 1)),
|
|
nn.Conv2d(512, 512, (3, 3)),
|
|
nn.ReLU(),
|
|
nn.ReflectionPad2d((1, 1, 1, 1)),
|
|
nn.Conv2d(512, 512, (3, 3)),
|
|
nn.ReLU()
|
|
)
|
|
|
|
decoder_stem = nn.Sequential(
|
|
nn.ReflectionPad2d((1, 1, 1, 1)),
|
|
nn.Conv2d(512, 256, (3, 3)),
|
|
nn.ReLU(),
|
|
nn.Upsample(scale_factor=2, mode='nearest'),
|
|
nn.ReflectionPad2d((1, 1, 1, 1)),
|
|
nn.Conv2d(256, 256, (3, 3)),
|
|
nn.ReLU(),
|
|
nn.ReflectionPad2d((1, 1, 1, 1)),
|
|
nn.Conv2d(256, 256, (3, 3)),
|
|
nn.ReLU(),
|
|
nn.ReflectionPad2d((1, 1, 1, 1)),
|
|
nn.Conv2d(256, 256, (3, 3)),
|
|
nn.ReLU(),
|
|
nn.ReflectionPad2d((1, 1, 1, 1)),
|
|
nn.Conv2d(256, 128, (3, 3)),
|
|
nn.ReLU(),
|
|
nn.Upsample(scale_factor=2, mode='nearest'),
|
|
nn.ReflectionPad2d((1, 1, 1, 1)),
|
|
nn.Conv2d(128, 128, (3, 3)),
|
|
nn.ReLU(),
|
|
nn.ReflectionPad2d((1, 1, 1, 1)),
|
|
nn.Conv2d(128, 64, (3, 3)),
|
|
nn.ReLU(),
|
|
nn.Upsample(scale_factor=2, mode='nearest'),
|
|
nn.ReflectionPad2d((1, 1, 1, 1)),
|
|
nn.Conv2d(64, 64, (3, 3)),
|
|
nn.ReLU(),
|
|
nn.ReflectionPad2d((1, 1, 1, 1)),
|
|
nn.Conv2d(64, 3, (3, 3)),
|
|
) |