-
Notifications
You must be signed in to change notification settings - Fork 1k
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
c3d8b1d
commit f83f25e
Showing
8 changed files
with
1,857 additions
and
1,458 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
name: Integration test with benchmark | ||
|
||
on: [push] | ||
|
||
env: | ||
TESSDATA_PREFIX: "/usr/share/tesseract-ocr/4.00/tessdata" | ||
TORCH_DEVICE: "cpu" | ||
OCR_ENGINE: "tesseract" # So we don't have to install ghostscript, which takes a long time | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up Python 3.11 | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: 3.11 | ||
- name: Install system dependencies | ||
run: cat scripts/install/apt-requirements.txt | xargs sudo apt-get install -y | ||
- name: Show tessdata folders | ||
run: ls /usr/share/tesseract-ocr/ | ||
- name: Install python dependencies | ||
run: | | ||
pip install poetry | ||
poetry install | ||
poetry remove torch | ||
poetry run pip install torch --index-url https://download.pytorch.org/whl/cpu | ||
- name: Download benchmark data | ||
run: | | ||
wget -O benchmark_data.zip "https://drive.google.com/uc?export=download&id=1ktVDYPEeyHlKLaF56FnHjI5VjVnYa1xL" | ||
unzip benchmark_data.zip | ||
- name: Run benchmark test | ||
run: | | ||
poetry run python benchmark.py benchmark_data/pdfs benchmark_data/references report.json | ||
poetry run python scripts/verify_benchmark_scores.py report.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
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 |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import base64 | ||
import json | ||
import os | ||
import zlib | ||
from typing import List | ||
|
||
from marker.schema import Page | ||
from marker.settings import settings | ||
from PIL import Image | ||
import io | ||
|
||
|
||
def dump_nougat_debug_data(doc, images, converted_spans): | ||
if not settings.DEBUG or not settings.DEBUG_DATA_FOLDER: | ||
return | ||
|
||
# We attempted one conversion per image | ||
assert len(converted_spans) == len(images) | ||
|
||
data_lines = [] | ||
for idx, (image, converted_span) in enumerate(zip(images, converted_spans)): | ||
if converted_span is None: | ||
continue | ||
# Image is a BytesIO object | ||
pil_image = Image.open(image) | ||
img_bytes = io.BytesIO() | ||
pil_image.save(img_bytes, format="WEBP", lossless=True) | ||
b64_image = base64.b64encode(img_bytes.getvalue()).decode("utf-8") | ||
data_lines.append({ | ||
"image": b64_image, | ||
"text": converted_span.text, | ||
"bbox": converted_span.bbox | ||
}) | ||
|
||
# Remove extension from doc name | ||
doc_base = os.path.basename(doc.name).rsplit(".", 1)[0] | ||
|
||
debug_file = os.path.join(settings.DEBUG_DATA_FOLDER, f"{doc_base}_equations.json") | ||
with open(debug_file, "w+") as f: | ||
json.dump(data_lines, f, indent=4) | ||
|
||
|
||
def dump_bbox_debug_data(doc, blocks: List[Page]): | ||
if not settings.DEBUG or not settings.DEBUG_DATA_FOLDER: | ||
return | ||
|
||
# Remove extension from doc name | ||
doc_base = os.path.basename(doc.name).rsplit(".", 1)[0] | ||
|
||
debug_file = os.path.join(settings.DEBUG_DATA_FOLDER, f"{doc_base}_bbox.json") | ||
debug_data = [] | ||
for idx, page_blocks in enumerate(blocks): | ||
page = doc[idx] | ||
|
||
pix = page.get_pixmap(dpi=settings.NOUGAT_DPI, annots=False, clip=page_blocks.bbox) | ||
png = pix.pil_tobytes(format="PNG") | ||
png_image = Image.open(io.BytesIO(png)) | ||
width, height = png_image.size | ||
max_dimension = 6000 | ||
if width > max_dimension or height > max_dimension: | ||
scaling_factor = min(max_dimension / width, max_dimension / height) | ||
png_image = png_image.resize((int(width * scaling_factor), int(height * scaling_factor)), Image.ANTIALIAS) | ||
|
||
img_bytes = io.BytesIO() | ||
png_image.save(img_bytes, format="WEBP", lossless=True, quality=100) | ||
b64_image = base64.b64encode(img_bytes.getvalue()).decode("utf-8") | ||
|
||
page_data = page_blocks.model_dump() | ||
page_data["image"] = b64_image | ||
debug_data.append(page_data) | ||
|
||
with open(debug_file, "w+") as f: | ||
json.dump(debug_data, f, indent=4) | ||
|
||
|
||
|
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
Oops, something went wrong.