Layout-Parser / layout-parser

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

[AutoLayoutModel] Outdated docs and silent error #136

Closed falcaopetri closed 2 years ago

falcaopetri commented 2 years ago

Describe the bug README contains the following (since #73):

Perform DL layout detection in 4 lines of code

import layoutparser as lp
model = lp.AutoLayoutModel('lp://EfficientDete/PubLayNet')
# image = Image.open("path/to/image")
layout = model.detect(image) 

This fails to instantiate a valid model because AutoLayoutModel runs https://github.com/Layout-Parser/layout-parser/blob/89aca0320acbeb8348369dba060bd1c892fbd50f/src/layoutparser/models/auto_layoutmodel.py#L62-L63

and

>>> import layoutparser as lp
>>> list(lp.models.auto_layoutmodel.ALL_AVAILABLE_BACKENDS)
['detectron2', 'paddledetection', 'efficientdet']

i.e., 'efficientdet' is not in 'lp://EfficientDete/PubLayNet'.

When AutoLayoutModel cannot find a model to instantiate, it silently returns None (because it returns nothing). This means that we get AttributeError: 'NoneType' object has no attribute 'detect' during layout = model.detect(image)

My suggestions are:

lolipopshock commented 2 years ago

Thanks -- Good catch! Will fix it later

lolipopshock commented 2 years ago

Also see #86