mgharbi / demosaicnet_caffe

An implementation of Deep Joint Demosaicking and Denoising - SiGGRAPH Asia 2016
http://groups.csail.mit.edu/graphics/demosaicnet/
Other
109 stars 34 forks source link

Any mining hard example code ? thanks #15

Open junxigauss opened 5 years ago

junxigauss commented 5 years ago

I try it on mit data with pytorch except mining hard example, but false color and edge zipper is obvious. detail belows:

data:mit data(194w images) loss:L2 loss(averagesize = True) weight w initilize: n = m.kernel_size[0] m.kernel_size[1] m.inchannels m.weight.data.normal(0, math.sqrt(2. / n)) biases initilize: if m.bias is not None: m.bias.data.zero_() network input: 128*128 optimazation: adam, betas=(0.9, 0.999) weight decay: 1e-8 epoch: 40 learning rate: 1e-3,after 10epochs decrease by factor 10 normalize input data [-1, 1] batchsize:800 gpu:4x2080ti network structure:

def init(self, opt, skip, depth=15, width=64, pretrained=True, pad=True): super(BayerDemosaick, self).init()

self.depth = depth
self.width = width

if pad:
  pad = 1
else:
  pad = 0

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

self.main_processor = nn.Sequential(layers)
self.residual_predictor = nn.Conv2d(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, width, 3, padding=pad)),
  ("post_relu", nn.ReLU(inplace=True)),
  ("output", nn.Conv2d(width, 3, 1)),
  ]))

def _crop_like(self, src, tgt): """Crop a source image to match the spatial dimensions of a target.

Assumes sizes are even.

Args:
    src (th.Tensor or np.ndarray): image to be cropped
    tgt (th.Tensor or np.ndarray): reference image
"""
src_sz = np.array(src.shape)
tgt_sz = np.array(tgt.shape)

# Assumes the spatial dimensions are the last two
crop = (src_sz[-2:]-tgt_sz[-2:])
assert (np.mod(crop, 2) == 0).all(), "crop like sizes should be even"
crop //= 2
if (crop > 0).any():
    return src[..., crop[0]:src_sz[-2]-crop[0], crop[1]:src_sz[-1]-crop[1]]
else:
    return src

def forward(self, mosaic): """Demosaicks a Bayer image.

Args:
  mosaic (th.Tensor):  input Bayer mosaic

Returns:
  th.Tensor: the demosaicked image
"""

# 1/4 resolution features
features = self.main_processor(mosaic)
filters, masks = features[:, :self.width], features[:, self.width:]
filtered = filters * masks
residual = self.residual_predictor(filtered)

# Match mosaic and residual
upsampled = self.upsampler(residual)

cropped = self._crop_like(mosaic, upsampled)

packed = torch.cat([cropped, upsampled], 1)  # skip connection
output = self.fullres_processor(packed)
return output
junxigauss commented 5 years ago

no noise input

junxigauss commented 5 years ago

image image it's some test result . left : network output right: groundtruth

junxigauss commented 5 years ago

can you give me any advice? thanks very much

junxigauss commented 5 years ago

@mgharbi

junxigauss commented 5 years ago

no pretrained model