faustomorales / keras-ocr

A packaged and flexible version of the CRAFT text detector and Keras CRNN recognition model.
https://keras-ocr.readthedocs.io/
MIT License
1.41k stars 365 forks source link

ZeroDivisionError: division by zero #115

Open NeighborhoodCoding opened 4 years ago

NeighborhoodCoding commented 4 years ago

Hi, I'm following your tutorial https://keras-ocr.readthedocs.io/en/latest/examples/end_to_end_training.html and my step is training the recognizer with no Pre-trained weight. Also I changed recognizer alphabet to non latin characters

However, In the recognizer train step, I got a ZeroDivisionError: division by zero. I think... Train image generator? has no label or no image? If you please, for other non-latin trainers of the future, can you explain what is this error?? Thanks in advance.

104/104 [==============================] - 461s 4s/step - loss: 22.7555 - val_loss: 20.7057
Epoch 2/1000
104/104 [==============================] - 451s 4s/step - loss: 20.3573 - val_loss: 21.4699
Epoch 3/1000
104/104 [==============================] - 373s 4s/step - loss: 16.7728 - val_loss: 16.2160
Epoch 4/1000
104/104 [==============================] - 350s 3s/step - loss: 14.6223 - val_loss: 16.1058
Epoch 5/1000
104/104 [==============================] - 369s 4s/step - loss: 13.7717 - val_loss: 13.6269
Epoch 6/1000
104/104 [==============================] - 360s 3s/step - loss: 13.0744 - val_loss: 11.9901
Epoch 7/1000
104/104 [==============================] - 372s 4s/step - loss: 11.6895 - val_loss: 11.6947
Epoch 8/1000
 14/104 [===>..........................] - ETA: 4:01 - loss: 12.2752
---------------------------------------------------------------------------
UnknownError                              Traceback (most recent call last)
<ipython-input-43-1c9e2d89d135> in <module>()
     20     validation_data=recognition_val_generator,
     21     validation_steps=math.ceil(len(background_splits[1])*1 / recognition_batch_size),
---> 22     workers=0
     23 )

10 frames
/usr/local/lib/python3.6/dist-packages/tensorflow/python/eager/execute.py in quick_execute(op_name, num_outputs, inputs, attrs, ctx, name)
     58     ctx.ensure_initialized()
     59     tensors = pywrap_tfe.TFE_Py_Execute(ctx._handle, device_name, op_name,
---> 60                                         inputs, attrs, num_outputs)
     61   except core._NotOkStatusException as e:
     62     if name is not None:

UnknownError: 2 root error(s) found.
  (0) Unknown:  ZeroDivisionError: division by zero
Traceback (most recent call last):

  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/script_ops.py", line 244, in __call__
    ret = func(*args)

  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/autograph/impl/api.py", line 302, in wrapper
    return func(*args, **kwargs)

  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/data/ops/dataset_ops.py", line 827, in generator_py_func
    values = next(generator_state.get_iterator(iterator_id))

  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/data_adapter.py", line 814, in wrapped_generator
    for data in generator_fn():

  File "/usr/local/lib/python3.6/dist-packages/keras_ocr/recognition.py", line 359, in get_batch_generator
    batch = [sample for sample, _ in zip(image_generator, range(batch_size))]

  File "/usr/local/lib/python3.6/dist-packages/keras_ocr/recognition.py", line 359, in <listcomp>
    batch = [sample for sample, _ in zip(image_generator, range(batch_size))]

  File "/usr/local/lib/python3.6/dist-packages/keras_ocr/data_generation.py", line 272, in convert_image_generator_to_recognizer_input
    skip_rotate=True)

  File "/usr/local/lib/python3.6/dist-packages/keras_ocr/tools.py", line 88, in warpBox
    scale = min(target_width / w, target_height / h)

ZeroDivisionError: division by zero

     [[{{node PyFunc}}]]
     [[IteratorGetNext]]
     [[Shape/_10]]
  (1) Unknown:  ZeroDivisionError: division by zero
Traceback (most recent call last):

  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/script_ops.py", line 244, in __call__
    ret = func(*args)

  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/autograph/impl/api.py", line 302, in wrapper
    return func(*args, **kwargs)

  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/data/ops/dataset_ops.py", line 827, in generator_py_func
    values = next(generator_state.get_iterator(iterator_id))

  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/data_adapter.py", line 814, in wrapped_generator
    for data in generator_fn():

  File "/usr/local/lib/python3.6/dist-packages/keras_ocr/recognition.py", line 359, in get_batch_generator
    batch = [sample for sample, _ in zip(image_generator, range(batch_size))]

  File "/usr/local/lib/python3.6/dist-packages/keras_ocr/recognition.py", line 359, in <listcomp>
    batch = [sample for sample, _ in zip(image_generator, range(batch_size))]

  File "/usr/local/lib/python3.6/dist-packages/keras_ocr/data_generation.py", line 272, in convert_image_generator_to_recognizer_input
    skip_rotate=True)

  File "/usr/local/lib/python3.6/dist-packages/keras_ocr/tools.py", line 88, in warpBox
    scale = min(target_width / w, target_height / h)

ZeroDivisionError: division by zero

     [[{{node PyFunc}}]]
     [[IteratorGetNext]]
0 successful operations.
0 derived errors ignored. [Op:__inference_train_function_17688]

Function call stack:
train_function -> train_function
ahsan44411 commented 4 years ago

Hello. Did you find the solution? I am having the same problem with COCO-text dataset

ezzaimsoufiane commented 3 years ago

@SungmanHong @ahsan44411 im having the same pronlem with COCO Dataset. Found any possible fix?

ezzaimsoufiane commented 3 years ago

try this

if tf.config.list_physical_devices('GPU'):
    physical_devices = tf.config.list_physical_devices('GPU')
    tf.config.experimental.set_memory_growth(physical_devices[0], enable=True)
    tf.config.experimental.set_virtual_device_configuration(physical_devices[0], [tf.config.experimental.VirtualDeviceConfiguration(memory_limit=3072)])