當前位置: 首頁>>代碼示例>>Python>>正文


Python cfg.ROOT_DIR屬性代碼示例

本文整理匯總了Python中core.config.cfg.ROOT_DIR屬性的典型用法代碼示例。如果您正苦於以下問題:Python cfg.ROOT_DIR屬性的具體用法?Python cfg.ROOT_DIR怎麽用?Python cfg.ROOT_DIR使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在core.config.cfg的用法示例。


在下文中一共展示了cfg.ROOT_DIR屬性的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _do_matlab_eval

# 需要導入模塊: from core.config import cfg [as 別名]
# 或者: from core.config.cfg import ROOT_DIR [as 別名]
def _do_matlab_eval(json_dataset, salt, output_dir='output'):
    import subprocess
    logger.info('-----------------------------------------------------')
    logger.info('Computing results with the official MATLAB eval code.')
    logger.info('-----------------------------------------------------')
    info = voc_info(json_dataset)
    path = os.path.join(
        cfg.ROOT_DIR, 'lib', 'datasets', 'VOCdevkit-matlab-wrapper')
    cmd = 'cd {} && '.format(path)
    cmd += '{:s} -nodisplay -nodesktop '.format(cfg.MATLAB)
    cmd += '-r "dbstop if error; '
    cmd += 'voc_eval(\'{:s}\',\'{:s}\',\'{:s}\',\'{:s}\'); quit;"' \
       .format(info['devkit_path'], 'comp4' + salt, info['image_set'],
               output_dir)
    logger.info('Running:\n{}'.format(cmd))
    subprocess.call(cmd, shell=True) 
開發者ID:roytseng-tw,項目名稱:Detectron.pytorch,代碼行數:18,代碼來源:voc_dataset_evaluator.py

示例2: mobilenet_load_pretrained_imagenet_weights

# 需要導入模塊: from core.config import cfg [as 別名]
# 或者: from core.config.cfg import ROOT_DIR [as 別名]
def mobilenet_load_pretrained_imagenet_weights(model):
    """Load pretrained weights
    Args:
        model: the generalized rcnnn module
    """
    _, ext = os.path.splitext(cfg.TRAIN.IMAGENET_PRETRAINED_WEIGHTS)
    if ext == '.pkl':
        with open(cfg.TRAIN.IMAGENET_PRETRAINED_WEIGHTS, 'rb') as fp:
            src_blobs = pickle.load(fp, encoding='latin1')
        if 'blobs' in src_blobs:
            src_blobs = src_blobs['blobs']
        pretrianed_state_dict = src_blobs
    else:
        weights_file = os.path.join(cfg.ROOT_DIR, cfg.TRAIN.IMAGENET_PRETRAINED_WEIGHTS)
        pretrianed_state_dict = mobilenet_convert_state_dict(torch.load(weights_file))
    model.Conv_Body.conv.load_state_dict(pretrianed_state_dict, strict=False)
    if hasattr(model, 'Box_Head'):
        model.Box_Head.conv.load_state_dict(pretrianed_state_dict, strict=False) 
開發者ID:ruotianluo,項目名稱:Context-aware-ZSR,代碼行數:20,代碼來源:pretrained_weights_helper.py

示例3: vgg_load_pretrained_imagenet_weights

# 需要導入模塊: from core.config import cfg [as 別名]
# 或者: from core.config.cfg import ROOT_DIR [as 別名]
def vgg_load_pretrained_imagenet_weights(model, convert_state_dict):
    """Load pretrained weights
    Args:
        model: the generalized rcnnn module
    """
    _, ext = os.path.splitext(cfg.TRAIN.IMAGENET_PRETRAINED_WEIGHTS)
    if ext == '.pkl':
        with open(cfg.TRAIN.IMAGENET_PRETRAINED_WEIGHTS, 'rb') as fp:
            src_blobs = pickle.load(fp, encoding='latin1')
        if 'blobs' in src_blobs:
            src_blobs = src_blobs['blobs']
        pretrianed_state_dict = src_blobs
    else:
        weights_file = os.path.join(cfg.ROOT_DIR, cfg.TRAIN.IMAGENET_PRETRAINED_WEIGHTS)
        pretrianed_state_dict = convert_state_dict(torch.load(weights_file))
    model.Conv_Body.load_state_dict(pretrianed_state_dict, strict=False)
    if hasattr(model, 'Box_Head'):
        model.Box_Head.load_state_dict(pretrianed_state_dict, strict=False) 
開發者ID:ruotianluo,項目名稱:Context-aware-ZSR,代碼行數:20,代碼來源:pretrained_weights_helper.py

示例4: load_pretrained_imagenet_weights

# 需要導入模塊: from core.config import cfg [as 別名]
# 或者: from core.config.cfg import ROOT_DIR [as 別名]
def load_pretrained_imagenet_weights(model):
    """Load pretrained weights
    Args:
        num_layers: 50 for res50 and so on.
        model: the generalized rcnnn module
    """
    _, ext = os.path.splitext(cfg.VGG.IMAGENET_PRETRAINED_WEIGHTS)
    if ext == '.pkl':
        with open(cfg.VGG.IMAGENET_PRETRAINED_WEIGHTS, 'rb') as fp:
            src_blobs = pickle.load(fp, encoding='latin1')
        if 'blobs' in src_blobs:
            src_blobs = src_blobs['blobs']
        pretrianed_state_dict = src_blobs
    else:
        weights_file = os.path.join(cfg.ROOT_DIR, cfg.VGG.IMAGENET_PRETRAINED_WEIGHTS)
        pretrianed_state_dict = convert_state_dict(torch.load(weights_file))


    model_state_dict = model.state_dict()

    pattern = dwh.vgg_weights_name_pattern()

    name_mapping, _ = model.detectron_weight_mapping

    for k, v in name_mapping.items():
        if isinstance(v, str):  # maybe a str, None or True
            if pattern.match(v):
                pretrianed_key = k.split('.', 1)[-1]
                if ext == '.pkl':
                    model_state_dict[k].copy_(torch.Tensor(pretrianed_state_dict[v]))
                else:
                    model_state_dict[k].copy_(pretrianed_state_dict[pretrianed_key]) 
開發者ID:ppengtang,項目名稱:pcl.pytorch,代碼行數:34,代碼來源:vgg_weights_helper.py

示例5: load_pretrained_imagenet_weights

# 需要導入模塊: from core.config import cfg [as 別名]
# 或者: from core.config.cfg import ROOT_DIR [as 別名]
def load_pretrained_imagenet_weights(model):
    """Load pretrained weights
    Args:
        num_layers: 50 for res50 and so on.
        model: the generalized rcnnn module
    """
    _, ext = os.path.splitext(cfg.RESNETS.IMAGENET_PRETRAINED_WEIGHTS)
    if ext == '.pkl':
        with open(cfg.RESNETS.IMAGENET_PRETRAINED_WEIGHTS, 'rb') as fp:
            src_blobs = pickle.load(fp, encoding='latin1')
        if 'blobs' in src_blobs:
            src_blobs = src_blobs['blobs']
        pretrianed_state_dict = src_blobs
    else:
        weights_file = os.path.join(cfg.ROOT_DIR, cfg.RESNETS.IMAGENET_PRETRAINED_WEIGHTS)
        pretrianed_state_dict = convert_state_dict(torch.load(weights_file))

        # Convert batchnorm weights
        for name, mod in model.named_modules():
            if isinstance(mod, mynn.AffineChannel2d):
                if cfg.FPN.FPN_ON:
                    pretrianed_name = name.split('.', 2)[-1]
                else:
                    pretrianed_name = name.split('.', 1)[-1]
                bn_mean = pretrianed_state_dict[pretrianed_name + '.running_mean']
                bn_var = pretrianed_state_dict[pretrianed_name + '.running_var']
                scale = pretrianed_state_dict[pretrianed_name + '.weight']
                bias = pretrianed_state_dict[pretrianed_name + '.bias']
                std = torch.sqrt(bn_var + 1e-5)
                new_scale = scale / std
                new_bias = bias - bn_mean * scale / std
                pretrianed_state_dict[pretrianed_name + '.weight'] = new_scale
                pretrianed_state_dict[pretrianed_name + '.bias'] = new_bias

    model_state_dict = model.state_dict()

    pattern = dwh.resnet_weights_name_pattern()

    name_mapping, _ = model.detectron_weight_mapping

    for k, v in name_mapping.items():
        if isinstance(v, str):  # maybe a str, None or True
            if pattern.match(v):
                if cfg.FPN.FPN_ON:
                    pretrianed_key = k.split('.', 2)[-1]
                else:
                    pretrianed_key = k.split('.', 1)[-1]
                if ext == '.pkl':
                    model_state_dict[k].copy_(torch.Tensor(pretrianed_state_dict[v]))
                else:
                    model_state_dict[k].copy_(pretrianed_state_dict[pretrianed_key]) 
開發者ID:roytseng-tw,項目名稱:Detectron.pytorch,代碼行數:53,代碼來源:resnet_weights_helper.py


注:本文中的core.config.cfg.ROOT_DIR屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。