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.38k stars 355 forks source link

Colab execution #112

Closed NeighborhoodCoding closed 4 years ago

NeighborhoodCoding commented 4 years ago

I'm using google colab and it errors in training(fit) numpy.AxisError: axis 1 is out of bounds for array of dimension 1 And my colab file link(reproducible) is : https://colab.research.google.com/drive/1AmQzQiHghCi_Lnxf3hcZKUsuewtPMRlg?usp=sharing

It errors while fit the detector or generator randomly in colab(about 0.3% possibility in 1 epoch) maybe it is a version error of Tensorflow? I searched and it is related in the input format is not np.array....(?) If I reduce the epoch, it works entirely... but I want to train a large epoch... and I want to ask about this random error If reproducible in my sharable colab link...

thank you.

detector.model.fit_generator(
    generator=detection_train_generator,
    #steps_per_epoch=math.ceil(len(background_splits[0]) / detector_batch_size),
    steps_per_epoch=1000,
    epochs=5,
    workers=0,
    callbacks=[
        tf.keras.callbacks.EarlyStopping(restore_best_weights=True, patience=5),
        tf.keras.callbacks.CSVLogger(f'{detector_basepath}.csv'),
        tf.keras.callbacks.ModelCheckpoint(filepath=f'{detector_basepath}.h5')
    ],
    validation_data=detection_val_generator,
    #validation_steps=math.ceil(len(background_splits[1]) / detector_batch_size)
    validation_steps=100
)

and

 318/1000 [========>.....................] - ETA: 16:05 - loss: 0.0054
---------------------------------------------------------------------------
InvalidArgumentError                      Traceback (most recent call last)
<ipython-input-13-4e1d29ce0729> in <module>()
     13     validation_data=detection_val_generator,
     14     #validation_steps=math.ceil(len(background_splits[1]) / detector_batch_size)
---> 15     validation_steps=100
     16 )

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:

InvalidArgumentError: 2 root error(s) found.
  (0) Invalid argument:  AxisError: axis 1 is out of bounds for array of dimension 1
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/detection.py", line 631, in get_batch_generator
    batch = [next(image_generator) for n in range(batch_size)]

  File "/usr/local/lib/python3.6/dist-packages/keras_ocr/detection.py", line 631, in <listcomp>
    batch = [next(image_generator) for n in range(batch_size)]

  File "/usr/local/lib/python3.6/dist-packages/keras_ocr/data_generation.py", line 577, in get_image_generator
    draw_contour=draw_contour_text)

  File "/usr/local/lib/python3.6/dist-packages/keras_ocr/data_generation.py", line 351, in draw_text_image
    min_character_size = character_sizes.sum(axis=1).min()

  File "/usr/local/lib/python3.6/dist-packages/numpy/core/_methods.py", line 38, in _sum
    return umr_sum(a, axis, dtype, out, keepdims, initial, where)

numpy.AxisError: axis 1 is out of bounds for array of dimension 1

     [[{{node PyFunc}}]]
     [[IteratorGetNext]]
  (1) Invalid argument:  AxisError: axis 1 is out of bounds for array of dimension 1
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/detection.py", line 631, in get_batch_generator
    batch = [next(image_generator) for n in range(batch_size)]

  File "/usr/local/lib/python3.6/dist-packages/keras_ocr/detection.py", line 631, in <listcomp>
    batch = [next(image_generator) for n in range(batch_size)]

  File "/usr/local/lib/python3.6/dist-packages/keras_ocr/data_generation.py", line 577, in get_image_generator
    draw_contour=draw_contour_text)

  File "/usr/local/lib/python3.6/dist-packages/keras_ocr/data_generation.py", line 351, in draw_text_image
    min_character_size = character_sizes.sum(axis=1).min()

  File "/usr/local/lib/python3.6/dist-packages/numpy/core/_methods.py", line 38, in _sum
    return umr_sum(a, axis, dtype, out, keepdims, initial, where)

numpy.AxisError: axis 1 is out of bounds for array of dimension 1

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

Function call stack:
train_function -> train_function