Download features/real_forged_classifier/model.py from Pujan-Dev/AI_API: direct link, hf CLI and curl.
- Browser
- Download file 1.2 kB
-
https://huggingface.co/spaces/Pujan-Dev/AI_API/resolve/main/features/real_forged_classifier/model.py
- Command line
-
hf download hf://spaces/Pujan-Dev/AI_API/features/real_forged_classifier/model.py
-
curl -L -o model.py https://huggingface.co/spaces/Pujan-Dev/AI_API/resolve/main/features/real_forged_classifier/model.py
1.2 kB
| import torch | |
| import torch.nn as nn | |
| import torch.nn.functional as F | |
| class FFTCNN(nn.Module): | |
| """ | |
| Defines the Convolutional Neural Network architecture. | |
| This structure must match the model that was trained and saved. | |
| """ | |
| def __init__(self): | |
| super(FFTCNN, self).__init__() | |
| # Ensure 'self.' is used here to define the layers as instance attributes | |
| self.conv_layers = nn.Sequential( | |
| nn.Conv2d(1, 16, kernel_size=3, padding=1), | |
| nn.ReLU(), | |
| nn.MaxPool2d(kernel_size=2, stride=2), | |
| nn.Conv2d(16, 32, kernel_size=3, padding=1), | |
| nn.ReLU(), | |
| nn.MaxPool2d(kernel_size=2, stride=2) | |
| ) | |
| # Ensure 'self.' is used here as well | |
| self.fc_layers = nn.Sequential( | |
| nn.Linear(32 * 56 * 56, 128), # This size depends on your 224x224 input | |
| nn.ReLU(), | |
| nn.Linear(128, 2) # 2 output classes | |
| ) | |
| def forward(self, x): | |
| # Now, 'self.conv_layers' can be found because it was defined correctly | |
| x = self.conv_layers(x) | |
| x = x.view(x.size(0), -1) # Flatten the feature maps | |
| x = self.fc_layers(x) | |
| return x |