Download Analysis_code/resnet_like.py from bong9513/Visibility_Nowcasting: direct link, hf CLI and curl.
- Browser
- Download file 1.38 kB
-
https://huggingface.co/bong9513/Visibility_Nowcasting/resolve/refs%2Fpr%2F1/Analysis_code/resnet_like.py
- Command line
-
hf download hf://bong9513/Visibility_Nowcasting@refs/pr/1/Analysis_code/resnet_like.py
-
curl -L -o resnet_like.py https://huggingface.co/bong9513/Visibility_Nowcasting/resolve/refs%2Fpr%2F1/Analysis_code/resnet_like.py
1.38 kB
| import torch | |
| import torch.nn as nn | |
| import torch.nn.functional as F | |
| # ResNet-like Implementation | |
| class ResNetLike(nn.Module): | |
| def __init__(self, num_classes, input_dim, d_main=128, d_hidden=64, n_blocks=4, dropout_first=0.25, dropout_second=0.0): | |
| super(ResNetLike, self).__init__() | |
| self.num_classes = num_classes # ํด๋์ค ๊ฐ์ ์ ์ฅ | |
| # Input layer | |
| self.input_layer = nn.Linear(input_dim, d_main) | |
| # Residual blocks | |
| self.blocks = nn.ModuleList([ | |
| nn.Sequential( | |
| nn.Linear(d_main, d_hidden), | |
| nn.ReLU(), | |
| nn.Dropout(dropout_first), | |
| nn.Linear(d_hidden, d_main), | |
| nn.Dropout(dropout_second) | |
| ) for _ in range(n_blocks) | |
| ]) | |
| if num_classes == 2: | |
| self.output_layer = nn.Linear(d_main, 1) # Binary classification | |
| elif num_classes > 2: | |
| self.output_layer = nn.Linear(d_main, num_classes) # Multi classification | |
| def forward(self, x_num, x_cat): # ๋ ๊ฐ์ ์ ๋ ฅ์ ๋ฐ์ | |
| x = torch.cat([x_num, x_cat], dim=1) # ๋ ๊ฐ๋ฅผ ํ๋๋ก ํฉ์ณ์ ๋ชจ๋ธ์ ์ ๋ฌ | |
| x = F.relu(self.input_layer(x)) | |
| for block in self.blocks: | |
| x = x + block(x) # Residual connection | |
| x = self.output_layer(x) | |
| return x | |