Spaces:
Configuration error
Configuration error
Download ml/model.py from Samidha21/emosaic-backend: direct link, hf CLI and curl.
- Browser
- Download file 1.31 kB
-
https://huggingface.co/spaces/Samidha21/emosaic-backend/resolve/main/ml/model.py
- Command line
-
hf download hf://spaces/Samidha21/emosaic-backend/ml/model.py
-
curl -L -o model.py https://huggingface.co/spaces/Samidha21/emosaic-backend/resolve/main/ml/model.py
1.31 kB
| import torch | |
| import torch.nn as nn | |
| class PatchCNN(nn.Module): | |
| def __init__(self, num_classes=7): | |
| super(PatchCNN, self).__init__() | |
| # ββ Feature Extractor ββ | |
| self.features = nn.Sequential( | |
| # Block 1 β detects edges and basic textures | |
| nn.Conv2d(3, 32, kernel_size=3, padding=1), | |
| nn.BatchNorm2d(32), | |
| nn.ReLU(), | |
| nn.MaxPool2d(2, 2), # 32x32 β 16x16 | |
| # Block 2 β detects patterns from edges | |
| nn.Conv2d(32, 64, kernel_size=3, padding=1), | |
| nn.BatchNorm2d(64), | |
| nn.ReLU(), | |
| nn.MaxPool2d(2, 2), # 16x16 β 8x8 | |
| # Block 3 β detects complex textures | |
| nn.Conv2d(64, 128, kernel_size=3, padding=1), | |
| nn.BatchNorm2d(128), | |
| nn.ReLU(), | |
| nn.MaxPool2d(2, 2), # 8x8 β 4x4 | |
| ) | |
| # ββ Classifier ββ | |
| self.classifier = nn.Sequential( | |
| nn.Flatten(), # (128, 4, 4) β 2048 | |
| nn.Linear(128 * 4 * 4, 256), | |
| nn.ReLU(), | |
| nn.Dropout(0.3), | |
| nn.Linear(256, num_classes) # 256 β 7 | |
| ) | |
| def forward(self, x): | |
| x = self.features(x) | |
| x = self.classifier(x) | |
| return x |