|
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( |
|
|
|
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), |
|
|
|
|
|
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), |
|
|
|
|
|
nn.Conv2d(256, 384, kernel_size=3, padding=1), |
|
nn.ReLU(inplace=True), |
|
|
|
|
|
nn.Conv2d(384, 384, kernel_size=3, padding=1), |
|
nn.ReLU(inplace=True), |
|
|
|
|
|
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 |
|
|