Skip to content

Commit bdbcdde

Browse files
committed
Fix PathManager Intialization
1 parent b7c3c88 commit bdbcdde

2 files changed

Lines changed: 9 additions & 7 deletions

File tree

src/layoutparser/models/catalog.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
from iopath.common.file_io import PathHandler, PathManager, HTTPURLHandler
2+
from iopath.common.file_io import PathManager as PathManagerBase
3+
# A trick learned from https://github.com/facebookresearch/detectron2/blob/65faeb4779e4c142484deeece18dc958c5c9ad18/detectron2/utils/file_io.py#L3
24

35
MODEL_CATALOG = {
46
'HJDataset': {
@@ -61,7 +63,7 @@ class LayoutParserHandler(PathHandler):
6163
def _get_supported_prefixes(self):
6264
return [self.PREFIX]
6365

64-
def _get_local_path(self, path):
66+
def _get_local_path(self, path, **kwargs):
6567
model_name = path[len(self.PREFIX):]
6668
dataset_name, *model_name, data_type = model_name.split('/')
6769

@@ -71,12 +73,12 @@ def _get_local_path(self, path):
7173
model_url = CONFIG_CATALOG[dataset_name]['/'.join(model_name)]
7274
else:
7375
raise ValueError(f"Unknown data_type {data_type}")
74-
return PathManager.get_local_path(model_url)
76+
return PathManager.get_local_path(model_url, **kwargs)
7577

7678
def _open(self, path, mode="r", **kwargs):
7779
return PathManager.open(self._get_local_path(path), mode, **kwargs)
7880

7981

80-
PathManagerSingleton = PathManager()
81-
PathManagerSingleton.register_handler(DropboxHandler())
82-
PathManagerSingleton.register_handler(LayoutParserHandler())
82+
PathManager = PathManagerBase()
83+
PathManager.register_handler(DropboxHandler())
84+
PathManager.register_handler(LayoutParserHandler())

src/layoutparser/models/layoutmodel.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import numpy as np
77
import torch
88

9-
from .catalog import PathManagerSingleton
9+
from .catalog import PathManager
1010
from ..elements import *
1111

1212
__all__ = ["Detectron2LayoutModel"]
@@ -93,7 +93,7 @@ class Detectron2LayoutModel(BaseLayoutModel):
9393
def __init__(self, config_path, model_path=None, label_map=None, extra_config=[]):
9494

9595
cfg = self._config.get_cfg()
96-
config_path = PathManagerSingleton.get_local_path(config_path)
96+
config_path = PathManager.get_local_path(config_path)
9797
cfg.merge_from_file(config_path)
9898
cfg.merge_from_list(extra_config)
9999

0 commit comments

Comments
 (0)