pytorch-VGG network

VGG network structure 

 

The first layer: 3x3x3x64, in steps of 1, padding = 1 

The second layer: 3x3x64x64, in steps of 1, padding = 1 

The third layer: 3x3x64x128, in steps of 1, padding = 1

Fourth layer: 3x3x128x128, in steps of 1, padding = 1

Fifth layer: 3x3x128x256, in steps of 1, padding = 1

Sixth layer: 3x3x256x256, in steps of 1, padding = 1

Seventh layer: 3x3x256x256, in steps of 1, padding = 1

Eighth layer: 3x3x256x512, in steps of 1, padding = 1 

Ninth layer: 3x3x512x512, in steps of 1, padding = 1 

Tenth layer: 3x3x512x512, in steps of 1, padding = 1 

Eleventh layer: 3x3x512x512, in steps of 1, padding = 1 

Twelfth layer: 3x3x512x512, in steps of 1, padding = 1 

Tenth Layer: 3x3x512x512, in steps of 1, padding = 1 

Fourteenth Layer: fully connected operation 512 * 7 * 7, 4096

Operation fully connected 4096, 4096: Fifteenth layer

Sixteenth layer: 4096, num_classes full connection operation

import torch
from torch import nn

class VGG(nn.Module):
    def __init__(self, num_classes):
        super(VGG, self).__init__()
        self.features = nn.Sequential(
            nn.Conv2d(3, 64, kernel_size=3, padding=1),
            nn.ReLU (True)
            nn.Conv2d(64, 64, kernel_size=3, padding=1),
            nn.ReLU (True)
            nn.MaxPool2d(kernel_size=2, stride=2),
            nn.Conv2d(64, 128, kernel_size=3, padding=1),
            nn.ReLU (True)
            nn.Conv2d(128, 128, kernel_size=3, padding=1),
            nn.ReLU (True)
            nn.MaxPool2d(kernel_size=2, stride=2),
            nn.Conv2d(128, 256, kernel_size=3, padding=1),
            nn.ReLU (True)
            nn.Conv2d(256, 256, kernel_size=3, padding=1),
            nn.ReLU (True)
            nn.Conv2d(256, 256, kernel_size=3, padding=1),
            nn.ReLU (True)
            nn.MaxPool2d(kernel_size=2, stride=2),
            nn.Conv2d(256, 512, kernel_size=3, padding=1),
            nn.ReLU (True)
            nn.Conv2d(512, 512, kernel_size=3, padding=1),
            nn.ReLU (True)
            nn.Conv2d(512, 512, kernel_size=3, padding=1),
            nn.ReLU (True)
            nn.MaxPool2d(kernel_size=2, stride=2),
            nn.Conv2d(512, 512, kernel_size=3, padding=1),
            nn.ReLU (True)
            nn.Conv2d(512, 512, kernel_size=3, padding=1),
            nn.ReLU (True)
            nn.Conv2d(512, 512, kernel_size=3, padding=1),
            nn.ReLU (True)
            nn.MaxPool2d(kernel_size=2, stride=2),)
        self.classifier = nn.Sequential(
            nn.Linear(512*7*7, 4096),
            nn.ReLU (True)
            nn.Dropout(),
            nn.Linear(4096, 4096),
            nn.ReLU (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

 

Guess you like

Origin www.cnblogs.com/my-love-is-python/p/11729565.html