Download model_cnn.py from bctnry/sanime2x: direct link, hf CLI and curl.
- Browser
- Download file 815 Bytes
-
https://huggingface.co/bctnry/sanime2x/resolve/main/model_cnn.py
- Command line
-
hf download hf://bctnry/sanime2x/model_cnn.py
-
curl -L -o model_cnn.py https://huggingface.co/bctnry/sanime2x/resolve/main/model_cnn.py
815 Bytes
| import torch | |
| import torch.nn as nn | |
| class PlainCNN(nn.Module): | |
| def __init__(self, layer=12): | |
| super().__init__() | |
| self.head = nn.Sequential( | |
| nn.Conv2d(3, 32, 3, 1, 1), nn.SiLU(), | |
| nn.Conv2d(32, 64, 3, 1, 1), nn.SiLU(), | |
| ) | |
| layers = [] | |
| for i in range(layer-4): | |
| layers.append(nn.Conv2d(64, 64, 3, 1, 1)) | |
| layers.append(nn.SiLU()) | |
| self.middle_part = nn.ModuleList(layers) | |
| self.tail = nn.Sequential( | |
| nn.Conv2d(64, 32, 3, 1, 1), nn.SiLU(), | |
| nn.Conv2d(32, 3, 3, 1, 1) | |
| ) | |
| def forward(self, x): | |
| # x :: (B, 3, 96, 96) | |
| res = x | |
| x = self.head(x) | |
| for b in self.middle_part: | |
| x = b(x) | |
| x = self.tail(x) | |
| x = x + res | |
| return x | |