-
Notifications
You must be signed in to change notification settings - Fork 983
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cd795a7
commit 4e60cc5
Showing
6 changed files
with
46 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,4 @@ | ||
import time | ||
|
||
import pypdfium2 # Causes a warning if not the top import | ||
import argparse | ||
import copy | ||
import json | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
import contextlib | ||
|
||
import torch | ||
from typing import List, Tuple, Generator | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,22 @@ | ||
import pytest | ||
from surya.model.ocr_error.model import load_model as load_ocr_error_model, load_tokenizer as load_ocr_error_processor | ||
from surya.model.layout.model import load_model as load_layout_model | ||
from surya.model.layout.processor import load_processor as load_layout_processor | ||
|
||
@pytest.fixture(scope="session") | ||
def ocr_error_model(): | ||
ocr_error_m = load_ocr_error_model() | ||
ocr_error_p = load_ocr_error_processor() | ||
ocr_error_m.processor = ocr_error_p | ||
yield ocr_error_m | ||
del ocr_error_m | ||
del ocr_error_m | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def layout_model(): | ||
layout_m = load_layout_model() | ||
layout_p = load_layout_processor() | ||
layout_m.processor = layout_p | ||
yield layout_m | ||
del layout_m | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import os | ||
os.environ["PYTORCH_ENABLE_MPS_FALLBACK"] = "1" | ||
|
||
from surya.layout import batch_layout_detection | ||
from PIL import Image, ImageDraw | ||
|
||
def test_layout_topk(layout_model): | ||
image = Image.new("RGB", (1024, 1024), "white") | ||
draw = ImageDraw.Draw(image) | ||
draw.text((10, 10), "Hello World", fill="black", font_size=72) | ||
draw.text((10, 200), "This is a sentence of text.\nNow it is a paragraph.\nA three-line one.", fill="black", | ||
font_size=24) | ||
|
||
layout_results = batch_layout_detection([image], layout_model, layout_model.processor) | ||
|
||
assert len(layout_results) == 1 | ||
assert layout_results[0].image_bbox == [0, 0, 1024, 1024] | ||
|
||
bboxes = layout_results[0].bboxes | ||
assert len(bboxes) == 2 | ||
|
||
assert bboxes[0].label == "SectionHeader" | ||
assert len(bboxes[0].top_k) == 5 | ||
|
||
assert bboxes[1].label == "Text" | ||
assert len(bboxes[1].top_k) == 5 |