Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gives wrong results when the code is run for some images in a loop #9

Closed
surajsubramanian opened this issue Feb 5, 2021 · 4 comments

Comments

@surajsubramanian
Copy link

The code works when it is run for a single image. But when I run the same code in a loop for few images from the publaynet dataset, cached results seem to apply (i.e. The bounding boxes overlap and the boxes for the previous images are also put in the current image).

@surajsubramanian
Copy link
Author

Code used :

import layoutparser as lp # and other imports
model = lp.Detectron2LayoutModel('lp://PubLayNet/mask_rcnn_R_50_FPN_3x/config')

for img in os.listdir('images'):
    if '.jpg' not in img:
        continue
    input_ = cv2.imread(os.path.join(root, 'images', img))
    root = os.getcwd()
    layout = model.detect(input_)
    output = lp.draw_box(input_, layout)
    output = np.array(output)
    cv2.imwrite(os.path.join(root, 'output', img), output)
    with open(os.path.join(root, 'output-json', img.split('.')[0] + '.txt'), 'w') as f:
        f.write(str(layout))

@lolipopshock
Copy link
Member

Thanks! It's fixed in v0.1.3:

canvas = canvas.copy()

@remidbs
Copy link

remidbs commented Apr 9, 2021

Hello! Thank you for your amazing work!
I ran into the same issue in version 0.1.3 and also with current master version of the code, so I think it is not resolved yet.
I fixed it by changing line 1488 of file layoutparser/elements.py from

    def __init__(self, blocks: List = [], page_data: Dict = None):
        self._blocks = blocks

to

    def __init__(self, blocks: Optional[List] = None, page_data: Dict = None):
        self._blocks = blocks if blocks is not None else []

See here for reference.

@lolipopshock
Copy link
Member

Hello! Thank you for your amazing work!
I ran into the same issue in version 0.1.3 and also with current master version of the code, so I think it is not resolved yet.
I fixed it by changing line 1488 of file layoutparser/elements.py from

    def __init__(self, blocks: List = [], page_data: Dict = None):
        self._blocks = blocks

to

    def __init__(self, blocks: Optional[List] = None, page_data: Dict = None):
        self._blocks = blocks if blocks is not None else []

See here for reference.

Thanks! Good catch and yeah, it's definitely incorrect to use [] as the default parameter value. Will fix this in the next release.

@lolipopshock lolipopshock reopened this Apr 10, 2021
lolipopshock added a commit that referenced this issue Apr 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants