Beispiel #1
0
 def __init__(self, args, depth=3):
     super(Submodel, self).__init__()
     self.args = args
     self.depth = depth
     input_channel = 4
     if self.args.add_noise:
         input_channel = 5
     channel = 64 / args.submodel_div
     print('dalong log : check channel in SubModel ={}'.format(channel))
     self.BayerMosaic = layers.BayerMosaicLayer(args.bayer_type)
     self.Crop = layers.CropLayer()
     self.layer1 = OrderedDict()
     self.pack_layer = layers.PackBayerMosaicLayer(args.bayer_type)
     for index in range(depth):
         in_channel = 64
         out_channel = 64
         if index == 0:
             in_channel = input_channel
         if index == depth - 1:
             out_channel = 12
         self.layer1['layer_{}'.format(index)] = nn.Sequential(
             nn.Conv2d(in_channel, out_channel, kernel_size=3, padding=1),
             nn.LeakyReLU(negative_slope=0.2),
         )
     self.layer1 = nn.Sequential(self.layer1)
     self.postLayer1 = nn.Sequential(
         nn.ConvTranspose2d(12, 3, kernel_size=2, stride=2, groups=3),
         nn.LeakyReLU(negative_slope=0.2))
     self.postLayer2 = nn.Sequential(
         nn.Conv2d(6, 3, kernel_size=3, padding=1),
         nn.LeakyReLU(negative_slope=0.2),
         nn.Conv2d(3, 3, kernel_size=3, padding=1),
     )
     self.init_params()
Beispiel #2
0
  def __init__(self, weight=1.0, normalize=True):
    super(VGGLoss, self).__init__()

    self.normalize = normalize;
    self.weight = weight

    vgg = tmodels.vgg16(pretrained=True).features
    slices_idx = [
        [0, 4],
        [4, 9],
        [9, 16],
        [16, 23],
        [23, 30],
        ]
    self.net = torch.nn.Sequential()
    for i, idx in enumerate(slices_idx):
      seq = torch.nn.Sequential()
      for j in range(idx[0], idx[1]):
        seq.add_module(str(j), vgg[j])
      self.net.add_module(str(i), seq)

    for p in self.parameters():
      p.requires_grad = False

    self.mse = nn.MSELoss()
    self.CropLayer = layers.CropLayer();
Beispiel #3
0
 def __init__(self, args):
     super(FastDenoisaicking, self).__init__()
     self.pack = layers.PackBayerMosaicLayer(args.bayer_type, pack_depth=1)
     self.GMpreprocess = layers.GMPreprocess()
     self.RBpreprocess = layers.RBPreprocess()
     self.Lpreprocess = layers.LPreprocess()
     self.crop = layers.CropLayer()
     self.down_layer1 = nn.Sequential(
         nn.Conv2d(1, 16, kernel_size=3, stride=1, padding=1),
         nn.LeakyReLU(negative_slope=0.2),
         nn.Conv2d(16, 32, kernel_size=3, stride=1, padding=1),
         nn.LeakyReLU(negative_slope=0.2),
     )
     self.down_layer2 = nn.Sequential(
         nn.Conv2d(32, 64, kernel_size=3, stride=1, padding=1),
         nn.LeakyReLU(negative_slope=0.2),
         nn.Conv2d(64, 128, kernel_size=3, stride=1, padding=1),
         nn.LeakyReLU(negative_slope=0.2),
     )
     self.down_layer3 = nn.Sequential(
         nn.Conv2d(128, 256, kernel_size=3, stride=1, padding=1),
         nn.LeakyReLU(negative_slope=0.2),
         nn.Conv2d(256, 512, kernel_size=3, stride=1, padding=1),
     )
     self.pool = nn.AdaptiveAvgPool2d(1)
     self.fc1 = nn.Sequential(
         nn.Linear(512, 512),
         nn.LeakyReLU(negative_slope=0.2),
     )
     self.h2a = nn.Linear(512, 23**2)
     self.h2b = nn.Linear(512, 23**2)
     self.h1 = nn.Linear(512, 23**2)
     self.init_params()
Beispiel #4
0
    def __init__(self, args):
        super(BayerNetwork, self).__init__()

        self.mosaic_mask = layers.BayerMosaicLayer(bayer_type=args.bayer_type)
        self.crop_like = layers.CropLayer()
        self.depth = args.depth
        self.width = args.width

        layers1 = OrderedDict([
            ("pack_mosaic", nn.Conv2d(3, 4, 2, stride=2)
             ),  # Downsample 2x2 to re-establish translation invariance
        ])
        for i in range(self.depth):
            n_out = self.width
            n_in = self.width
            if i == 0:
                n_in = 4
            if i == self.depth - 1:
                n_out = 2 * self.width
            layers1["conv{}".format(i + 1)] = nn.Conv2d(n_in, n_out, 3)
            layers1["relu{}".format(i + 1)] = nn.ReLU(inplace=True)

        self.main_processor = nn.Sequential(layers1)
        self.residual_predictor = nn.Conv2d(self.width, 12, 1)
        self.upsampler = nn.ConvTranspose2d(12, 3, 2, stride=2, groups=3)

        self.fullres_processor = nn.Sequential(
            OrderedDict([
                ("post_conv", nn.Conv2d(6, self.width, 3)),
                ("post_relu", nn.ReLU(inplace=True)),
                ("output", nn.Conv2d(self.width, 3, 1)),
            ]))
        self.init_params()
Beispiel #5
0
 def __init__(self,pixel_weight = 1,percep_weight = 1):
     super(pixel_perceptural_loss,self).__init__();
     self.pixel_weight = pixel_weight;
     self.percep_weight = percep_weight;
     self.pixel = nn.L1Loss();
     self.percep = VGGLoss();
     self.CropLayer = layers.CropLayer();
Beispiel #6
0
 def __init__(self,
              depth,
              channel,
              ksize,
              pad=0,
              batchnorm=True,
              bayer_type='GRBG'):
     super(DemosaicNet, self).__init__()
     self.bayer_type = bayer_type
     # Pack the input to 4D inputs
     self.packmosaic = layers.PackBayerMosaicLayer()
     # conv_block
     self.preconv = layers.lowlevel_block(1, 4, channel, ksize, pad,
                                          batchnorm)
     self.block1 = layers.lowlevel_block(depth - 2, channel, channel, ksize,
                                         pad, batchnorm)
     self.conv15 = layers.lowlevel_block(1,
                                         channel,
                                         12,
                                         ksize,
                                         pad=0,
                                         batchnorm=batchnorm)
     # unpack the residul array to original inputs
     self.unpack = layers.UnpackBayerMosaicLayer()
     # original Mosaic array for 3 channels
     self.mosaic_mask = layers.BayerMosaicLayer(bayer_type=self.bayer_type)
     # crop the input with regard to reference
     self.crop_layer = layers.CropLayer()
     # full resolution convolution
     self.fullres_conv1 = layers.lowlevel_block(1, 6, channel, ksize, pad,
                                                batchnorm)
     self.fullres_conv2 = nn.Conv2d(channel,
                                    3,
                                    kernel_size=1,
                                    stride=1,
                                    padding=pad)
     # init the parameters
     self.init_params()
Beispiel #7
0
 def __init__(self):
     super(L2Loss,self).__init__();
     self.pixel_loss = torch.nn.MSELoss();
     self.perceptural_loss = 0;
     self.CropLayer = layers.CropLayer();
Beispiel #8
0
 def __init__(self):
   super(PSNR, self).__init__()
   self.mse = nn.MSELoss()
   self.CropLayer = layers.CropLayer();