dawsonia.ml.network.model#

Handwritten Text Recognition Neural Network.

Module Contents#

Classes#

HTRModel

HTRModel Class based on: Y. Soullard, C. Ruffino and T. Paquet, CTCModel: A Connectionnist Temporal Classification implementation for Keras. ee: https://arxiv.org/abs/1901.07957, 2019. github: ysoullard/HTRModel

CustomSchedule

Custom schedule of the learning rate with warmup_steps.

Functions#

bluche

Gated Convolucional Recurrent Neural Network by Bluche et al.

puigcerver

Convolucional Recurrent Neural Network by Puigcerver et al.

flor

Gated Convolucional Recurrent Neural Network by Flor et al.

puigcerver_octconv

Octave CNN by khinggan, architecture is same as puigcerver.

_create_octconv_last_block

Data#

logger

API#

dawsonia.ml.network.model.logger#

‘getLogger(…)’

class dawsonia.ml.network.model.HTRModel(architecture: str, input_size: tuple[int, int, int], vocab_size: int, greedy: bool = False, beam_width: int = 10, top_paths: int = 1, stop_tolerance: int = 20, reduce_tolerance: int = 15, cooldown: int = 0)#

HTRModel Class based on: Y. Soullard, C. Ruffino and T. Paquet, CTCModel: A Connectionnist Temporal Classification implementation for Keras. ee: https://arxiv.org/abs/1901.07957, 2019. github: ysoullard/HTRModel

The HTRModel class use Tensorflow 2 Keras module for the use of the Connectionist Temporal Classification (CTC) with the Hadwritten Text Recognition (HTR).

In a Tensorflow Keras Model, x is the input features and y the labels.

Initialization

Initialization of a HTR Model.

:param architecture: option of the architecture model to build and compile greedy, beam_width, top_paths: Parameters of the CTC decoding (see ctc decoding tensorflow for more details)

summary(output=None, target=None)#

Show/Save model structure (summary)

load_checkpoint(target)#

Load a model with checkpoint file.

get_callbacks(logdir, checkpoint, monitor='val_loss', verbose=0)#

Setup the list of callbacks for the model.

compile(learning_rate: dawsonia.ml.network.model.CustomSchedule | float | None = None, initial_step: int = 0)#

Configures the HTR Model for training/predict.

Parameters:

optimizer – optimizer for training

fit(x=None, y=None, batch_size=None, epochs=1, verbose=1, callbacks=None, validation_split=0.0, validation_data=None, shuffle=True, class_weight=None, sample_weight=None, initial_epoch=0, steps_per_epoch=None, validation_steps=None, validation_freq=1, max_queue_size=10, workers=1, use_multiprocessing=False, **kwargs)#

Model training on data yielded (fit function has support to generator). A fit() abstration function of TensorFlow 2.

Provide x parameter of the form: yielding (x, y, sample_weight).

Param:

See tensorflow.keras.Model.fit()

Returns:

A history object

predict(x, batch_size=None, verbose=0, steps=1, callbacks=None, max_queue_size=10, workers=1, use_multiprocessing=False, ctc_decode=True)#

Model predicting on data yielded (predict function has support to generator). A predict() abstration function of TensorFlow 2.

Provide x parameter of the form: yielding [x].

Param:

See tensorflow.keras.Model.predict()

Returns:

raw data on ctc_decode=False or CTC decode on ctc_decode=True (both with probabilities)

static ctc_loss_lambda_func(y_true, y_pred)#

Function for computing the CTC (Connectionist Temporal Classification) loss.

class dawsonia.ml.network.model.CustomSchedule(d_model, initial_step=0, warmup_steps=4000)#

Bases: tensorflow.keras.optimizers.schedules.LearningRateSchedule

Custom schedule of the learning rate with warmup_steps.

From original paper “Attention is all you need”.

Initialization

__call__(step)#
dawsonia.ml.network.model.bluche(input_size, d_model)#

Gated Convolucional Recurrent Neural Network by Bluche et al.

Reference:

Bluche, T., Messina, R.: Gated convolutional recurrent neural networks
for multilingual handwriting recognition.  In: Document Analysis and
Recognition (ICDAR), 2017 14th IAPR International Conference on, vol. 1,
pp. 646–651, 2017.  URL: https://ieeexplore.ieee.org/document/8270042
dawsonia.ml.network.model.puigcerver(input_size, d_model)#

Convolucional Recurrent Neural Network by Puigcerver et al.

Reference:

Joan Puigcerver.  Are multidimensional recurrent layers really necessary
for handwritten text recognition?  In: Document Analysis and Recognition
(ICDAR), 2017 14th IAPR International Conference on, vol. 1, pp. 67–72.
IEEE (2017)

Carlos Mocholí Calvo and Enrique Vidal Ruiz.  Development and
experimentation of a deep learning system for convolutional and
recurrent neural networks Escola Tècnica Superior d’Enginyeria
Informàtica, Universitat Politècnica de València, 2018
dawsonia.ml.network.model.flor(input_size, d_model)#

Gated Convolucional Recurrent Neural Network by Flor et al.

dawsonia.ml.network.model.puigcerver_octconv(input_size, d_model)#

Octave CNN by khinggan, architecture is same as puigcerver.

dawsonia.ml.network.model._create_octconv_last_block(inputs, ch, alpha)#