Commit b8b5d978 by 前钰

Upload New File

parent 508f1989
import torch
import torch
import torch.nn as nn
class VGG(nn.Module):
def __init__(self, num_classes=1000):
super(VGG, self).__init__()
self.features = nn.Sequential(
nn.Conv2d(3, 64, kernel_size=3, padding=1), # output[64, 224, 224]
nn.ReLU(inplace=True),
nn.Conv2d(64, 64, kernel_size=3, padding=1), # output[64, 224, 224]
nn.ReLU(inplace=True),
nn.MaxPool2d(kernel_size=2, stride=2), # output[64, 112, 112]
nn.Conv2d(64, 128, kernel_size=3, padding=1), # output[128, 112, 112]
nn.ReLU(inplace=True),
nn.Conv2d(128, 128, kernel_size=3, padding=1), # output[128, 112, 112]
nn.ReLU(inplace=True),
nn.MaxPool2d(kernel_size=2, stride=2), # output[128, 56, 56]
nn.Conv2d(128, 256, kernel_size=3, padding=1), # output[256, 56, 56]
nn.ReLU(inplace=True),
nn.Conv2d(256, 256, kernel_size=3, padding=1), # output[256, 56, 56]
nn.ReLU(inplace=True),
nn.Conv2d(256, 256, kernel_size=3, padding=1), # output[256, 56, 56]
nn.ReLU(inplace=True),
nn.MaxPool2d(kernel_size=2, stride=2), # output[256, 28, 28]
nn.Conv2d(256, 512, kernel_size=3, padding=1), # output[512, 28, 28]
nn.ReLU(inplace=True),
nn.Conv2d(512, 512, kernel_size=3, padding=1), # output[512, 28, 28]
nn.ReLU(inplace=True),
nn.Conv2d(512, 512, kernel_size=3, padding=1), # output[512, 28, 28]
nn.ReLU(inplace=True),
nn.MaxPool2d(kernel_size=2, stride=2), # output[512, 14, 14]
nn.Conv2d(512, 512, kernel_size=3, padding=1), # output[512, 14, 14]
nn.ReLU(inplace=True),
nn.Conv2d(512, 512, kernel_size=3, padding=1), # output[512, 14, 14]
nn.ReLU(inplace=True),
nn.Conv2d(512, 512, kernel_size=3, padding=1), # output[512, 14, 14]
nn.ReLU(inplace=True),
nn.MaxPool2d(kernel_size=2, stride=2), # output[512, 7, 7]
)
self.classifier = nn.Sequential(
nn.Linear(512 * 7 * 7, 4096),
nn.ReLU(inplace=True),
nn.Dropout(p=0.5),
nn.Linear(4096, 4096),
nn.ReLU(inplace=True),
nn.Dropout(p=0.5),
nn.Linear(4096, num_classes),
)
def forward(self, x):
x = self.features(x)
x = torch.flatten(x, start_dim=1)
x = self.classifier(x)
return x
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment