Netout
The pylaia-htr-netout
command can be used to dump the features extracted by PyLaia for a set of text-lines. To know more about the options of this command, use pylaia-htr-netout --help
.
This command was initially designed to combine PyLaia and Kaldi. Since December 2022, combining PyLaia with language models can be achieved more easily by building a language model with KenLM and predicting with pylaia-htr-decode-ctc .
|
Purpose
This command outputs the feature matrix and lattice computed by PyLaia in Kaldi format for a given dataset.
It requires:
-
the pickled
model
file created during model initialization, -
the weights
*.ckpt
of the trained model created during model training.
The files generated by this command are designed to combine PyLaia and Kaldi, but could also be used to predict with a custom decoder.
Parameters
The full list of parameters is detailed in this section.
General parameters
Parameter | Description | Type | Default |
---|---|---|---|
|
Positional argument. File containing the names of the images to decode (one image per line). |
|
|
|
Directories containing line images. |
|
|
|
Path to a JSON configuration file |
|
Common parameters
Name | Description | Type | Default |
---|---|---|---|
|
Directory where the model will be saved |
|
|
|
Filename of the model. |
|
|
|
Directory name of the experiment. |
|
|
|
Checkpoint to load. Must be a filepath, a filename, a glob pattern or |
|
|
Data arguments
Name | Description | Type | Default |
---|---|---|---|
|
Batch size. |
|
|
|
Color mode. Must be either |
|
|
Netout arguments
Name | Description | Type | Default |
---|---|---|---|
|
Transformation to apply at the end of the model. Should be |
|
|
|
Path to the output file containing a list of keys (image ids) and values (output matrix where rows represents timesteps and columns CTC labels). This file can be directly used with Kaldi. |
|
|
|
Path to the output file containing containing a list of keys (image ids) and values (lattices representing the CTC output). This file can be directly used with Kaldi. |
|
|
|
Number of digits to be used for formatting |
|
|
Logging arguments
Name | Description | Type | Default |
---|---|---|---|
|
Logging format. |
|
|
|
Logging level. Should be in
|
|
|
|
Filepath for the logs file. Can be a filepath or a filename to be created in |
|
|
|
Whether to overwrite the logfile or to append. |
|
|
|
If filename is set, use this to log also to stderr at the given level. |
|
|
Trainer arguments
Pytorch Lightning Trainer
flags can also be set using the --trainer
argument. See the documentation.
This flag is mostly useful to define whether to predict on CPU or GPU.
-
--trainer.gpus 0
to run on CPU, -
--trainer.gpus n
to run onn
GPUs (use with--training.auto_select True
for auto-selection), -
--trainer.gpus -1
to run on all GPUs.
Examples
Dumping PyLaia’s features can be done using command-line arguments or a YAML configuration file. Note that CLI arguments override the values from the configuration file.
Dumping features from a model from Hugging Face
First, clone a trained model from Hugging Face:
git clone https://huggingface.co/Teklia/pylaia-huginmunin
List image names in img_list.txt
:
docs/assets/219007024-f45433e7-99fd-43b0-bce6-93f63fa72a8f
docs/assets/219008758-c0097bb4-c55a-4652-ad2e-bba350bee0e4
Dump PyLaia’s output with:
pylaia-htr-netout --common.experiment_dirname pylaia-huginmunin/ \
--common.model_filename pylaia-huginmunin/model \
--netout.matrix matrix.txt \
--netout.lattice lattice.txt \
--img_dir [docs/assets] \
img_list.txt
Output files will be written in --common.experiment_dirname
:
├── pylaia-huginmunin/ ├── matrix.txt └── lattice.txt
Dumping features using a YAML configuration file
Run the following command to dump PyLaia’s output:
pylaia-htr-decode-ctc --config config_netout.yaml
With the following configuration file:
common:
experiment_dirname: pylaia-huginmunin
model_filename: pylaia-huginmunin/model
img_list: img_list.txt
img_dirs:
- docs/assets/
netout:
matrix: matrix.txt
lattice: lattice.txt
Output files will be written in --common.experiment_dirname
:
├── pylaia-huginmunin/ ├── matrix.txt └── lattice.txt