-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathmodels.py
74 lines (65 loc) · 3.13 KB
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
"""
Copyright (C) 2018 Axel Davy
Copyright (C) 2018 Yiqi Yan
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
This is a modified version derived from
https://github.com/SaoYan/DnCNN-PyTorch/blob/master/models.py
"""
import torch
import torch.nn as nn
class ModifiedDnCNN(nn.Module):
def __init__(self, input_channels, output_channels, nlconv_features, nlconv_layers, dnnconv_features, dnnconv_layers):
super(ModifiedDnCNN, self).__init__()
self.input_channels = input_channels
self.output_channels = output_channels
self.nlconv_features = nlconv_features
self.nlconv_layers = nlconv_layers
self.dnnconv_features = dnnconv_features
self.dnnconv_layers = dnnconv_layers
layers = []
layers.append(nn.Conv2d(in_channels=self.input_channels,\
out_channels=self.nlconv_features,\
kernel_size=1,\
padding=0,\
bias=True))
layers.append(nn.ReLU(inplace=True))
for _ in range(self.nlconv_layers-1):
layers.append(nn.Conv2d(in_channels=self.nlconv_features,\
out_channels=self.nlconv_features,\
kernel_size=1,\
padding=0,\
bias=True))
layers.append(nn.ReLU(inplace=True))
# Shorter DnCNN
layers.append(nn.Conv2d(in_channels=self.nlconv_features,\
out_channels=self.dnnconv_features,\
kernel_size=3,\
padding=1,\
bias=False))
layers.append(nn.ReLU(inplace=True))
for _ in range(self.dnnconv_layers-2):
layers.append(nn.Conv2d(in_channels=self.dnnconv_features,\
out_channels=self.dnnconv_features,\
kernel_size=3,\
padding=1,\
bias=False))
layers.append(nn.BatchNorm2d(self.dnnconv_features))
layers.append(nn.ReLU(inplace=True))
layers.append(nn.Conv2d(in_channels=self.dnnconv_features,\
out_channels=self.output_channels,\
kernel_size=3,\
padding=1,\
bias=False))
self.net = nn.Sequential(*layers)
def forward(self, x):
out = self.net(x)
return out