keras-ocr icon indicating copy to clipboard operation
keras-ocr copied to clipboard

ValueError: could not broadcast input array from shape (2048,1448) into shape (31,200)

Open ivsanro1 opened this issue 5 years ago • 5 comments

I am running this in an Anaconda env (conda 4.7.12) in Windows 10 Enterprise.

I am getting this stacktrace when running pipeline.recognize on one of my images:

2020-05-17 09:43:17.709956: W tensorflow/core/framework/cpu_allocator_impl.cc:81] Allocation of 759169024 exceeds 10% of system memory.
2020-05-17 09:43:18.125906: W tensorflow/core/framework/cpu_allocator_impl.cc:81] Allocation of 759169024 exceeds 10% of system memory.
Traceback (most recent call last):
  File "c:\Users\my_user\work\my_project\processing\run_example.py", line 109, in <module>
    main()
  File "c:\Users\my_user\work\my_project\processing\run_example.py", line 49, in main
    detection_kwargs=detection_kwargs
  File "c:\Users\my_user\work\my_project\processing\data_extraction.py", line 518, in extract_bbs_text_dir_files
    df, prediction_group = get_df_from_labeled_img(path_img, path_json, detection_kwargs=detection_kwargs)
  File "c:\Users\my_user\work\my_project\processing\data_extraction.py", line 215, in get_df_from_labeled_img
    prediction_groups = pipeline.recognize(images, detection_kwargs=detection_kwargs)
  File "C:\Users\my_user\Anaconda3\envs\my_env\lib\site-packages\keras_ocr\pipeline.py", line 58, in
recognize
    **recognition_kwargs)
  File "C:\Users\my_user\Anaconda3\envs\my_env\lib\site-packages\keras_ocr\recognition.py", line 431, in recognize_from_boxes
    target_width=self.model.input_shape[2]))
  File "C:\Users\my_user\Anaconda3\envs\my_env\lib\site-packages\keras_ocr\tools.py", line 97, in warpBox
    full[:crop.shape[0], :crop.shape[1]] = crop

ValueError: could not broadcast input array from shape (2048,1448) into shape (31,200)

I have processed more than 100 images, but this is happening in this image.

Unfortunately, I cannot share the image as it has personal data, but I can help to debug the problem, but first I would like to know if this error is from my end or it could be a issue of keras-ocr.

Thanks in advance

ivsanro1 avatar May 17 '20 08:05 ivsanro1

Something is going wrong with the box warping process. Please provide a sample image to reproduce the issue. My apologies for the inconvenience.

faustomorales avatar Jul 30 '20 01:07 faustomorales

Exactly, I had error on this line, too. I ended up wrapping warpBox call into a try: catch block so that execution does not break.

fingoldo avatar Oct 09 '20 06:10 fingoldo

Hi! I have found that if the box width/height is smaller than the supplied margin, this error occurs.

hadils avatar Nov 08 '20 11:11 hadils

I'm using size 640x640 as the example of this repo with the margin 50 and having the same issue, if I try a smaller margin I also get the same problem. Also sometimes there is another problem when an array called slots becomes zero sized (This one has something to do with the contours, but I don't remember well and the error of this issue is happens more often)

LFBJC avatar Dec 02 '21 17:12 LFBJC

now debugging it I found out that this error happens when scalew = 0 or scaleh = 0, because this leads cv2.warpPerspective to generate an image with the same size as the input image instead of the dsize given

LFBJC avatar Dec 02 '21 19:12 LFBJC