Spaces:
Sleeping
Sleeping
Download model.py from CircleStar/Image_Classification-CPU: direct link, hf CLI and curl.
- Browser
- Download file 777 Bytes
-
https://huggingface.co/spaces/CircleStar/Image_Classification-CPU/resolve/230bcc76117e1c4a55b4b9393286d32efe7f1bb3/model.py
- Command line
-
hf download hf://spaces/CircleStar/Image_Classification-CPU@230bcc76117e1c4a55b4b9393286d32efe7f1bb3/model.py
-
curl -L -o model.py https://huggingface.co/spaces/CircleStar/Image_Classification-CPU/resolve/230bcc76117e1c4a55b4b9393286d32efe7f1bb3/model.py
777 Bytes
| import torch.nn as nn | |
| from torchvision import models | |
| class SimpleCNN(nn.Module): | |
| def __init__( | |
| self, | |
| num_classes: int, | |
| conv1_channels: int = 16, | |
| conv2_channels: int = 32, | |
| kernel_size: int = 3, | |
| dropout: float = 0.2, | |
| fc_dim: int = 128, | |
| ): | |
| super().__init__() | |
| weights = models.ResNet18_Weights.DEFAULT | |
| self.backbone = models.resnet18(weights=weights) | |
| in_features = self.backbone.fc.in_features | |
| self.backbone.fc = nn.Sequential( | |
| nn.Dropout(dropout), | |
| nn.Linear(in_features, fc_dim), | |
| nn.ReLU(), | |
| nn.Dropout(dropout), | |
| nn.Linear(fc_dim, num_classes), | |
| ) | |
| def forward(self, x): | |
| return self.backbone(x) |