Python torchvision.models.vgg.VGG Examples

The following are 21 code examples of torchvision.models.vgg.VGG(). 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 torchvision.models.vgg , or try the search function .
Example #1
Source File: prune_train.py    From nn-compression with MIT License 6 votes vote down vote up
def get_vgg_cfg(model):
    """
    return config list to generate VGG instance
    :param model: class VGG (torch.nn.Module), model to prune
    :return:
        list, config list to generate VGG instance
    """
    assert isinstance(model, models.VGG)
    features = model.features
    if isinstance(features, torch.nn.DataParallel):
        features = features.module

    cfg = []
    batch_norm = False
    for m in features:
        if isinstance(m, torch.nn.modules.conv._ConvNd):
            cfg.append(m.out_channels)
        elif isinstance(m, torch.nn.modules.pooling._MaxPoolNd):
            cfg.append('M')
        elif isinstance(m, torch.nn.modules.batchnorm._BatchNorm):
            batch_norm = True

    return cfg, batch_norm 
Example #2
Source File: fcn_2d.py    From elektronn3 with MIT License 5 votes vote down vote up
def forward(self, x):
        output = {}

        # get the output of each maxpooling layer (5 maxpool in VGG net)
        for idx in range(len(self.ranges)):
            for layer in range(self.ranges[idx][0], self.ranges[idx][1]):
                x = self.features[layer](x)
            output["x%d"%(idx+1)] = x

        return output 
Example #3
Source File: vgg.py    From openpose-pytorch with GNU Lesser General Public License v3.0 5 votes vote down vote up
def hand21(config_channels):
    cfg = [
        64, 64, 'M',
        128, 128, 'M',
        256, 256, 256, 256, 'M',
        512, 512, 512, 512,
        512, 512, 128,
    ]
    return VGG(config_channels, make_layers(config_channels, cfg)) 
Example #4
Source File: vgg.py    From openpose-pytorch with GNU Lesser General Public License v3.0 5 votes vote down vote up
def person18_19(config_channels):
    cfg = [
        64, 64, 'M',
        128, 128, 'M',
        256, 256, 256, 256, 'M',
        512, 512,
        256, 128,
    ]
    return VGG(config_channels, make_layers(config_channels, cfg)) 
Example #5
Source File: vgg.py    From openpose-pytorch with GNU Lesser General Public License v3.0 5 votes vote down vote up
def vgg19_bn(config_channels):
    model = VGG(config_channels, make_layers(config_channels, cfg['E'], batch_norm=True))
    if config_channels.config.getboolean('model', 'pretrained'):
        url = model_urls['vgg19_bn']
        logging.info('use pretrained model: ' + url)
        state_dict = model.state_dict()
        for key, value in model_zoo.load_url(url).items():
            if key in state_dict:
                state_dict[key] = value
        model.load_state_dict(state_dict)
    return model 
Example #6
Source File: vgg.py    From openpose-pytorch with GNU Lesser General Public License v3.0 5 votes vote down vote up
def vgg19(config_channels):
    model = VGG(config_channels, make_layers(config_channels, cfg['E']))
    if config_channels.config.getboolean('model', 'pretrained'):
        url = model_urls['vgg19']
        logging.info('use pretrained model: ' + url)
        state_dict = model.state_dict()
        for key, value in model_zoo.load_url(url).items():
            if key in state_dict:
                state_dict[key] = value
        model.load_state_dict(state_dict)
    return model 
Example #7
Source File: vgg.py    From openpose-pytorch with GNU Lesser General Public License v3.0 5 votes vote down vote up
def vgg16(config_channels):
    model = VGG(config_channels, make_layers(config_channels, cfg['D']))
    if config_channels.config.getboolean('model', 'pretrained'):
        url = model_urls['vgg16']
        logging.info('use pretrained model: ' + url)
        state_dict = model.state_dict()
        for key, value in model_zoo.load_url(url).items():
            if key in state_dict:
                state_dict[key] = value
        model.load_state_dict(state_dict)
    return model 
Example #8
Source File: vgg.py    From openpose-pytorch with GNU Lesser General Public License v3.0 5 votes vote down vote up
def vgg13_bn(config_channels):
    model = VGG(config_channels, make_layers(config_channels, cfg['B'], batch_norm=True))
    if config_channels.config.getboolean('model', 'pretrained'):
        url = model_urls['vgg13_bn']
        logging.info('use pretrained model: ' + url)
        state_dict = model.state_dict()
        for key, value in model_zoo.load_url(url).items():
            if key in state_dict:
                state_dict[key] = value
        model.load_state_dict(state_dict)
    return model 
Example #9
Source File: vgg.py    From openpose-pytorch with GNU Lesser General Public License v3.0 5 votes vote down vote up
def vgg13(config_channels):
    model = VGG(config_channels, make_layers(config_channels, cfg['B']))
    if config_channels.config.getboolean('model', 'pretrained'):
        url = model_urls['vgg13']
        logging.info('use pretrained model: ' + url)
        state_dict = model.state_dict()
        for key, value in model_zoo.load_url(url).items():
            if key in state_dict:
                state_dict[key] = value
        model.load_state_dict(state_dict)
    return model 
Example #10
Source File: vgg.py    From openpose-pytorch with GNU Lesser General Public License v3.0 5 votes vote down vote up
def vgg11_bn(config_channels):
    model = VGG(config_channels, make_layers(config_channels, cfg['A'], batch_norm=True))
    if config_channels.config.getboolean('model', 'pretrained'):
        url = model_urls['vgg11_bn']
        logging.info('use pretrained model: ' + url)
        state_dict = model.state_dict()
        for key, value in model_zoo.load_url(url).items():
            if key in state_dict:
                state_dict[key] = value
        model.load_state_dict(state_dict)
    return model 
Example #11
Source File: vgg.py    From openpose-pytorch with GNU Lesser General Public License v3.0 5 votes vote down vote up
def vgg11(config_channels):
    model = VGG(config_channels, make_layers(config_channels, cfg['A']))
    if config_channels.config.getboolean('model', 'pretrained'):
        url = model_urls['vgg11']
        logging.info('use pretrained model: ' + url)
        state_dict = model.state_dict()
        for key, value in model_zoo.load_url(url).items():
            if key in state_dict:
                state_dict[key] = value
        model.load_state_dict(state_dict)
    return model 
Example #12
Source File: vgg.py    From talking-heads with GNU General Public License v3.0 5 votes vote down vote up
def vgg_face(pretrained=False, **kwargs):
    if pretrained:
        kwargs['init_weights'] = False
    model = vgg.VGG(vgg.make_layers(vgg.cfgs['D'], batch_norm=False), num_classes=2622, **kwargs)
    if pretrained:
        model.load_state_dict(vgg_face_state_dict())
    return model 
Example #13
Source File: vgg.py    From yolo2-pytorch with GNU Lesser General Public License v3.0 5 votes vote down vote up
def vgg11(config_channels, anchors, num_cls):
    model = VGG(config_channels, anchors, num_cls, make_layers(config_channels, cfg['A']))
    if config_channels.config.getboolean('model', 'pretrained'):
        url = model_urls['vgg11']
        logging.info('use pretrained model: ' + url)
        state_dict = model.state_dict()
        for key, value in model_zoo.load_url(url).items():
            if key in state_dict:
                state_dict[key] = value
        model.load_state_dict(state_dict)
    return model 
Example #14
Source File: vgg.py    From segmentation_models.pytorch with MIT License 5 votes vote down vote up
def make_dilated(self, stage_list, dilation_list):
        raise ValueError("'VGG' models do not support dilated mode due to Max Pooling"
                         " operations for downsampling!") 
Example #15
Source File: get_cnn.py    From graph_distillation with Apache License 2.0 5 votes vote down vote up
def get_vgg(in_channels=3, **kwargs):
  model = VGG(make_layers(cfg['D'], in_channels), **kwargs)
  return model 
Example #16
Source File: vgg.py    From yolo2-pytorch with GNU Lesser General Public License v3.0 5 votes vote down vote up
def vgg19_bn(config_channels, anchors, num_cls):
    model = VGG(config_channels, anchors, num_cls, make_layers(config_channels, cfg['E'], batch_norm=True))
    if config_channels.config.getboolean('model', 'pretrained'):
        url = model_urls['vgg19_bn']
        logging.info('use pretrained model: ' + url)
        state_dict = model.state_dict()
        for key, value in model_zoo.load_url(url).items():
            if key in state_dict:
                state_dict[key] = value
        model.load_state_dict(state_dict)
    return model 
Example #17
Source File: vgg.py    From yolo2-pytorch with GNU Lesser General Public License v3.0 5 votes vote down vote up
def vgg19(config_channels, anchors, num_cls):
    model = VGG(config_channels, anchors, num_cls, make_layers(config_channels, cfg['E']))
    if config_channels.config.getboolean('model', 'pretrained'):
        url = model_urls['vgg19']
        logging.info('use pretrained model: ' + url)
        state_dict = model.state_dict()
        for key, value in model_zoo.load_url(url).items():
            if key in state_dict:
                state_dict[key] = value
        model.load_state_dict(state_dict)
    return model 
Example #18
Source File: vgg.py    From yolo2-pytorch with GNU Lesser General Public License v3.0 5 votes vote down vote up
def vgg16(config_channels, anchors, num_cls):
    model = VGG(config_channels, anchors, num_cls, make_layers(config_channels, cfg['D']))
    if config_channels.config.getboolean('model', 'pretrained'):
        url = model_urls['vgg16']
        logging.info('use pretrained model: ' + url)
        state_dict = model.state_dict()
        for key, value in model_zoo.load_url(url).items():
            if key in state_dict:
                state_dict[key] = value
        model.load_state_dict(state_dict)
    return model 
Example #19
Source File: vgg.py    From yolo2-pytorch with GNU Lesser General Public License v3.0 5 votes vote down vote up
def vgg13_bn(config_channels, anchors, num_cls):
    model = VGG(config_channels, anchors, num_cls, make_layers(config_channels, cfg['B'], batch_norm=True))
    if config_channels.config.getboolean('model', 'pretrained'):
        url = model_urls['vgg13_bn']
        logging.info('use pretrained model: ' + url)
        state_dict = model.state_dict()
        for key, value in model_zoo.load_url(url).items():
            if key in state_dict:
                state_dict[key] = value
        model.load_state_dict(state_dict)
    return model 
Example #20
Source File: vgg.py    From yolo2-pytorch with GNU Lesser General Public License v3.0 5 votes vote down vote up
def vgg13(config_channels, anchors, num_cls):
    model = VGG(config_channels, anchors, num_cls, make_layers(config_channels, cfg['B']))
    if config_channels.config.getboolean('model', 'pretrained'):
        url = model_urls['vgg13']
        logging.info('use pretrained model: ' + url)
        state_dict = model.state_dict()
        for key, value in model_zoo.load_url(url).items():
            if key in state_dict:
                state_dict[key] = value
        model.load_state_dict(state_dict)
    return model 
Example #21
Source File: vgg.py    From yolo2-pytorch with GNU Lesser General Public License v3.0 5 votes vote down vote up
def vgg11_bn(config_channels, anchors, num_cls):
    model = VGG(config_channels, anchors, num_cls, make_layers(config_channels, cfg['A'], batch_norm=True))
    if config_channels.config.getboolean('model', 'pretrained'):
        url = model_urls['vgg11_bn']
        logging.info('use pretrained model: ' + url)
        state_dict = model.state_dict()
        for key, value in model_zoo.load_url(url).items():
            if key in state_dict:
                state_dict[key] = value
        model.load_state_dict(state_dict)
    return model