Skip to content

Commit 425966e

Browse files
authored
Merge pull request #18 from Layout-Parser/use-iopath
Update support for iopath, modified based on #17
2 parents ee20e9b + bdbcdde commit 425966e

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"torch",
2828
"torchvision",
2929
"pycocotools>=2.0.2",
30-
"fvcore==0.1.1.post20200623",
30+
"iopath",
3131
],
3232
extras_require={
3333
"ocr": [

src/layoutparser/models/catalog.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
from fvcore.common.file_io import PathHandler, PathManager, HTTPURLHandler
1+
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,11 +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

82+
PathManager = PathManagerBase()
8083
PathManager.register_handler(DropboxHandler())
8184
PathManager.register_handler(LayoutParserHandler())

src/layoutparser/models/layoutmodel.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55
from PIL import Image
66
import numpy as np
77
import torch
8-
from fvcore.common.file_io import PathManager
9-
10-
# TODO: Update to iopath in the next major release
118

9+
from .catalog import PathManager
1210
from ..elements import *
1311

1412
__all__ = ["Detectron2LayoutModel"]

0 commit comments

Comments
 (0)