Spaces:
Running on Zero
Running on Zero
Download diffcve/modules/residual.py from hugging-apps/diffcve-2607: direct link, hf CLI and curl.
- Browser
- Download file 1.12 kB
-
https://huggingface.co/spaces/hugging-apps/diffcve-2607/resolve/main/diffcve/modules/residual.py
- Command line
-
hf download hf://spaces/hugging-apps/diffcve-2607/diffcve/modules/residual.py
-
curl -L -o residual.py https://huggingface.co/spaces/hugging-apps/diffcve-2607/resolve/main/diffcve/modules/residual.py
1.12 kB
| import torch | |
| from torch import nn as nn | |
| from .initialization import default_init_weights | |
| class ResidualDenseBlock(nn.Module): | |
| def __init__(self, num_feat=64, num_grow_ch=32): | |
| super(ResidualDenseBlock, self).__init__() | |
| self.conv1 = nn.Conv2d(num_feat, num_grow_ch, 3, 1, 1) | |
| self.conv2 = nn.Conv2d(num_feat + num_grow_ch, num_grow_ch, 3, 1, 1) | |
| self.conv3 = nn.Conv2d(num_feat + 2 * num_grow_ch, num_grow_ch, 3, 1, 1) | |
| self.conv4 = nn.Conv2d(num_feat + 3 * num_grow_ch, num_grow_ch, 3, 1, 1) | |
| self.conv5 = nn.Conv2d(num_feat + 4 * num_grow_ch, num_feat, 3, 1, 1) | |
| self.lrelu = nn.LeakyReLU(negative_slope=0.2, inplace=True) | |
| default_init_weights([self.conv1, self.conv2, self.conv3, self.conv4, self.conv5], 0.1) | |
| def forward(self, x): | |
| x1 = self.lrelu(self.conv1(x)) | |
| x2 = self.lrelu(self.conv2(torch.cat((x, x1), 1))) | |
| x3 = self.lrelu(self.conv3(torch.cat((x, x1, x2), 1))) | |
| x4 = self.lrelu(self.conv4(torch.cat((x, x1, x2, x3), 1))) | |
| x5 = self.conv5(torch.cat((x, x1, x2, x3, x4), 1)) | |
| return x5 * 0.2 + x | |