Skip to content

Commit

Permalink
[demo/docs] Update notebook docs & minor demo update / fix (#1755)
Browse files Browse the repository at this point in the history
  • Loading branch information
felixT2K authored Oct 20, 2024
1 parent 7f21e76 commit 2ca3928
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 29 deletions.
24 changes: 12 additions & 12 deletions demo/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,14 @@ def main(det_archs, reco_archs):
# Only straight pages or possible rotation
st.sidebar.title("Parameters")
assume_straight_pages = st.sidebar.checkbox("Assume straight pages", value=True)
st.sidebar.write("\n")
# Disable page orientation detection
disable_page_orientation = st.sidebar.checkbox("Disable page orientation detection", value=False)
st.sidebar.write("\n")
# Disable crop orientation detection
disable_crop_orientation = st.sidebar.checkbox("Disable crop orientation detection", value=False)
st.sidebar.write("\n")
# Straighten pages
straighten_pages = st.sidebar.checkbox("Straighten pages", value=False)
# Export as straight boxes
export_straight_boxes = st.sidebar.checkbox("Export as straight boxes", value=False)
st.sidebar.write("\n")
# Binarization threshold
bin_thresh = st.sidebar.slider("Binarization threshold", min_value=0.1, max_value=0.9, value=0.3, step=0.1)
Expand All @@ -95,15 +94,16 @@ def main(det_archs, reco_archs):
else:
with st.spinner("Loading model..."):
predictor = load_predictor(
det_arch,
reco_arch,
assume_straight_pages,
straighten_pages,
disable_page_orientation,
disable_crop_orientation,
bin_thresh,
box_thresh,
forward_device,
det_arch=det_arch,
reco_arch=reco_arch,
assume_straight_pages=assume_straight_pages,
straighten_pages=straighten_pages,
export_as_straight_boxes=export_straight_boxes,
disable_page_orientation=disable_page_orientation,
disable_crop_orientation=disable_crop_orientation,
bin_thresh=bin_thresh,
box_thresh=box_thresh,
device=forward_device,
)

with st.spinner("Analyzing..."):
Expand Down
4 changes: 3 additions & 1 deletion demo/backend/pytorch.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def load_predictor(
reco_arch: str,
assume_straight_pages: bool,
straighten_pages: bool,
export_as_straight_boxes: bool,
disable_page_orientation: bool,
disable_crop_orientation: bool,
bin_thresh: float,
Expand All @@ -51,6 +52,7 @@ def load_predictor(
reco_arch: recognition architecture
assume_straight_pages: whether to assume straight pages or not
straighten_pages: whether to straighten rotated pages or not
export_as_straight_boxes: whether to export boxes as straight or not
disable_page_orientation: whether to disable page orientation or not
disable_crop_orientation: whether to disable crop orientation or not
bin_thresh: binarization threshold for the segmentation map
Expand All @@ -67,7 +69,7 @@ def load_predictor(
pretrained=True,
assume_straight_pages=assume_straight_pages,
straighten_pages=straighten_pages,
export_as_straight_boxes=straighten_pages,
export_as_straight_boxes=export_as_straight_boxes,
detect_orientation=not assume_straight_pages,
disable_page_orientation=disable_page_orientation,
disable_crop_orientation=disable_crop_orientation,
Expand Down
4 changes: 3 additions & 1 deletion demo/backend/tensorflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def load_predictor(
reco_arch: str,
assume_straight_pages: bool,
straighten_pages: bool,
export_as_straight_boxes: bool,
disable_page_orientation: bool,
disable_crop_orientation: bool,
bin_thresh: float,
Expand All @@ -50,6 +51,7 @@ def load_predictor(
reco_arch: recognition architecture
assume_straight_pages: whether to assume straight pages or not
straighten_pages: whether to straighten rotated pages or not
export_as_straight_boxes: whether to export boxes as straight or not
disable_page_orientation: whether to disable page orientation or not
disable_crop_orientation: whether to disable crop orientation or not
bin_thresh: binarization threshold for the segmentation map
Expand All @@ -67,7 +69,7 @@ def load_predictor(
pretrained=True,
assume_straight_pages=assume_straight_pages,
straighten_pages=straighten_pages,
export_as_straight_boxes=straighten_pages,
export_as_straight_boxes=export_as_straight_boxes,
detect_orientation=not assume_straight_pages,
disable_page_orientation=disable_page_orientation,
disable_crop_orientation=disable_crop_orientation,
Expand Down
1 change: 1 addition & 0 deletions demo/packages.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
python3-opencv
fonts-freefont-ttf
4 changes: 2 additions & 2 deletions doctr/io/elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def __init__(
if geometry is None:
# Check whether this is a rotated or straight box
box_resolution_fn = resolve_enclosing_rbbox if len(words[0].geometry) == 4 else resolve_enclosing_bbox
geometry = box_resolution_fn([w.geometry for w in words]) # type: ignore[operator]
geometry = box_resolution_fn([w.geometry for w in words]) # type: ignore[misc]

super().__init__(words=words)
self.geometry = geometry
Expand Down Expand Up @@ -232,7 +232,7 @@ def __init__(
box_resolution_fn = (
resolve_enclosing_rbbox if isinstance(lines[0].geometry, np.ndarray) else resolve_enclosing_bbox
)
geometry = box_resolution_fn(line_boxes + artefact_boxes) # type: ignore[operator]
geometry = box_resolution_fn(line_boxes + artefact_boxes) # type: ignore

super().__init__(lines=lines, artefacts=artefacts)
self.geometry = geometry
Expand Down
2 changes: 1 addition & 1 deletion doctr/models/utils/pytorch.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def export_model_to_onnx(model: nn.Module, model_name: str, dummy_input: torch.T
"""
torch.onnx.export(
model,
dummy_input,
dummy_input, # type: ignore[arg-type]
f"{model_name}.onnx",
input_names=["input"],
output_names=["logits"],
Expand Down
27 changes: 15 additions & 12 deletions notebooks/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@ docTR Notebooks

Here are some notebooks compiled for users to better leverage the library capabilities:

+--------------------------------------------------------------------------------------------------------+----------------------------------------------+---------------------------------------------------------------------------------------------------------------------+
| Notebook | Description | Colab |
+--------------------------------------------------------------------------------------------------------+----------------------------------------------+---------------------------------------------------------------------------------------------------------------------+
| `[Quicktour] <https://github.com/mindee/notebooks/blob/main/doctr/quicktour.ipynb>`_ | A presentation of the main features of docTR | .. image:: https://colab.research.google.com/assets/colab-badge.svg |
| | | :target: https://colab.research.google.com/github/mindee/notebooks/blob/main/doctr/quicktour.ipynb |
+--------------------------------------------------------------------------------------------------------+----------------------------------------------+---------------------------------------------------------------------------------------------------------------------+
| `[Export as PDF/A] <https://github.com/mindee/notebooks/blob/main/doctr/export_as_pdfa.ipynb>`_ | Produce searchable PDFs from docTR results | .. image:: https://colab.research.google.com/assets/colab-badge.svg |
| | | :target: https://colab.research.google.com/github/mindee/notebooks/blob/main/doctr/export_as_pdfa.ipynb |
+--------------------------------------------------------------------------------------------------------+----------------------------------------------+---------------------------------------------------------------------------------------------------------------------+
| `[Artefact detection] <https://github.com/mindee/notebooks/blob/main/doctr/artefact_detection.ipynb>`_ | Object detection for artefacts in documents | .. image:: https://colab.research.google.com/assets/colab-badge.svg |
| | | :target: https://colab.research.google.com/github/mindee/notebooks/blob/main/doctr/artefact_detection.ipynb |
+--------------------------------------------------------------------------------------------------------+----------------------------------------------+---------------------------------------------------------------------------------------------------------------------+
+--------------------------------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------+
| Notebook | Description | Colab |
+--------------------------------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------+
| `[Quicktour] <https://github.com/mindee/notebooks/blob/main/doctr/quicktour.ipynb>`_ | A presentation of the main features of docTR | .. image:: https://colab.research.google.com/assets/colab-badge.svg |
| | | :target: https://colab.research.google.com/github/mindee/notebooks/blob/main/doctr/quicktour.ipynb |
+--------------------------------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------+
| `[Export as PDF/A] <https://github.com/mindee/notebooks/blob/main/doctr/export_as_pdfa.ipynb>`_ | Produce searchable PDFs from docTR results | .. image:: https://colab.research.google.com/assets/colab-badge.svg |
| | | :target: https://colab.research.google.com/github/mindee/notebooks/blob/main/doctr/export_as_pdfa.ipynb |
+--------------------------------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------+
| `[Using standalone predictors] <https://github.com/mindee/notebooks/blob/main/doctr/using_standalone_predictors.ipynb>`_ | Showcase how to use detection, recognition, and orientation predictors| .. image:: https://colab.research.google.com/assets/colab-badge.svg |
| | | :target: https://colab.research.google.com/github/mindee/notebooks/blob/main/doctr/using_standalone_predictors.ipynb |
+--------------------------------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------+
| `[Dealing with rotated documents] <https://github.com/mindee/notebooks/blob/main/doctr/dealing_with_rotations.ipynb>`_ | A presentation on how to handle documents containing rotations | .. image:: https://colab.research.google.com/assets/colab-badge.svg |
| | | :target: https://colab.research.google.com/github/mindee/notebooks/blob/main/doctr/dealing_with_rotations.ipynb |
+--------------------------------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------+

0 comments on commit 2ca3928

Please sign in to comment.