Download models/blocks.py from Angione-Lab/Shape2Force: direct link, hf CLI and curl.
- Browser
- Download file 925 Bytes
-
https://huggingface.co/Angione-Lab/Shape2Force/resolve/b74cd3bc79a2b6b4c1928d77864ba2e5ab3e1fda/models/blocks.py
- Command line
-
hf download hf://Angione-Lab/Shape2Force@b74cd3bc79a2b6b4c1928d77864ba2e5ab3e1fda/models/blocks.py
-
curl -L -o blocks.py https://huggingface.co/Angione-Lab/Shape2Force/resolve/b74cd3bc79a2b6b4c1928d77864ba2e5ab3e1fda/models/blocks.py
925 Bytes
| import torch.nn as nn | |
| import torch | |
| class ResidualBlock(nn.Module): | |
| def __init__(self, in_channels, out_channels): | |
| super(ResidualBlock, self).__init__() | |
| self.conv1 = nn.Conv2d(in_channels, out_channels, kernel_size=3, padding=1) | |
| self.bn1 = nn.BatchNorm2d(out_channels) | |
| self.conv2 = nn.Conv2d(out_channels, out_channels, kernel_size=3, padding=1) | |
| self.bn2 = nn.BatchNorm2d(out_channels) | |
| self.relu = nn.ReLU(inplace=True) | |
| self.downsample = nn.Conv2d(in_channels, out_channels, kernel_size=1) if in_channels != out_channels else None | |
| def forward(self, x): | |
| residual = x | |
| out = self.conv1(x) | |
| out = self.bn1(out) | |
| out = self.relu(out) | |
| out = self.conv2(out) | |
| out = self.bn2(out) | |
| if self.downsample: | |
| residual = self.downsample(x) | |
| out += residual | |
| out = self.relu(out) | |
| return out | |