Python vgg.VGG16 Examples

The following are 2 code examples of vgg.VGG16(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module vgg , or try the search function .
Example #1
Source File: RUN.py    From SSD-variants with MIT License 5 votes vote down vote up
def __init__(self, n_classes):
        super(RUN300, self).__init__()
        self.n_classes = n_classes

        self.Base = VGG16()
        self.Extra = nn.Sequential(OrderedDict([
            ('extra1_1', nn.Conv2d(1024, 256, 1)),
            ('extra1_2', nn.Conv2d(256, 512, 3, padding=1, stride=2)),
            ('extra2_1', nn.Conv2d(512, 128, 1)),
            ('extra2_2', nn.Conv2d(128, 256, 3, padding=1, stride=2)),
            ('extra3_1', nn.Conv2d(256, 128, 1)),
            ('extra3_2', nn.Conv2d(128, 256, 3)),
            ('extra4_1', nn.Conv2d(256, 128, 1)),
            ('extra4_2', nn.Conv2d(128, 256, 3))]))
        self.pred_layers = ['conv4_3', 'conv7', 'extra1_2', 'extra2_2', 'extra3_2','extra4_2']
        n_channels = [512, 1024, 512, 256, 256, 256]

        self.L2Norm = nn.ModuleList([L2Norm(512, 20)])
        self.l2norm_layers = ['conv4_3']

        # Multi-Way Residual Blocks
        self.ResBlocks = nn.ModuleList()
        for i in range(len(n_channels) - 1):
            self.ResBlocks.append(
                ThreeWay(n_channels[i], n_channels[i+1], self.config['grids'][i], self.config['grids'][i+1], 
                         out_channels=256))
        self.ResBlocks.append(TwoWay(n_channels[-1], out_channels=256))

        # Unified Prediction Module
        n_boxes = len(self.config['aspect_ratios']) + 1
        #self.Loc  = nn.Conv2d(256, n_boxes * 4, 3, padding=1)
        #self.Conf = nn.Conv2d(256, n_boxes * (self.n_classes+1), 3, padding=1)
        self.Loc = nn.Sequential(
            nn.Conv2d(256, 256, 1),
            nn.ReLU(inplace=True),
            nn.Conv2d(256, n_boxes * 4, 3, padding=1))
        self.Conf = nn.Sequential(
            nn.Conv2d(256, 256, 1),
            nn.ReLU(inplace=True),
            nn.Conv2d(256, n_boxes * (self.n_classes+1), 3, padding=1)) 
Example #2
Source File: RRC.py    From SSD-variants with MIT License 4 votes vote down vote up
def __init__(self, n_classes=1):
        super().__init__()

        self.n_classes = n_classes
        self.rolling_times = 4
        self.rolling_ratio = 0.075

        self.Base = VGG16()
        self.Extra = nn.Sequential(OrderedDict([
            ('extra1_1', nn.Conv2d(1024, 256, 1)),
            ('extra1_2', nn.Conv2d(256, 256, 3, padding=1, stride=2)),
            ('extra2_1', nn.Conv2d(256, 128, 1)),
            ('extra2_2', nn.Conv2d(128, 256, 3, padding=1, stride=2)),
            ('extra3_1', nn.Conv2d(256, 128, 1)),
            ('extra3_2', nn.Conv2d(128, 256, 3, padding=1, stride=2))]))
        self.pred_layers = ['conv4_3', 'conv7', 'extra1_2', 'extra2_2', 'extra3_2']

        self.L2Norm = nn.ModuleList([L2Norm(512, 20)])
        self.l2norm_layers = ['conv4_3']

        # intermediate layers
        self.Inter = nn.ModuleList([
            nn.Sequential(nn.Conv2d(512, 256, 3, padding=1), nn.ReLU(inplace=True))
            nn.Sequential(nn.Conv2d(1024, 256, 3, padding=1), nn.ReLU(inplace=True))
            nn.Sequential(),
            nn.Sequential(),
            nn.Sequential()])
        n_channels = [256, 256, 256, 256, 256]

        # Recurrent Rolling
        self.RollLeft = nn.ModuleList([])
        self.RollRight = nn.ModuleList([])
        self.Roll = nn.ModuleList([])
        for i in range(len(n_channels)):
            n_out = int(n_channels[i] * self.rolling_ratio)
            if i > 0:
                self.RollLeft.append( nn.Sequential(
                    nn.Conv2d(n_channels[i-1], n_out, 1), 
                    nn.ReLU(inplace=True), 
                    nn.MaxPool2d(2, ceil_mode=True)))
            if i < len(n_channels) - 1:
                self.RollRight.append( nn.Sequential(
                    nn.Conv2d(n_channels[i+1], n_out, 1), 
                    nn.Relu(inplace=True), 
                    nn.ConvTranspose2d(n_out, n_out, kernel_size=4, stride=2, padding=1)))

            n_out = n_out * (int(i>0) + int(i<len(n_channels)-1))
            self.Roll.append(nn.Sequential(
                    nn.Conv2d(n_channels[i] + n_out, n_channels[i], 1), 
                    nn.ReLU(inplace=True)))

        # Prediction
        self.Loc = nn.ModuleList([])
        self.Conf = nn.ModuleList([])
        for i in range(len(n_channels)):
            n_boxes = len(self.config['aspect_ratios'][i]) + 1
            self.Loc.append(nn.Conv2d(n_channels[i], n_boxes * 4, 3, padding=1))
            self.Conf.append(nn.Conv2d(n_channels[i], n_boxes * (self.n_classes + 1), 3, padding=1))