當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。