Skip to main content

Teklia DAN

Project description

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 = "images/page.jpg"
_, image = dan_model.preprocess(str(image_path))

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

# Predict
text, confidence_scores = model.predict(
    input_tensor,
    input_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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

atr_dan-0.2.0rc10.tar.gz (101.6 kB view details)

Uploaded Source

Built Distribution

atr_dan-0.2.0rc10-py3-none-any.whl (125.2 kB view details)

Uploaded Python 3

File details

Details for the file atr_dan-0.2.0rc10.tar.gz.

File metadata

  • Download URL: atr_dan-0.2.0rc10.tar.gz
  • Upload date:
  • Size: 101.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.14

File hashes

Hashes for atr_dan-0.2.0rc10.tar.gz
Algorithm Hash digest
SHA256 ae43c7d1dcce171336a1a76196c7ad8071ec6b6ab9bae50cedbe3e0e49b56a47
MD5 ba15cf5cbbb6455df70b79cfb0981792
BLAKE2b-256 d52cf01c45baad5e1f2d069179b56222444ab8cc7d958263193162b99fca6e9b

See more details on using hashes here.

File details

Details for the file atr_dan-0.2.0rc10-py3-none-any.whl.

File metadata

  • Download URL: atr_dan-0.2.0rc10-py3-none-any.whl
  • Upload date:
  • Size: 125.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.14

File hashes

Hashes for atr_dan-0.2.0rc10-py3-none-any.whl
Algorithm Hash digest
SHA256 617bc48ab84eea29027bccb65b7270d5369bbdb38c87a88d10616ae677b9b685
MD5 8c064bad4ceff6553d9e7c1532371dee
BLAKE2b-256 ab879b3ed58f75c9e00c61874a961e54063c89a8aa0b424f3847a2bdf4caec61

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page