compute_loss error get NoneType #54

Closed
opened 2025-10-14 15:52:09 -06:00 by navan · 0 comments
Owner

Originally created by @jwijffels on 8/13/2020

Note to possible users of PyLaia.
If you encounter this error, it is highly likely due to your text contains extra characters which are not specified in your syms_ctc.txt file

2020-08-13 08:24:04,191 INFO laia.common.arguments : 
{'add_logsoftmax_to_loss': True,
 'batch_size': 10,
 'checkpoint': 'ckpt.lowest-valid-cer*',
 'delimiters': ['@'],
 'gpu': 1,
 'img_dirs': ['/content/getuigenissen/imgs/textlines_h128'],
 'iterations_per_update': 1,
 'learning_rate': 0.0003,
 'logging_also_to_stderr': 20,
 'logging_config': None,
 'logging_file': '/content/getuigenissen/log/training-trace.log',
 'logging_level': 20,
 'logging_overwrite': False,
 'max_epochs': None,
 'max_nondecreasing_epochs': 20,
 'model_filename': 'model',
 'momentum': 0,
 'num_rolling_checkpoints': 3,
 'print_args': True,
 'save_checkpoint_interval': 10,
 'seed': 74565,
 'show_progress_bar': True,
 'syms': <_io.TextIOWrapper name='/content/getuigenissen/imgs/syms_ctc.txt' mode='r' encoding='UTF-8'>,
 'tr_txt_table': <_io.TextIOWrapper name='/content/getuigenissen/imgs/tr.txt' mode='r' encoding='UTF-8'>,
 'train_path': '/content/getuigenissen',
 'train_samples_per_epoch': None,
 'use_baidu_ctc': False,
 'use_distortions': False,
 'va_txt_table': <_io.TextIOWrapper name='/content/getuigenissen/imgs/va.txt' mode='r' encoding='UTF-8'>,
 'valid_samples_per_epoch': None}
2020-08-13 08:24:04,297 INFO laia.common.loader : Loaded model /content/getuigenissen/model
2020-08-13 08:24:12,390 INFO laia : Training data transforms:
Compose(
    vision.Convert(mode=L)
    vision.Invert()
    ToTensor()
)
Train:  24% 114/485 [01:58<06:24,  1.04s/it]
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/laia-0.1.0-py3.8.egg/laia/engine/engine.py", line 232, in exception_catcher
    yield
  File "/usr/local/lib/python3.8/dist-packages/laia-0.1.0-py3.8.egg/laia/engine/trainer.py", line 222, in compute_loss
    loss = self._criterion(batch_output, batch_target, **kwargs)
  File "/usr/local/lib/python3.8/dist-packages/torch/nn/modules/module.py", line 722, in _call_impl
    result = self.forward(*input, **kwargs)
  File "/usr/local/lib/python3.8/dist-packages/laia-0.1.0-py3.8.egg/laia/losses/ctc_loss.py", line 340, in forward
    acts, labels, act_lens, label_lens = CTCPrepare.apply(
  File "/usr/local/lib/python3.8/dist-packages/laia-0.1.0-py3.8.egg/laia/losses/ctc_loss.py", line 140, in forward
    labels = torch.tensor(
TypeError: an integer is required (got type NoneType)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/bin/pylaia-htr-train-ctc", line 4, in <module>
    __import__('pkg_resources').run_script('laia==0.1.0', 'pylaia-htr-train-ctc')
  File "/usr/local/lib/python3.8/dist-packages/pkg_resources/__init__.py", line 665, in run_script
    self.require(requires)[0].run_script(script_name, ns)
  File "/usr/local/lib/python3.8/dist-packages/pkg_resources/__init__.py", line 1463, in run_script
    exec(code, namespace, namespace)
  File "/usr/local/lib/python3.8/dist-packages/laia-0.1.0-py3.8.egg/EGG-INFO/scripts/pylaia-htr-train-ctc", line 279, in <module>
    experiment.run()
  File "/usr/local/lib/python3.8/dist-packages/laia-0.1.0-py3.8.egg/laia/experiments/experiment.py", line 76, in run
    self._tr_engine.run()
  File "/usr/local/lib/python3.8/dist-packages/laia-0.1.0-py3.8.egg/laia/hooks/action.py", line 29, in wrapper
    return func(
  File "/usr/local/lib/python3.8/dist-packages/laia-0.1.0-py3.8.egg/laia/engine/trainer.py", line 126, in run
    self._run_epoch()
  File "/usr/local/lib/python3.8/dist-packages/laia-0.1.0-py3.8.egg/laia/engine/engine.py", line 224, in _run_epoch
    self._run_iteration(it, batch)
  File "/usr/local/lib/python3.8/dist-packages/laia-0.1.0-py3.8.egg/laia/engine/trainer.py", line 180, in _run_iteration
    batch_loss = self.compute_loss(batch, batch_output, batch_target)
  File "/usr/local/lib/python3.8/dist-packages/laia-0.1.0-py3.8.egg/laia/engine/trainer.py", line 228, in compute_loss
    return loss
  File "/usr/lib/python3.8/contextlib.py", line 131, in __exit__
    self.gen.throw(type, value, traceback)
  File "/usr/local/lib/python3.8/dist-packages/laia-0.1.0-py3.8.egg/laia/engine/engine.py", line 240, in exception_catcher
    raise_from(wrapper, e)
  File "/usr/local/lib/python3.8/dist-packages/torch/_six.py", line 53, in raise_from
    raise value from from_value
laia.engine.engine_exception.EngineException: Exception "TypeError('an integer is required (got type NoneType)')" raised during epoch 0, iteration 114. The batch that caused the exception was: ['32505198-73', '32505199-31', '32500853-08', '32501271-05', '32505219-03', '32505217-04', '32505165-26', '32500973-14', '32500665-39', '32505171-19']
/
/
/
*Originally created by @jwijffels on 8/13/2020* Note to possible users of PyLaia. If you encounter this error, it is highly likely due to your text contains extra characters which are not specified in your syms_ctc.txt file ``` 2020-08-13 08:24:04,191 INFO laia.common.arguments : {'add_logsoftmax_to_loss': True, 'batch_size': 10, 'checkpoint': 'ckpt.lowest-valid-cer*', 'delimiters': ['@'], 'gpu': 1, 'img_dirs': ['/content/getuigenissen/imgs/textlines_h128'], 'iterations_per_update': 1, 'learning_rate': 0.0003, 'logging_also_to_stderr': 20, 'logging_config': None, 'logging_file': '/content/getuigenissen/log/training-trace.log', 'logging_level': 20, 'logging_overwrite': False, 'max_epochs': None, 'max_nondecreasing_epochs': 20, 'model_filename': 'model', 'momentum': 0, 'num_rolling_checkpoints': 3, 'print_args': True, 'save_checkpoint_interval': 10, 'seed': 74565, 'show_progress_bar': True, 'syms': <_io.TextIOWrapper name='/content/getuigenissen/imgs/syms_ctc.txt' mode='r' encoding='UTF-8'>, 'tr_txt_table': <_io.TextIOWrapper name='/content/getuigenissen/imgs/tr.txt' mode='r' encoding='UTF-8'>, 'train_path': '/content/getuigenissen', 'train_samples_per_epoch': None, 'use_baidu_ctc': False, 'use_distortions': False, 'va_txt_table': <_io.TextIOWrapper name='/content/getuigenissen/imgs/va.txt' mode='r' encoding='UTF-8'>, 'valid_samples_per_epoch': None} 2020-08-13 08:24:04,297 INFO laia.common.loader : Loaded model /content/getuigenissen/model 2020-08-13 08:24:12,390 INFO laia : Training data transforms: Compose( vision.Convert(mode=L) vision.Invert() ToTensor() ) Train: 24% 114/485 [01:58<06:24, 1.04s/it] Traceback (most recent call last): File "/usr/local/lib/python3.8/dist-packages/laia-0.1.0-py3.8.egg/laia/engine/engine.py", line 232, in exception_catcher yield File "/usr/local/lib/python3.8/dist-packages/laia-0.1.0-py3.8.egg/laia/engine/trainer.py", line 222, in compute_loss loss = self._criterion(batch_output, batch_target, **kwargs) File "/usr/local/lib/python3.8/dist-packages/torch/nn/modules/module.py", line 722, in _call_impl result = self.forward(*input, **kwargs) File "/usr/local/lib/python3.8/dist-packages/laia-0.1.0-py3.8.egg/laia/losses/ctc_loss.py", line 340, in forward acts, labels, act_lens, label_lens = CTCPrepare.apply( File "/usr/local/lib/python3.8/dist-packages/laia-0.1.0-py3.8.egg/laia/losses/ctc_loss.py", line 140, in forward labels = torch.tensor( TypeError: an integer is required (got type NoneType) The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/usr/local/bin/pylaia-htr-train-ctc", line 4, in <module> __import__('pkg_resources').run_script('laia==0.1.0', 'pylaia-htr-train-ctc') File "/usr/local/lib/python3.8/dist-packages/pkg_resources/__init__.py", line 665, in run_script self.require(requires)[0].run_script(script_name, ns) File "/usr/local/lib/python3.8/dist-packages/pkg_resources/__init__.py", line 1463, in run_script exec(code, namespace, namespace) File "/usr/local/lib/python3.8/dist-packages/laia-0.1.0-py3.8.egg/EGG-INFO/scripts/pylaia-htr-train-ctc", line 279, in <module> experiment.run() File "/usr/local/lib/python3.8/dist-packages/laia-0.1.0-py3.8.egg/laia/experiments/experiment.py", line 76, in run self._tr_engine.run() File "/usr/local/lib/python3.8/dist-packages/laia-0.1.0-py3.8.egg/laia/hooks/action.py", line 29, in wrapper return func( File "/usr/local/lib/python3.8/dist-packages/laia-0.1.0-py3.8.egg/laia/engine/trainer.py", line 126, in run self._run_epoch() File "/usr/local/lib/python3.8/dist-packages/laia-0.1.0-py3.8.egg/laia/engine/engine.py", line 224, in _run_epoch self._run_iteration(it, batch) File "/usr/local/lib/python3.8/dist-packages/laia-0.1.0-py3.8.egg/laia/engine/trainer.py", line 180, in _run_iteration batch_loss = self.compute_loss(batch, batch_output, batch_target) File "/usr/local/lib/python3.8/dist-packages/laia-0.1.0-py3.8.egg/laia/engine/trainer.py", line 228, in compute_loss return loss File "/usr/lib/python3.8/contextlib.py", line 131, in __exit__ self.gen.throw(type, value, traceback) File "/usr/local/lib/python3.8/dist-packages/laia-0.1.0-py3.8.egg/laia/engine/engine.py", line 240, in exception_catcher raise_from(wrapper, e) File "/usr/local/lib/python3.8/dist-packages/torch/_six.py", line 53, in raise_from raise value from from_value laia.engine.engine_exception.EngineException: Exception "TypeError('an integer is required (got type NoneType)')" raised during epoch 0, iteration 114. The batch that caused the exception was: ['32505198-73', '32505199-31', '32500853-08', '32501271-05', '32505219-03', '32505217-04', '32505165-26', '32500973-14', '32500665-39', '32505171-19'] / / / ```
navan closed this issue 2025-10-14 15:52:09 -06:00
Sign in to join this conversation.
No labels
dependencies
stale
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github/PyLaia#54
No description provided.