Spaces:
Sleeping
Sleeping
Download src/handwriting/model.py from lzpiece/IntelligentHandwrittenCGS: direct link, hf CLI and curl.
- Browser
- Download file 1.22 kB
-
https://huggingface.co/spaces/lzpiece/IntelligentHandwrittenCGS/resolve/main/src/handwriting/model.py
- Command line
-
hf download hf://spaces/lzpiece/IntelligentHandwrittenCGS/src/handwriting/model.py
-
curl -L -o model.py https://huggingface.co/spaces/lzpiece/IntelligentHandwrittenCGS/resolve/main/src/handwriting/model.py
1.22 kB
| import torch | |
| import torch.nn as nn | |
| class SimpleCNN(nn.Module): | |
| def __init__(self) -> None: | |
| super().__init__() | |
| self.features = nn.Sequential( | |
| nn.Conv2d(1, 32, kernel_size=3, padding=1), | |
| nn.ReLU(inplace=True), | |
| nn.Conv2d(32, 32, kernel_size=3, padding=1), | |
| nn.ReLU(inplace=True), | |
| nn.MaxPool2d(2), | |
| nn.Dropout(0.1), | |
| nn.Conv2d(32, 64, kernel_size=3, padding=1), | |
| nn.ReLU(inplace=True), | |
| nn.Conv2d(64, 64, kernel_size=3, padding=1), | |
| nn.ReLU(inplace=True), | |
| nn.MaxPool2d(2), | |
| nn.Dropout(0.2), | |
| ) | |
| self.classifier = nn.Sequential( | |
| nn.Flatten(), | |
| nn.Linear(64 * 7 * 7, 256), | |
| nn.ReLU(inplace=True), | |
| nn.Dropout(0.3), | |
| nn.Linear(256, 10), | |
| ) | |
| def forward(self, x: torch.Tensor) -> torch.Tensor: | |
| x = self.features(x) | |
| x = self.classifier(x) | |
| return x | |
| def forward_features(self, x: torch.Tensor) -> torch.Tensor: | |
| x = self.features(x) | |
| x = torch.flatten(x, 1) | |
| x = self.classifier[1](x) | |
| x = self.classifier[2](x) | |
| return x | |