Skip to main content

DAN: a Segmentation-free Document Attention Network for Handwritten Document Recognition

Python >= 3.10

For more details about this package, make sure to see the documentation available at https://atr.pages.teklia.com/dan/.

This is an open-source project, licensed using the CeCILL-C license.

Inference

To apply DAN to an image, one needs to first add a few imports and to load an image. Note that the image should be in RGB.

import cv2
from dan.ocr.predict.inference import DAN

image = cv2.cvtColor(cv2.imread(IMAGE_PATH), cv2.COLOR_BGR2RGB)

Then one can initialize and load the trained model with the parameters used during training. The directory passed as parameter should have:

  • a model.pt file,
  • a charset.pkl file,
  • a parameters.yml file corresponding to the inference_parameters.yml file generated during training.
from pathlib import Path

model_path = Path("models")

model = DAN("cpu")
model.load(model_path, mode="eval")

To run the inference on a GPU, one can replace cpu by the name of the GPU. In the end, one can run the prediction:

from pathlib import Path
from dan.utils import parse_charset_pattern

# Load image
image_path = Path("images/page.jpg")
image = read_image(image_path)
_, preprocessed_normalized_image = dan_model.preprocess(image)

input_tensor = preprocessed_normalized_image.unsqueeze(0)
input_tensor = input_tensor.to("cpu")
input_sizes = [preprocessed_normalized_image.shape[1:]]
original_sizes = [image.shape[1:]]

# Predict
text, confidence_scores = model.predict(
    input_tensor,
    input_sizes,
    original_sizes,
    char_separators=parse_charset_pattern(dan_model.charset),
    confidences=True,
)

Training

This package provides three subcommands. To get more information about any subcommand, use the --help option.

Get started

See the dedicated page on the official DAN documentation.

Data extraction from Arkindex

See the dedicated page on the official DAN documentation.

Model training

See the dedicated page on the official DAN documentation.

Model prediction

See the dedicated page on the official DAN documentation.

Release files for atr-dan 0.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for atr-dan 0.2.2
File Size Uploaded
atr_dan-0.2.2.tar.gz 105.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for atr-dan 0.2.2
File Interpreter ABI Platform
atr_dan-0.2.2-py3-none-any.whl Python 3 none any Details

Total release size: 235.5 kB

Release files / atr_dan-0.2.2.tar.gz

Download URL atr_dan-0.2.2.tar.gz
Size 105.7 kB
Tags Source
SHA-256 checksum
How to use checksums
61dceef1b199df1a2aace594900e7546eabf707636e07bae80fd049ef19a81b4
BLAKE2b-256 checksum
How to use checksums
d23a92c699bc5560842408609f6ce26a573a33fa0929936cef2fae2929ba187e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.13

Release files / atr_dan-0.2.2-py3-none-any.whl

Download URL atr_dan-0.2.2-py3-none-any.whl
Size 129.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c36b5c7c09640a4d734996542838d9f47d80489184a1a13a69b18f719dba6dfd
BLAKE2b-256 checksum
How to use checksums
13f6e1662e90e27d0d93268b613f9960030cbce3569d60b0e9227ff84c4f0ff0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.13
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page