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

Upgrade Keras to 2.4.0 to be compatible with Python 3.8 #86

Merged
merged 4 commits into from
Oct 9, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Add test_vision_model
  • Loading branch information
Hiromu Hota committed Oct 9, 2020
commit 7cc0f3c13df0e3d56074404a0478df0020f13dec
6 changes: 5 additions & 1 deletion pdftotree/visual/visual_utils.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import os
from typing import Tuple

import keras.backend as K
import numpy as np
import selectivesearch
from keras.preprocessing.image import img_to_array, load_img
from numpy import ndarray
from wand.color import Color
from wand.image import Image


def predict_heatmap(pdf_path, page_num, model, img_dim=448, img_dir="tmp/img"):
def predict_heatmap(
pdf_path, page_num, model, img_dim=448, img_dir="tmp/img"
) -> Tuple[ndarray, ndarray]:
"""
Return an image corresponding to the page of the pdf
documents saved at pdf_path. If the image is not found in img_dir this
Expand Down
3 changes: 2 additions & 1 deletion tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,5 @@ def test_vision_completion():
model_type="vision",
model_path="tests/input/paleo_visual_model.h5",
)
assert output is not None
soup = BeautifulSoup(output, "lxml")
assert len(soup.find_all("table")) == 2
20 changes: 20 additions & 0 deletions tests/test_table_detection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"""Test table area detection."""

from pdftotree.core import load_model
from pdftotree.visual.visual_utils import predict_heatmap


def test_vision_model():
"""Check if the vision model runs and returns results in expected format."""
pdf_file = "tests/input/paleo.pdf"
model_path = "tests/input/paleo_visual_model.h5"
model = load_model("vision", model_path)
page_num = 0
image, pred = predict_heatmap(
pdf_file, page_num, model
) # index start at 0 with wand
assert image.shape == (448, 448, 3)
assert pred.shape == (448, 448)


# TODO: add test_ml_model and test_heuristic_model