Download ZFNet-CIFAR10/Classification-normal/scripts/model.py from code-philia/mtpnet_image_models: direct link, hf CLI and curl.
- Browser
- Download file 1.77 kB
-
https://huggingface.co/datasets/code-philia/mtpnet_image_models/resolve/main/ZFNet-CIFAR10/Classification-normal/scripts/model.py
- Command line
-
hf download hf://datasets/code-philia/mtpnet_image_models/ZFNet-CIFAR10/Classification-normal/scripts/model.py
-
curl -L -o model.py https://huggingface.co/datasets/code-philia/mtpnet_image_models/resolve/main/ZFNet-CIFAR10/Classification-normal/scripts/model.py
1.77 kB
| import torch | |
| import torch.nn as nn | |
| class ZFNet(nn.Module): | |
| def __init__(self, num_classes=10): | |
| super(ZFNet, self).__init__() | |
| self.features = nn.Sequential( | |
| # conv1 | |
| nn.Conv2d(3, 96, kernel_size=7, stride=2, padding=1), | |
| nn.ReLU(inplace=True), | |
| nn.MaxPool2d(kernel_size=3, stride=2, padding=1), | |
| nn.LocalResponseNorm(size=5, alpha=0.0001, beta=0.75, k=2), | |
| # conv2 | |
| nn.Conv2d(96, 256, kernel_size=5, padding=2), | |
| nn.ReLU(inplace=True), | |
| nn.MaxPool2d(kernel_size=3, stride=2, padding=1), | |
| nn.LocalResponseNorm(size=5, alpha=0.0001, beta=0.75, k=2), | |
| # conv3 | |
| nn.Conv2d(256, 384, kernel_size=3, padding=1), | |
| nn.ReLU(inplace=True), | |
| # conv4 | |
| nn.Conv2d(384, 384, kernel_size=3, padding=1), | |
| nn.ReLU(inplace=True), | |
| # conv5 | |
| nn.Conv2d(384, 256, kernel_size=3, padding=1), | |
| nn.ReLU(inplace=True), | |
| nn.MaxPool2d(kernel_size=3, stride=2, padding=1), | |
| ) | |
| self.classifier = nn.Sequential( | |
| nn.Linear(256 * 2 * 2, 4096), | |
| nn.ReLU(inplace=True), | |
| nn.Dropout(), | |
| nn.Linear(4096, 4096), | |
| nn.ReLU(inplace=True), | |
| nn.Dropout(), | |
| nn.Linear(4096, num_classes), | |
| ) | |
| def forward(self, x): | |
| x = self.features(x) | |
| x = x.view(x.size(0), -1) | |
| x = self.classifier(x) | |
| return x | |
| def feature(self, x): | |
| return self.features(x) | |
| def prediction(self, x): | |
| x = x.view(x.size(0), -1) | |
| return self.classifier(x) | |