Esempio n. 1
0
    def _load_file(self, f):
        # pdb.set_trace()
        # catalog lookup
        if f.startswith("catalog://"):
            paths_catalog = import_file(
                "maskrcnn_benchmark.config.paths_catalog", self.cfg.PATHS_CATALOG, True
            )
            catalog_f = paths_catalog.ModelCatalog.get(f[len("catalog://") :])
            self.logger.info("{} points to {}".format(f, catalog_f))
            f = catalog_f
        # download url files
        if f.startswith("http"):
            # if the file is a url path, download it and cache it
            cached_f = cache_url(f)
            self.logger.info("url {} cached in {}".format(f, cached_f))
            f = cached_f
        # convert Caffe2 checkpoint from pkl
        if f.endswith(".pkl"):
            return load_c2_format(self.cfg, f)
        
        # pdb.set_trace()
        # load native detectron.pytorch checkpoint
        loaded = super(DetectronCheckpointer, self)._load_file(f)
        # pdb.set_trace()

        if "model" not in loaded:
            loaded = dict(model=loaded)
        # pdb.set_trace()
        return loaded
Esempio n. 2
0
 def _load_file(self, f):
     # catalog lookup
     if f.startswith("catalog://"):
         from maskrcnn_benchmark.config import paths_catalog
         catalog_f = paths_catalog.ModelCatalog.get(f[len("catalog://"):])
         self.logger.info("{} points to {}".format(f, catalog_f))
         f = catalog_f
     # download url files
     if f.startswith("http"):
         # if the file is a url path, download it and cache it
         cached_f = cache_url(f)
         self.logger.info("url {} cached in {}".format(f, cached_f))
         f = cached_f
     # convert Caffe2 checkpoint from pkl
     if f.endswith(".pkl"):
         return load_c2_format(self.cfg, f)
     # load native detectron.pytorch checkpoint
     loaded = super(DetectronCheckpointer, self)._load_file(f)
     if "model" not in loaded:
         loaded = dict(model=loaded)
     if self.cfg is not None:
         from .c2_model_loading import _rename_conv_weights_for_deformable_conv_layers
         _rename_conv_weights_for_deformable_conv_layers(
             loaded['model'], self.cfg)
     return loaded
Esempio n. 3
0
    def _load_file(self, f):
        # catalog lookup
        if f.startswith("catalog://"):
            paths_catalog = import_file(
                "maskrcnn_benchmark.config.paths_catalog",
                self.cfg.PATHS_CATALOG, True)
            catalog_f = paths_catalog.ModelCatalog.get(f[len("catalog://"):])
            self.logger.info("{} points to {}".format(f, catalog_f))
            f = catalog_f
        # download url files
        if f.startswith("http"):
            # if the file is a url path, download it and cache it
            cached_f = cache_url(f)
            self.logger.info("url {} cached in {}".format(f, cached_f))
            f = cached_f
        # convert Caffe2 checkpoint from pkl
        if f.endswith(".pkl"):
            print
            return load_c2_format(self.cfg, f)
        # load native detectron.pytorch checkpoint
        loaded = super(DetectronCheckpointer, self)._load_file(f)

        # unload_keyword = list(self.cfg.FEW_SHOT.UNLOAD_KEYWORD)
        # if self.cfg.FEW_SHOT.LOAD_PRETRIANED_RPN_ONLY:
        #     unload_keyword += ['roi_heads']
        # new_dict = {}
        # for key,value in loaded.items():
        #     if any([ keyword in key for keyword in unload_keyword]):
        #         continue
        #     new_dict[key] = value
        # loaded = new_dict
        if "model" not in loaded:
            loaded = dict(model=loaded)
        return loaded
Esempio n. 4
0
    def _load_file(self, f):
        # f: catalog://ImageNetPretrained/MSRA/R-50
        if f.startswith("catalog://"):
            # 把paths_catalog.py作为一个module导入, 这个文件的路径是配置文件中设置的
            # 有可能存在于文件系统的任何位置, 因此不能直接import
            paths_catalog = import_file(
                "maskrcnn_benchmark.config.paths_catalog",
                self.cfg.PATHS_CATALOG,  # paths_catalog.py的绝对路径
                True)

            # 'https://dl.fbaipublicfiles.com/detectron/ImageNetPretrained/MSRA/R-50.pkl'
            # 获取pretrained model的url
            catalog_f = paths_catalog.ModelCatalog.get(f[len("catalog://"):])
            self.logger.info("{} points to {}".format(f, catalog_f))
            f = catalog_f

        # download url files
        if f.startswith("http"):
            # if the file is a url path, download it and cache it
            cached_f = cache_url(f)
            self.logger.info("url {} cached in {}".format(f, cached_f))
            f = cached_f

        # 把pkl文件转换成Caffe2模型文件
        if f.endswith(".pkl"):
            return load_c2_format(self.cfg, f)

        # load native detectron.pytorch checkpoint
        loaded = super(DetectronCheckpointer, self)._load_file(f)
        if "model" not in loaded:
            loaded = dict(model=loaded)

        return loaded
def resnet152(pretrained=False, **kwargs):
    """Constructs the ResNet-152 model.
    Args:
        pretrained (bool): If True, returns a model pre-trained on ImageNet.
    Returns:
        `nn.Module' instance.
    """
    model = ResNet(Bottleneck, [3, 8, 36, 3], **kwargs)
    if pretrained:
        model.load_state_dict(cache_url(model_urls['resnet152']))
    return model
def resnet34(pretrained=False, **kwargs):
    """Constructs the ResNet-34 model.
    Args:
        pretrained (bool): If True, returns a model pre-trained on ImageNet.
    Returns:
        `nn.Module' instance.
    """
    model = ResNet(BasicBlock, [3, 4, 6, 3], **kwargs)
    if pretrained:
        model.load_state_dict(cache_url(model_urls['resnet34']))
    return model
Esempio n. 7
0
def _load_file(cfg):
    f = cfg.MODEL.WEIGHT
    # catalog lookup
    if f.startswith("catalog://"):
        paths_catalog = import_file("maskrcnn_benchmark.config.paths_catalog",
                                    cfg.PATHS_CATALOG, True)
        catalog_f = paths_catalog.ModelCatalog.get(f[len("catalog://"):])

        f = catalog_f
    # download url files
    if f.startswith("http"):
        # if the file is a url path, download it and cache it
        cached_f = cache_url(f)

        f = cached_f
    # convert Caffe2 checkpoint from pkl
    if f.endswith(".pkl"):
        return load_c2_format(cfg, f)
Esempio n. 8
0
 def _load_file(self, f):
     # catalog lookup
     if f.startswith("catalog://"):
         paths_catalog = import_file(
             "maskrcnn_benchmark.config.paths_catalog", self.cfg.PATHS_CATALOG, True
         )
         catalog_f = paths_catalog.ModelCatalog.get(f[len("catalog://") :])
         self.logger.info("{} points to {}".format(f, catalog_f))
         f = catalog_f
     # download url files
     if f.startswith("http"):
         # if the file is a url path, download it and cache it
         cached_f = cache_url(f)
         self.logger.info("url {} cached in {}".format(f, cached_f))
         f = cached_f
     # convert Caffe2 checkpoint from pkl
     if f.endswith(".pkl"):
         return load_c2_format(self.cfg, f)
     # load native detectron.pytorch checkpoint
     loaded = super(DetectronCheckpointer, self)._load_file(f)
     if "model" not in loaded:
         loaded = dict(model=loaded)
     return loaded