layoutparser gives error "module layoutparser has no attribute ocr"

Viewed 2708

I am trying to use the new layoutparser package to do some OCR. However, coming from an R backgroud I have a hard time getting it up and running.

I installed it via (worked fine):

pip install layoutparser
pip install "layoutparser[ocr]"

Now, when I run the following I get an error:

import layoutparser as lp

import matplotlib.pyplot as plt

import pandas as pd
import numpy as np
import cv2

ocr_agent = lp.ocr.TesseractAgent()
AttributeError: module layoutparser has no attribute ocr
3 Answers

This worked for me (at least no python error):

import layoutparser.ocr as ocr
ocr_agent = ocr.TesseractAgent()

But need an explaination why the following does not work:

import layoutparser as lp
ocr_agent = lp.ocr.TesseractAgent()

The documentation states 'If you would like to use the Detectron2 models for layout detection, you might need to run the following command:'

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