sanghyun-son / EDSR-PyTorch

PyTorch version of the paper 'Enhanced Deep Residual Networks for Single Image Super-Resolution' (CVPRW 2017)
MIT License
2.43k stars 669 forks source link

can we use gray data (1 channel) rather than RGB 3 channels data #252

Open AlphaDragon009 opened 4 years ago

AlphaDragon009 commented 4 years ago

How can we use it to deal with gray or 1 channel data ? How many places I need to modified? Thanks !

AlphaDragon009 commented 4 years ago

Nobody is interesting in this question ? or it is too simple to not want to answer ?

BTW: does anybody help me to change the code to 1 channel ? thanks !
class MeanShift(nn.Conv2d): def init( self, rgb_range, rgb_mean=(0.4488, 0.4371, 0.4040), rgb_std=(1.0, 1.0, 1.0), sign=-1):

    super(MeanShift, self).__init__(3, 3, kernel_size=1)
    std = torch.Tensor(rgb_std)
    self.weight.data = torch.eye(3).view(3, 3, 1, 1) / std.view(3, 1, 1, 1)
    self.bias.data = sign * rgb_range * torch.Tensor(rgb_mean) / std
    for p in self.parameters():
        p.requires_grad = False
Levishery commented 4 years ago

I trained my model using gray data by

  1. set option --n_colors to 1
  2. change getitem in class SRData: pair = self.get_patch(lr, hr) pair = common.set_channel(*pair, n_channels=self.args.n_colors) to lr, hr = common.set_channel(lr, hr, n_channels=self.args.n_colors) pair = self.get_patch(lr, hr) (if you don't change step 2, you will get a demention error in get_patch)
beecars commented 3 years ago

We also need to modify or remove the MeanShift class in common.py.

I have removed it for now for my low-spec proof-of-concept project, but it should be easy enough to transform the function to work for 1 channel.