Shortcuts

CEModuleLoss

class mmocr.models.textrecog.CEModuleLoss(dictionary, max_seq_len=40, letter_case='unchanged', pad_with='auto', ignore_char='padding', flatten=False, reduction='none', ignore_first_char=False)[源代码]

Implementation of loss module for encoder-decoder based text recognition method with CrossEntropy loss.

参数
  • dictionary (dict or Dictionary) – The config for Dictionary or the instance of Dictionary.

  • max_seq_len (int) – Maximum sequence length. The sequence is usually generated from decoder. Defaults to 40.

  • letter_case (str) – There are three options to alter the letter cases of gt texts: - unchanged: Do not change gt texts. - upper: Convert gt texts into uppercase characters. - lower: Convert gt texts into lowercase characters. Usually, it only works for English characters. Defaults to ‘unchanged’.

  • pad_with (str) –

    The padding strategy for gt_text.padded_indexes. Defaults to ‘auto’. Options are: - ‘auto’: Use dictionary.padding_idx to pad gt texts, or

    dictionary.end_idx if dictionary.padding_idx is None.

    • ’padding’: Always use dictionary.padding_idx to pad gt texts.

    • ’end’: Always use dictionary.end_idx to pad gt texts.

    • ’none’: Do not pad gt texts.

  • ignore_char (int or str) – Specifies a target value that is ignored and does not contribute to the input gradient. ignore_char can be int or str. If int, it is the index of the ignored char. If str, it is the character to ignore. Apart from single characters, each item can be one of the following reversed keywords: ‘padding’, ‘start’, ‘end’, and ‘unknown’, which refer to their corresponding special tokens in the dictionary. It will not ignore any special tokens when ignore_char == -1 or ‘none’. Defaults to ‘padding’.

  • flatten (bool) – Whether to flatten the output and target before computing CE loss. Defaults to False.

  • reduction (str) – Specifies the reduction to apply to the output, should be one of the following: (‘none’, ‘mean’, ‘sum’). Defaults to ‘none’.

  • ignore_first_char (bool) – Whether to ignore the first token in target ( usually the start token). If True, the last token of the output sequence will also be removed to be aligned with the target length. Defaults to False.

  • flatten – Whether to flatten the vectors for loss computation. Defaults to False.

forward(outputs, data_samples)[源代码]
参数
  • outputs (Tensor) – A raw logit tensor of shape \((N, T, C)\).

  • data_samples (list[TextRecogDataSample]) – List of TextRecogDataSample which are processed by get_target.

返回

A loss dict with the key loss_ce.

返回类型

dict

Read the Docs v: stable
Versions
latest
stable
0.x
dev-1.x
Downloads
pdf
html
epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.