Skip to content

Commit

Permalink
Deploying to gh-pages from @ 9b6dea3 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
felixdittrich92 committed Dec 4, 2024
1 parent cd8f884 commit 55e093d
Show file tree
Hide file tree
Showing 113 changed files with 2,164 additions and 352 deletions.
Binary file modified .doctrees/environment.pickle
Binary file not shown.
11 changes: 9 additions & 2 deletions latest/_modules/doctr/models/classification/zoo.html
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ <h1>Source code for doctr.models.classification.zoo</h1><div class="highlight"><

<span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">Any</span>

<span class="kn">from</span> <span class="nn">doctr.file_utils</span> <span class="kn">import</span> <span class="n">is_tf_available</span>
<span class="kn">from</span> <span class="nn">doctr.file_utils</span> <span class="kn">import</span> <span class="n">is_tf_available</span><span class="p">,</span> <span class="n">is_torch_available</span>

<span class="kn">from</span> <span class="nn">..</span> <span class="kn">import</span> <span class="n">classification</span>
<span class="kn">from</span> <span class="nn">..preprocessor</span> <span class="kn">import</span> <span class="n">PreProcessor</span>
Expand Down Expand Up @@ -346,7 +346,14 @@ <h1>Source code for doctr.models.classification.zoo</h1><div class="highlight"><
<span class="c1"># Load directly classifier from backbone</span>
<span class="n">_model</span> <span class="o">=</span> <span class="n">classification</span><span class="o">.</span><span class="vm">__dict__</span><span class="p">[</span><span class="n">arch</span><span class="p">](</span><span class="n">pretrained</span><span class="o">=</span><span class="n">pretrained</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">arch</span><span class="p">,</span> <span class="n">classification</span><span class="o">.</span><span class="n">MobileNetV3</span><span class="p">):</span>
<span class="n">allowed_archs</span> <span class="o">=</span> <span class="p">[</span><span class="n">classification</span><span class="o">.</span><span class="n">MobileNetV3</span><span class="p">]</span>
<span class="k">if</span> <span class="n">is_torch_available</span><span class="p">():</span>
<span class="c1"># Adding the type for torch compiled models to the allowed architectures</span>
<span class="kn">from</span> <span class="nn">doctr.models.utils</span> <span class="kn">import</span> <span class="n">_CompiledModule</span>

<span class="n">allowed_archs</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">_CompiledModule</span><span class="p">)</span>

<span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">arch</span><span class="p">,</span> <span class="nb">tuple</span><span class="p">(</span><span class="n">allowed_archs</span><span class="p">)):</span>
<span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;unknown architecture: </span><span class="si">{</span><span class="nb">type</span><span class="p">(</span><span class="n">arch</span><span class="p">)</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">)</span>
<span class="n">_model</span> <span class="o">=</span> <span class="n">arch</span>

Expand Down
9 changes: 8 additions & 1 deletion latest/_modules/doctr/models/detection/zoo.html
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,14 @@ <h1>Source code for doctr.models.detection.zoo</h1><div class="highlight"><pre>
<span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">_model</span><span class="p">,</span> <span class="n">detection</span><span class="o">.</span><span class="n">FAST</span><span class="p">):</span>
<span class="n">_model</span> <span class="o">=</span> <span class="n">reparameterize</span><span class="p">(</span><span class="n">_model</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">arch</span><span class="p">,</span> <span class="p">(</span><span class="n">detection</span><span class="o">.</span><span class="n">DBNet</span><span class="p">,</span> <span class="n">detection</span><span class="o">.</span><span class="n">LinkNet</span><span class="p">,</span> <span class="n">detection</span><span class="o">.</span><span class="n">FAST</span><span class="p">)):</span>
<span class="n">allowed_archs</span> <span class="o">=</span> <span class="p">[</span><span class="n">detection</span><span class="o">.</span><span class="n">DBNet</span><span class="p">,</span> <span class="n">detection</span><span class="o">.</span><span class="n">LinkNet</span><span class="p">,</span> <span class="n">detection</span><span class="o">.</span><span class="n">FAST</span><span class="p">]</span>
<span class="k">if</span> <span class="n">is_torch_available</span><span class="p">():</span>
<span class="c1"># Adding the type for torch compiled models to the allowed architectures</span>
<span class="kn">from</span> <span class="nn">doctr.models.utils</span> <span class="kn">import</span> <span class="n">_CompiledModule</span>

<span class="n">allowed_archs</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">_CompiledModule</span><span class="p">)</span>

<span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">arch</span><span class="p">,</span> <span class="nb">tuple</span><span class="p">(</span><span class="n">allowed_archs</span><span class="p">)):</span>
<span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;unknown architecture: </span><span class="si">{</span><span class="nb">type</span><span class="p">(</span><span class="n">arch</span><span class="p">)</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">)</span>

<span class="n">_model</span> <span class="o">=</span> <span class="n">arch</span>
Expand Down
13 changes: 9 additions & 4 deletions latest/_modules/doctr/models/recognition/zoo.html
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ <h1>Source code for doctr.models.recognition.zoo</h1><div class="highlight"><pre

<span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">Any</span>

<span class="kn">from</span> <span class="nn">doctr.file_utils</span> <span class="kn">import</span> <span class="n">is_tf_available</span>
<span class="kn">from</span> <span class="nn">doctr.file_utils</span> <span class="kn">import</span> <span class="n">is_tf_available</span><span class="p">,</span> <span class="n">is_torch_available</span>
<span class="kn">from</span> <span class="nn">doctr.models.preprocessor</span> <span class="kn">import</span> <span class="n">PreProcessor</span>

<span class="kn">from</span> <span class="nn">..</span> <span class="kn">import</span> <span class="n">recognition</span>
Expand Down Expand Up @@ -333,9 +333,14 @@ <h1>Source code for doctr.models.recognition.zoo</h1><div class="highlight"><pre
<span class="n">pretrained</span><span class="o">=</span><span class="n">pretrained</span><span class="p">,</span> <span class="n">pretrained_backbone</span><span class="o">=</span><span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;pretrained_backbone&quot;</span><span class="p">,</span> <span class="kc">True</span><span class="p">)</span>
<span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span>
<span class="n">arch</span><span class="p">,</span> <span class="p">(</span><span class="n">recognition</span><span class="o">.</span><span class="n">CRNN</span><span class="p">,</span> <span class="n">recognition</span><span class="o">.</span><span class="n">SAR</span><span class="p">,</span> <span class="n">recognition</span><span class="o">.</span><span class="n">MASTER</span><span class="p">,</span> <span class="n">recognition</span><span class="o">.</span><span class="n">ViTSTR</span><span class="p">,</span> <span class="n">recognition</span><span class="o">.</span><span class="n">PARSeq</span><span class="p">)</span>
<span class="p">):</span>
<span class="n">allowed_archs</span> <span class="o">=</span> <span class="p">[</span><span class="n">recognition</span><span class="o">.</span><span class="n">CRNN</span><span class="p">,</span> <span class="n">recognition</span><span class="o">.</span><span class="n">SAR</span><span class="p">,</span> <span class="n">recognition</span><span class="o">.</span><span class="n">MASTER</span><span class="p">,</span> <span class="n">recognition</span><span class="o">.</span><span class="n">ViTSTR</span><span class="p">,</span> <span class="n">recognition</span><span class="o">.</span><span class="n">PARSeq</span><span class="p">]</span>
<span class="k">if</span> <span class="n">is_torch_available</span><span class="p">():</span>
<span class="c1"># Adding the type for torch compiled models to the allowed architectures</span>
<span class="kn">from</span> <span class="nn">doctr.models.utils</span> <span class="kn">import</span> <span class="n">_CompiledModule</span>

<span class="n">allowed_archs</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">_CompiledModule</span><span class="p">)</span>

<span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">arch</span><span class="p">,</span> <span class="nb">tuple</span><span class="p">(</span><span class="n">allowed_archs</span><span class="p">)):</span>
<span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;unknown architecture: </span><span class="si">{</span><span class="nb">type</span><span class="p">(</span><span class="n">arch</span><span class="p">)</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">)</span>
<span class="n">_model</span> <span class="o">=</span> <span class="n">arch</span>

Expand Down
77 changes: 72 additions & 5 deletions latest/_sources/using_doctr/using_model_export.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ Advantages:
.. code:: python3
import torch
predictor = ocr_predictor(reco_arch="crnn_mobilenet_v3_small", det_arch="linknet_resnet34", pretrained=True).cuda().half()
predictor = ocr_predictor(
reco_arch="crnn_mobilenet_v3_small",
det_arch="linknet_resnet34",
pretrained=True
).cuda().half()
res = predictor(doc)
.. tab:: TensorFlow
Expand All @@ -41,8 +45,63 @@ Advantages:
import tensorflow as tf
from tensorflow.keras import mixed_precision
mixed_precision.set_global_policy('mixed_float16')
predictor = ocr_predictor(reco_arch="crnn_mobilenet_v3_small", det_arch="linknet_resnet34", pretrained=True)
predictor = ocr_predictor(
reco_arch="crnn_mobilenet_v3_small",
det_arch="linknet_resnet34",
pretrained=True
)
Compiling your models (PyTorch only)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

**NOTE:**

- This feature is only available if you use PyTorch as backend.
- The recognition architecture `master` is not supported for model compilation yet.
- We provide only official support for the default (`inductor`) backend, but you can try other backends, configurations depending on your hardware and requirements as well.

Compiling your PyTorch models with `torch.compile` optimizes the model by converting it to a graph representation and applying backends that can improve performance.
This process can make inference faster and reduce memory overhead during execution.

Further information can be found in the `PyTorch documentation <https://pytorch.org/tutorials/intermediate/torch_compile_tutorial.html>`_.

.. code::
import torch
from doctr.models import (
ocr_predictor,
vitstr_small,
fast_base,
mobilenet_v3_small_crop_orientation,
mobilenet_v3_small_page_orientation,
crop_orientation_predictor,
page_orientation_predictor
)
# Compile the models
detection_model = torch.compile(
fast_base(pretrained=True).eval()
)
recognition_model = torch.compile(
vitstr_small(pretrained=True).eval()
)
crop_orientation_model = torch.compile(
mobilenet_v3_small_crop_orientation(pretrained=True).eval()
)
page_orientation_model = torch.compile(
mobilenet_v3_small_page_orientation(pretrained=True).eval()
)
predictor = models.ocr_predictor(
detection_model, recognition_model, assume_straight_pages=False
)
# NOTE: Only required for non-straight pages (`assume_straight_pages=False`) and non-disabled orientation classification
# Set the orientation predictors
predictor.crop_orientation_predictor = crop_orientation_predictor(crop_orientation_model)
predictor.page_orientation_predictor = page_orientation_predictor(page_orientation_model)
compiled_out = predictor(doc)
Export to ONNX
^^^^^^^^^^^^^^
Expand All @@ -64,7 +123,11 @@ It defines a common format for representing models, including the network struct
input_shape = (3, 32, 128)
model = vitstr_small(pretrained=True, exportable=True)
dummy_input = torch.rand((batch_size, input_shape), dtype=torch.float32)
model_path = export_model_to_onnx(model, model_name="vitstr.onnx, dummy_input=dummy_input)
model_path = export_model_to_onnx(
model,
model_name="vitstr.onnx",
dummy_input=dummy_input
)
.. tab:: TensorFlow

Expand All @@ -78,7 +141,11 @@ It defines a common format for representing models, including the network struct
input_shape = (32, 128, 3)
model = vitstr_small(pretrained=True, exportable=True)
dummy_input = [tf.TensorSpec([batch_size, input_shape], tf.float32, name="input")]
model_path, output = export_model_to_onnx(model, model_name="vitstr.onnx", dummy_input=dummy_input)
model_path, output = export_model_to_onnx(
model,
model_name="vitstr.onnx",
dummy_input=dummy_input
)
Using your ONNX exported model
Expand Down
12 changes: 6 additions & 6 deletions latest/_sources/using_doctr/using_models.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ For instance, this snippet instantiates an end-to-end ocr_predictor working with

.. code:: python3
from doctr.model import ocr_predictor
from doctr.models import ocr_predictor
model = ocr_predictor('linknet_resnet18', pretrained=True, assume_straight_pages=False, preserve_aspect_ratio=True)
Expand All @@ -309,7 +309,7 @@ Additionally, you can change the batch size of the underlying detection and reco

.. code:: python3
from doctr.model import ocr_predictor
from doctr.models import ocr_predictor
model = ocr_predictor(pretrained=True, det_bs=4, reco_bs=1024)
To modify the output structure you can pass the following arguments to the predictor which will be handled by the underlying `DocumentBuilder`:
Expand All @@ -322,7 +322,7 @@ For example to disable the automatic grouping of lines into blocks:

.. code:: python3
from doctr.model import ocr_predictor
from doctr.models import ocr_predictor
model = ocr_predictor(pretrained=True, resolve_blocks=False)
Expand Down Expand Up @@ -477,7 +477,7 @@ This will only have an effect with `assume_straight_pages=False` and/or `straigh

.. code:: python3
from doctr.model import ocr_predictor
from doctr.models import ocr_predictor
model = ocr_predictor(pretrained=True, assume_straight_pages=False, disable_page_orientation=True)
Expand All @@ -489,15 +489,15 @@ This will only have an effect with `assume_straight_pages=False` and/or `straigh

.. code:: python3
from doctr.model import ocr_predictor
from doctr.models import ocr_predictor
model = ocr_predictor(pretrained=True, assume_straight_pages=False, disable_crop_orientation=True)
* Add a hook to the `ocr_predictor` to manipulate the location predictions before the crops are passed to the recognition model.

.. code:: python3
from doctr.model import ocr_predictor
from doctr.models import ocr_predictor
class CustomHook:
def __call__(self, loc_preds):
Expand Down
Binary file modified latest/objects.inv
Binary file not shown.
2 changes: 1 addition & 1 deletion latest/searchindex.js

Large diffs are not rendered by default.

Loading

0 comments on commit 55e093d

Please sign in to comment.