def __init__(self, config: HiDDenConfiguration): super(Encoder, self).__init__() self.H = config.H self.W = config.W self.conv_channels = config.encoder_channels self.num_blocks = config.encoder_blocks self.cover_dependent = config.cover_dependent # self.residual = config.residual if self.cover_dependent == 1: layers = [ConvBNRelu(3, self.conv_channels)] else: layers = [ConvBNRelu(config.message_length, self.conv_channels)] for _ in range(config.encoder_blocks - 1): layer = ConvBNRelu(self.conv_channels, self.conv_channels) layers.append(layer) self.conv_layers = nn.Sequential(*layers) if self.cover_dependent == 1: self.after_concat_layer = ConvBNRelu( self.conv_channels + 3 + config.message_length, self.conv_channels) else: self.after_concat_layer = ConvBNRelu(config.message_length, self.conv_channels) self.final_layer = nn.Conv2d(self.conv_channels, 3, kernel_size=1) self.final_tanh = nn.Tanh() self.factor = 10 / 255
def __init__(self, config: HiDDenConfiguration): super(Discriminator, self).__init__() layers = [ConvBNRelu(3, config.discriminator_channels)] for _ in range(config.discriminator_blocks-1): layers.append(ConvBNRelu(config.discriminator_channels, config.discriminator_channels)) layers.append(nn.AdaptiveAvgPool2d(output_size=(1, 1))) self.before_linear = nn.Sequential(*layers) self.linear = nn.Linear(config.discriminator_channels, 1)
def __init__(self, config: HiDDenConfiguration): super(Encoder, self).__init__() self.conv_channels = config.encoder_channels self.num_blocks = config.encoder_blocks layers = [ConvBNRelu(config.input_channels, self.conv_channels)] for _ in range(config.encoder_blocks-1): layer = ConvBNRelu(self.conv_channels, self.conv_channels) layers.append(layer) self.conv_layers = nn.Sequential(*layers) self.after_concat_layer = ConvBNRelu(self.conv_channels + config.input_channels + config.message_length, self.conv_channels) self.final_layer = nn.Conv2d(self.conv_channels, config.input_channels, kernel_size=1)
def __init__(self, config: HiDDenConfiguration): super().__init__() self.channels = config.decoder_channels self.num_blocks = config.decoder_blocks layers = [ConvBNRelu(3, self.channels)] for _ in range(self.num_blocks - 1): layer = ConvBNRelu(self.channels, self.channels) layers.append(layer) layers.append(ConvBNRelu(self.channels, config.message_length)) layers.append(nn.AdaptiveAvgPool2d(output_size=(1, 1))) self.layers = nn.Sequential(*layers) self.linear = nn.Linear(config.message_length, config.message_length)