Teklia DAN
Project description
DAN: a Segmentation-free Document Attention Network for Handwritten Document Recognition
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.ptfile, - a
charset.pklfile, - a
parameters.ymlfile corresponding to theinference_parameters.ymlfile 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file atr_dan-0.2.1.tar.gz.
File metadata
- Download URL: atr_dan-0.2.1.tar.gz
- Upload date:
- Size: 103.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
72e87eb09c6314de036384020f82263bb9fe3ba270f921d69a196c138e29882f
|
|
| MD5 |
91377f486c2f70a5c083f27a627081c8
|
|
| BLAKE2b-256 |
e8fe9c87178a2c127c74d43b94a7faf4589aaf0846e41f30b7c6445bb331bd0a
|
File details
Details for the file atr_dan-0.2.1-py3-none-any.whl.
File metadata
- Download URL: atr_dan-0.2.1-py3-none-any.whl
- Upload date:
- Size: 127.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e4fd9ca27289e013714cebf15d6f7f52bc884d5b95022f843e117e09488cc397
|
|
| MD5 |
68173940447022d8e2f2ef8715fc53c1
|
|
| BLAKE2b-256 |
3cd7e47b92b8973414c6948ec5c56921a85aed9667caab8dff4d394bcc58ca39
|