Skip to content

How to run

Carlos Mocholí edited this page Nov 17, 2020 · 7 revisions

Using shell

Note: PyLaia is only officially supported for Linux

Once installed, PyLaia provides several script entry points, these are:

$ pylaia-htr-create-model
$ pylaia-htr-train-ctc
$ pylaia-htr-decode-ctc
$ pylaia-htr-netout

You can read each script's help message by running:

$ pylaia-htr-train-ctc -h
usage: pylaia-htr-train-ctc [-h] ...

Each script has a set of required positional parameters and multiple sets of optional arguments, for example:

$ pylaia-htr-train-ctc syms [img_dir] {tr,va}_txt_table --trainer.gpus=2

where syms, [img_dir], tr_txt_table, and va_txt_table are required positional arguments and gpus is an optional argument inside the trainer set of arguments. Default values are automatically set for each optional parameter, however, you may want to override these to fit your use case. All optional parameters are prepended by --.

Arguments format

Parameters passed via shell of a type do not use the exact same notation as Python. The Python to shell mapping for the most common is:

  • None: --param=null
  • "" (empty string): --param=
  • " " (one space): --param="' '" or --param=\
  • str: --param=Adam or --param='Adam'
  • number: --param=1.234
  • list or tuple: --param=[one,two,three] or --param='[one, two, three]'
  • bool: --param=yes|true|on or --param=no|false|off. Case insensitive.

PyLaia uses jsonargparse to expose its complex API to the command line. For further details, have a look at its docs.

Using a configuration file

Each script can generate its default configuration file:

$ pylaia-htr-train-ctc --print-config > train_config.yaml
$ cat train_config.yaml
common:
  checkpoint: null
  experiment_dirname: experiment
  model_filename: model
  monitor: va_cer
...

Modify this configuration file to fit your use case. Attributes can be removed, in which case, its default value will be used.

To run the script with a configuration file:

$ pylaia-htr-train-ctc --config=train_config.yaml

Regardless of what is set in the configuration file, parameters can be overridden by passing them to the command line:

$ pylaia-htr-train-ctc --config=train_config.yaml --trainer.gpus=4

Using Python

PyLaia's scripts can also be run using Python. Import them with any of:

from laia.scripts.htr.create_model import run
from laia.scripts.htr.train_ctc import run
from laia.scripts.htr.decode_ctc import run
from laia.scripts.htr.netout import run

The keyword (optional) parameters of each function are given using dataclasses. These act as parameter interfaces. For example:

import laia.common.arguments as args

run(syms, img_dirs, tr_txt_table, va_txt_table, trainer=args.TrainerArgs(gpus=[0,1]))

# These are the classes optionally used in each script:
# all: CommonArgs
# create-model: CreateCRNNArgs
# train-ctc: TrainArgs, OptimizerArgs, SchedulerArgs, DataArgs, TrainerArgs
# decode-ctc: DecodeArgs, DataArgs, TrainerArgs
# netout: NetoutArgs, DataArgs, TrainerArgs

Currently, the run functions have no return value. Results are logged to stdout or saved to files. Logs are logged to stderr or saved to a file. This is the same behaviour as using shell.

Clone this wiki locally