SRCNN是首个端到端SR卷积神经网络, 其结构包含特征提取、非线性映射和重建三阶段。以下代码展示其PyTorch实现:
python
import torch
import torch.nn as nn
import torch.nn.functional as F
class SRCNN:
def __init__:
super.__init__
_factor = scale_factor
self.conv1 = nn.Conv2d
self.conv2 = nn.Conv2d
self.conv3 = nn.Conv2d
def forward:
x = F.relu)
x = F.relu)
x = self.conv3
return x
RRDB模型
RRDB模型是一种具有丰富残差连接和密集块结构的网络,其代码实现如下:
python
class RRDB:
def __init__:
super.__init__
_scale = res_scale
selfdenseblock1 = DenseBlock
selfdenseblock2 = DenseBlock
selfdenseblock3 = DenseBlock
selfconv = nn.Conv2d
def forward:
residual = x
out = selfdenseblock1
out = selfdenseblock2
out = selfdenseblock3
out = selfconv
return out * _scale + residual
ESRGAN模型
ESRGAN模型是一种结合了残差密集块和相对平均判别器的图像分辨率增强模型。其代码实现如下:
python
class ESRGAN:
def __init__:
super.__init__
self.conv1 = nn.Conv2d
self.denselayer = nn.Sequential for _ in range])
self.conv2 = nn.Conv2d
self.up = nn.Sequential, nn.Upsample)
self.conv3 = nn.Conv2d
def forward:
x = self.conv1
x = self.denselayer
x = self.conv2
x = self.up
x = self.conv3
return x