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

[cherry-pick] fix layout recovery import error #13604

Merged
merged 1 commit into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,24 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from .paddleocr import *
from .paddleocr import (
PaddleOCR,
PPStructure,
draw_ocr,
draw_structure_result,
save_structure_res,
download_with_progressbar,
sorted_layout_boxes,
convert_info_docx,
to_excel,
)
import importlib.metadata as importlib_metadata

try:
__version__ = importlib_metadata.version(__package__ or __name__)
except importlib_metadata.PackageNotFoundError:
__version__ = "0.0.0"

__all__ = [
"PaddleOCR",
"PPStructure",
Expand Down
9 changes: 4 additions & 5 deletions paddleocr.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
sys.path.append(os.path.join(__dir__, ""))

import cv2
from copy import deepcopy
import logging
import numpy as np
from pathlib import Path
Expand Down Expand Up @@ -65,6 +66,7 @@ def _import_file(module_name, file_path, make_importable=False):
from tools.infer.utility import draw_ocr, str2bool, check_gpu
from ppstructure.utility import init_args, draw_structure_result
from ppstructure.predict_system import StructureSystem, save_structure_res, to_excel
from ppstructure.recovery.recovery_to_doc import sorted_layout_boxes, convert_info_docx

logger = get_logger()

Expand All @@ -76,6 +78,8 @@ def _import_file(module_name, file_path, make_importable=False):
"save_structure_res",
"download_with_progressbar",
"to_excel",
"sorted_layout_boxes",
"convert_info_docx",
]

SUPPORT_DET_MODEL = ["DB"]
Expand Down Expand Up @@ -939,18 +943,13 @@ def main():
save_structure_res(result, args.output, img_name, index)

if args.recovery and result != []:
from copy import deepcopy
from ppstructure.recovery.recovery_to_doc import sorted_layout_boxes

h, w, _ = img.shape
result_cp = deepcopy(result)
result_sorted = sorted_layout_boxes(result_cp, w)
all_res += result_sorted

if args.recovery and all_res != []:
try:
from ppstructure.recovery.recovery_to_doc import convert_info_docx

convert_info_docx(img, all_res, args.output, img_name)
except Exception as ex:
logger.error(
Expand Down