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