def __init__(self, config=Encoder_Localizer_config(), crop_size=(0.5, 0.5)): super(Encoder_Recovery, self).__init__() self.config = config device = config.device self.encoder = EncoderNetwork(is_embed_message=False, config=config).to(device) self.other_noise_layers = [Identity()] self.other_noise_layers.append(JpegCompression(device)) self.other_noise_layers.append(Quantization(device))
def __init__(self, noise_layers: list, device): super(Noiser, self).__init__() self.noise_layers = [Identity()] for layer in noise_layers: if type(layer) is str: if layer == 'JpegPlaceholder': #self.noise_layers.append(JpegCompression(device)) self.noise_layers.append(Jpeg(device, [70, 95])) elif layer == 'QuantizationPlaceholder': self.noise_layers.append(Quantization(device)) else: raise ValueError(f'Wrong layer placeholder string in Noiser.__init__().' f' Expected "JpegPlaceholder" or "QuantizationPlaceholder" but got {layer} instead') else: self.noise_layers.append(layer)
def __init__(self, device, jpeg_type='jpeg2'): super(Combined2, self).__init__() self.identity = Identity() if jpeg_type == 'jpeg2': self.jpeg = JpegCompression2() elif jpeg_type == 'jpeg': self.jpeg = JpegCompression(device) elif jpeg_type == 'diff_jpeg': self.jpeg = DiffJPEG() else: self.jpeg = Quantization() self.dropout = Dropout([0.3, 0.3]) self.gaussian = Gaussian() self.crop2 = Crop2( [0.187, 0.187], [0.187, 0.187]) # Crop2([0.547, 0.547], [0.547, 0.547]) self.cropout = Cropout([0.547, 0.547], [0.547, 0.547])
def __init__(self, noise_config: list, device: torch.device): super(Noiser, self).__init__() self.noise_config = noise_config noise_layers = [] for noise_layer_config in noise_config: layer_type = noise_layer_config['type'].lower() if layer_type == 'jpeg_compression': # TODO: Add jpeg compression level as a config option noise_layers.append(JpegCompression(device)) elif layer_type == 'crop': noise_layers.append( Crop(noise_layer_config['height_ratios'], noise_layer_config['width_ratios'])) elif layer_type == 'cropout': noise_layers.append( Cropout(noise_layer_config['height_ratios'], noise_layer_config['width_ratios'])) elif layer_type == 'dropout': noise_layers.append( Dropout(noise_layer_config['keep_ratio_range'])) elif layer_type == 'resize': if 'interpolation_method' in noise_layer_config: noise_layers.append( Resize(noise_layer_config['resize_ratio_range'], noise_layer_config['interpolation_method'])) else: noise_layers.append( Resize(noise_layer_config['resize_ratio_range'])) elif layer_type == 'rotate': pass elif layer_type == 'identity': noise_layers.append(Identity()) elif layer_type == 'quantization': noise_layers.append(Quantization()) else: raise ValueError('Noise layer of {} not supported'.format( noise_layer_config['type'])) self.noise_layers = nn.Sequential(*noise_layers)