当前位置: 首页>>代码示例>>Python>>正文


Python vgg.cfg方法代码示例

本文整理汇总了Python中torchvision.models.vgg.cfg方法的典型用法代码示例。如果您正苦于以下问题:Python vgg.cfg方法的具体用法?Python vgg.cfg怎么用?Python vgg.cfg使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在torchvision.models.vgg的用法示例。


在下文中一共展示了vgg.cfg方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: make_layers

# 需要导入模块: from torchvision.models import vgg [as 别名]
# 或者: from torchvision.models.vgg import cfg [as 别名]
def make_layers(cfg, batch_norm=False):
    """This is almost verbatim from torchvision.models.vgg, except that the
    MaxPool2d modules are configured with ceil_mode=True.
    """
    layers = []
    in_channels = 3
    for v in cfg:
        if v == 'M':
            layers.append(nn.MaxPool2d(kernel_size=2, stride=2, ceil_mode=True))
        else:
            conv2d = nn.Conv2d(in_channels, v, kernel_size=3, padding=1)
            modules = [conv2d, nn.ReLU(inplace=True)]
            if batch_norm:
                modules.insert(1, nn.BatchNorm2d(v))
            layers.extend(modules)
            in_channels = v
    return nn.Sequential(*layers) 
开发者ID:jhoffman,项目名称:cycada_release,代码行数:19,代码来源:fcn8s.py

示例2: make_layers

# 需要导入模块: from torchvision.models import vgg [as 别名]
# 或者: from torchvision.models.vgg import cfg [as 别名]
def make_layers(cfg, batch_norm=False):
	"""This is almost verbatim from torchvision.models.vgg, except that the
	MaxPool2d modules are configured with ceil_mode=True.
	"""
	layers = []
	in_channels = 3
	for v in cfg:
		if v == 'M':
			layers.append(nn.MaxPool2d(kernel_size=2, stride=2, ceil_mode=True))
		else:
			conv2d = nn.Conv2d(in_channels, v, kernel_size=3, padding=1)
			modules = [conv2d, nn.ReLU(inplace=True)]
			if batch_norm:
				modules.insert(1, nn.BatchNorm2d(v))
			layers.extend(modules)
			in_channels = v
	return nn.Sequential(*layers) 
开发者ID:Luodian,项目名称:MADAN,代码行数:19,代码来源:fcn8s.py

示例3: make_layers

# 需要导入模块: from torchvision.models import vgg [as 别名]
# 或者: from torchvision.models.vgg import cfg [as 别名]
def make_layers(config_channels, cfg, batch_norm=False):
    features = []
    for v in cfg:
        if v == 'M':
            features += [nn.MaxPool2d(kernel_size=2, stride=2)]
        else:
            conv2d = nn.Conv2d(config_channels.channels, config_channels(v, 'features.%d.weight' % len(features)), kernel_size=3, padding=1)
            if batch_norm:
                features += [conv2d, nn.BatchNorm2d(config_channels.channels), nn.ReLU(inplace=True)]
            else:
                features += [conv2d, nn.ReLU(inplace=True)]
    return nn.Sequential(*features) 
开发者ID:ruiminshen,项目名称:yolo2-pytorch,代码行数:14,代码来源:vgg.py

示例4: vgg11

# 需要导入模块: from torchvision.models import vgg [as 别名]
# 或者: from torchvision.models.vgg import cfg [as 别名]
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 
开发者ID:ruiminshen,项目名称:yolo2-pytorch,代码行数:13,代码来源:vgg.py

示例5: vgg11_bn

# 需要导入模块: from torchvision.models import vgg [as 别名]
# 或者: from torchvision.models.vgg import cfg [as 别名]
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 
开发者ID:ruiminshen,项目名称:yolo2-pytorch,代码行数:13,代码来源:vgg.py

示例6: vgg13

# 需要导入模块: from torchvision.models import vgg [as 别名]
# 或者: from torchvision.models.vgg import cfg [as 别名]
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 
开发者ID:ruiminshen,项目名称:yolo2-pytorch,代码行数:13,代码来源:vgg.py

示例7: vgg13_bn

# 需要导入模块: from torchvision.models import vgg [as 别名]
# 或者: from torchvision.models.vgg import cfg [as 别名]
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 
开发者ID:ruiminshen,项目名称:yolo2-pytorch,代码行数:13,代码来源:vgg.py

示例8: vgg16_bn

# 需要导入模块: from torchvision.models import vgg [as 别名]
# 或者: from torchvision.models.vgg import cfg [as 别名]
def vgg16_bn(config_channels, anchors, num_cls):
    model = VGG(config_channels, anchors, num_cls, make_layers(config_channels, cfg['D'], batch_norm=True))
    if config_channels.config.getboolean('model', 'pretrained'):
        url = model_urls['vgg16_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 
开发者ID:ruiminshen,项目名称:yolo2-pytorch,代码行数:13,代码来源:vgg.py

示例9: vgg19

# 需要导入模块: from torchvision.models import vgg [as 别名]
# 或者: from torchvision.models.vgg import cfg [as 别名]
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 
开发者ID:ruiminshen,项目名称:yolo2-pytorch,代码行数:13,代码来源:vgg.py

示例10: vgg19_bn

# 需要导入模块: from torchvision.models import vgg [as 别名]
# 或者: from torchvision.models.vgg import cfg [as 别名]
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 
开发者ID:ruiminshen,项目名称:yolo2-pytorch,代码行数:13,代码来源:vgg.py

示例11: __init__

# 需要导入模块: from torchvision.models import vgg [as 别名]
# 或者: from torchvision.models.vgg import cfg [as 别名]
def __init__(self, num_cls=19, pretrained=True, weights_init=None, 
            output_last_ft=False):
        super().__init__()
        self.output_last_ft = output_last_ft
        self.vgg = make_layers(vgg.cfg['D'])
        self.vgg_head = nn.Sequential(
            nn.Conv2d(512, 4096, 7),
            nn.ReLU(inplace=True),
            nn.Dropout2d(p=0.5),
            nn.Conv2d(4096, 4096, 1),
            nn.ReLU(inplace=True),
            nn.Dropout2d(p=0.5),
            nn.Conv2d(4096, num_cls, 1)
            )
        self.upscore2 = self.upscore_pool4 = Bilinear(2, num_cls)
        self.upscore8 = Bilinear(8, num_cls)
        self.score_pool4 = nn.Conv2d(512, num_cls, 1)
        for param in self.score_pool4.parameters():
            init.constant(param, 0)
        self.score_pool3 = nn.Conv2d(256, num_cls, 1)
        for param in self.score_pool3.parameters():
            init.constant(param, 0)
        
        if pretrained:
            if weights_init is not None:
                self.load_weights(torch.load(weights_init))
            else:
                self.load_base_weights() 
开发者ID:jhoffman,项目名称:cycada_release,代码行数:30,代码来源:fcn8s.py

示例12: make_layers

# 需要导入模块: from torchvision.models import vgg [as 别名]
# 或者: from torchvision.models.vgg import cfg [as 别名]
def make_layers(cfg, in_channels=3, batch_norm=False):
  layers = []
  for v in cfg:
    if v == 'M':
      layers += [nn.MaxPool2d(kernel_size=2, stride=2)]
    else:
      conv2d = nn.Conv2d(in_channels, v, kernel_size=3, padding=1)
      if batch_norm:
        layers += [conv2d, nn.BatchNorm2d(v), nn.ReLU(inplace=True)]
      else:
        layers += [conv2d, nn.ReLU(inplace=True)]
      in_channels = v
  return nn.Sequential(*layers) 
开发者ID:google,项目名称:graph_distillation,代码行数:15,代码来源:get_cnn.py

示例13: get_vgg

# 需要导入模块: from torchvision.models import vgg [as 别名]
# 或者: from torchvision.models.vgg import cfg [as 别名]
def get_vgg(in_channels=3, **kwargs):
  model = VGG(make_layers(cfg['D'], in_channels), **kwargs)
  return model 
开发者ID:google,项目名称:graph_distillation,代码行数:5,代码来源:get_cnn.py

示例14: __init__

# 需要导入模块: from torchvision.models import vgg [as 别名]
# 或者: from torchvision.models.vgg import cfg [as 别名]
def __init__(self, num_cls=19, pretrained=True, weights_init=None,
	             output_last_ft=False):
		super().__init__()
		self.output_last_ft = output_last_ft
		if weights_init:
			batch_norm = False
		else:
			batch_norm = True
		self.vgg = make_layers(vgg.cfg['D'], batch_norm=False)
		self.vgg_head = nn.Sequential(
			nn.Conv2d(512, 4096, 7),
			nn.ReLU(inplace=True),
			nn.Dropout2d(p=0.5),
			nn.Conv2d(4096, 4096, 1),
			nn.ReLU(inplace=True),
			nn.Dropout2d(p=0.5),
			nn.Conv2d(4096, num_cls, 1)
		)
		self.upscore2 = self.upscore_pool4 = Bilinear(2, num_cls)
		self.upscore8 = Bilinear(8, num_cls)
		self.score_pool4 = nn.Conv2d(512, num_cls, 1)
		for param in self.score_pool4.parameters():
			# init.constant(param, 0)
			init.constant_(param, 0)
		self.score_pool3 = nn.Conv2d(256, num_cls, 1)
		for param in self.score_pool3.parameters():
			# init.constant(param, 0)
			init.constant_(param, 0)
		
		if pretrained:
			if weights_init is not None:
				self.load_weights(torch.load(weights_init))
			else:
				self.load_base_weights() 
开发者ID:Luodian,项目名称:MADAN,代码行数:36,代码来源:fcn8s.py

示例15: vgg11

# 需要导入模块: from torchvision.models import vgg [as 别名]
# 或者: from torchvision.models.vgg import cfg [as 别名]
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 
开发者ID:ruiminshen,项目名称:openpose-pytorch,代码行数:13,代码来源:vgg.py


注:本文中的torchvision.models.vgg.cfg方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。