Layout-Parser / layout-parser

A Unified Toolkit for Deep Learning Based Document Image Analysis
https://layout-parser.github.io/
Apache License 2.0
4.75k stars 456 forks source link

NameError: name 'IMAGENET_DEFAULT_MEAN' without effdet extra #78

Closed de-code closed 2 years ago

de-code commented 2 years ago

Describe the bug

Following the installation instructions to use Detectron2, the command is:

pip install layoutparser torch && pip install "git+https://github.com/facebookresearch/detectron2.git@v0.5#egg=detectron2"

When trying to load the model (as per the example):

model = lp.Detectron2LayoutModel(
    'lp://PubLayNet/faster_rcnn_R_50_FPN_3x/config', 
     extra_config=["MODEL.ROI_HEADS.SCORE_THRESH_TEST", 0.8],
     label_map={0: "Text", 1: "Title", 2: "List", 3:"Table", 4:"Figure"}
)

That leads to the exception NameError: name 'IMAGENET_DEFAULT_MEAN' is not defined (see logs below)

Following the stacktrace, it seems to be related to EfficientDet.

The error goes away after installing that option via:

pip install layoutparser[effdet]

Environment Linux.

LayoutParser 0.3.1

Error traceback

logs ```text --------------------------------------------------------------------------- NameError Traceback (most recent call last) in ----> 1 model = lp.Detectron2LayoutModel( 2 'lp://PubLayNet/faster_rcnn_R_50_FPN_3x/config', 3 extra_config=["MODEL.ROI_HEADS.SCORE_THRESH_TEST", 0.8], 4 label_map={0: "Text", 1: "Title", 2: "List", 3:"Table", 4:"Figure"} 5 ) /opt/conda/lib/python3.8/site-packages/layoutparser/file_utils.py in __getattr__(self, name) 221 value = self._get_module(name) 222 elif name in self._class_to_module.keys(): --> 223 module = self._get_module(self._class_to_module[name]) 224 value = getattr(module, name) 225 else: /opt/conda/lib/python3.8/site-packages/layoutparser/file_utils.py in _get_module(self, module_name) 230 231 def _get_module(self, module_name: str): --> 232 return importlib.import_module("." + module_name, self.__name__) 233 234 def __reduce__(self): /opt/conda/lib/python3.8/importlib/__init__.py in import_module(name, package) 125 break 126 level += 1 --> 127 return _bootstrap._gcd_import(name[level:], package, level) 128 129 /opt/conda/lib/python3.8/importlib/_bootstrap.py in _gcd_import(name, package, level) /opt/conda/lib/python3.8/importlib/_bootstrap.py in _find_and_load(name, import_) /opt/conda/lib/python3.8/importlib/_bootstrap.py in _find_and_load_unlocked(name, import_) /opt/conda/lib/python3.8/importlib/_bootstrap.py in _call_with_frames_removed(f, *args, **kwds) /opt/conda/lib/python3.8/importlib/_bootstrap.py in _gcd_import(name, package, level) /opt/conda/lib/python3.8/importlib/_bootstrap.py in _find_and_load(name, import_) /opt/conda/lib/python3.8/importlib/_bootstrap.py in _find_and_load_unlocked(name, import_) /opt/conda/lib/python3.8/importlib/_bootstrap.py in _load_unlocked(spec) /opt/conda/lib/python3.8/importlib/_bootstrap_external.py in exec_module(self, module) /opt/conda/lib/python3.8/importlib/_bootstrap.py in _call_with_frames_removed(f, *args, **kwds) /opt/conda/lib/python3.8/site-packages/layoutparser/models/__init__.py in 15 from .detectron2.layoutmodel import Detectron2LayoutModel 16 from .paddledetection.layoutmodel import PaddleDetectionLayoutModel ---> 17 from .effdet.layoutmodel import EfficientDetLayoutModel 18 from .auto_layoutmodel import AutoLayoutModel /opt/conda/lib/python3.8/site-packages/layoutparser/models/effdet/__init__.py in 14 15 from . import catalog as _UNUSED ---> 16 from .layoutmodel import EfficientDetLayoutModel /opt/conda/lib/python3.8/site-packages/layoutparser/models/effdet/layoutmodel.py in 34 35 ---> 36 class InputTransform: 37 def __init__( 38 self, /opt/conda/lib/python3.8/site-packages/layoutparser/models/effdet/layoutmodel.py in InputTransform() 38 self, 39 image_size, ---> 40 mean=IMAGENET_DEFAULT_MEAN, 41 std=IMAGENET_DEFAULT_STD, 42 ): NameError: name 'IMAGENET_DEFAULT_MEAN' is not defined ```
lolipopshock commented 2 years ago

Gotcha! Thant's a good point and let me work on a fix!

lolipopshock commented 2 years ago

Fixed in #79