EasyOCR icon indicating copy to clipboard operation
EasyOCR copied to clipboard

EasyOCR is not giving output and exiting before printing anything and also no error on console!!!!

Open Ctmax-ui opened this issue 11 months ago • 14 comments

When i run the code it just exiting halfway there not even giving output, please help me

my system config:

  • Python 3.12.8
  • windows 10
  • i5 3gen
  • 8gb ram
  • 730 NVidia gpu
  • 256 SSD

project structure: image

input images: d image

code:

import torch
import easyocr
import cv2

print(f"PyTorch version: {torch.__version__}")
print(f"EasyOCR version: {easyocr.__version__}")
print(f"OpenCV version: {cv2.__version__}")

try:
    reader = easyocr.Reader(['en'])
    result = reader.readtext('input/d.png')
    print(result)
    result = reader.readtext('input/image.jpg')
    print(f"OCR Result: {result}")
except Exception as e:
    print(f"An error occurred: {e}")

output:

PS C:\Users\user\Desktop\my-projects\random-stuff\python-image-translator> python .\testocr.py
PyTorch version: 2.5.1+cpu
EasyOCR version: 1.7.2
OpenCV version: 4.10.0
Neither CUDA nor MPS are available - defaulting to CPU. Note: This module is much faster with a GPU.
PS C:\Users\user\Desktop\my-projects\random-stuff\python-image-translator> 
PS C:\Users\user\Desktop\my-projects\random-stuff\python-image-translator> python .\testocr.py
PyTorch version: 2.5.1+cpu
EasyOCR version: 1.7.2
OpenCV version: 4.10.0
Neither CUDA nor MPS are available - defaulting to CPU. Note: This module is much faster with a GPU.
PS C:\Users\user\Desktop\my-projects\random-stuff\python-image-translator> 

Ctmax-ui avatar Jan 09 '25 16:01 Ctmax-ui

yes same issue with me, the code works fine on Colab with CPU setting but not on laptop

Maryam483 avatar Jan 14 '25 19:01 Maryam483

yes same issue with me, the code works fine on Colab with CPU setting but not on laptop

and the worst part is, not giving any error !!!

Ctmax-ui avatar Jan 15 '25 04:01 Ctmax-ui

then how we solve this issue ?? there is no help on internet

Maryam483 avatar Jan 15 '25 06:01 Maryam483

then how we solve this issue ?? there is no help on internet

No idea, maybe you could try to reinstall your os.

Ctmax-ui avatar Jan 15 '25 06:01 Ctmax-ui

I'm not sure if it's related to this issue, but in my environment I've encountered a situation where it seems to hang inside reader.readtext. It appears to work with PyTorch 2.2.0, but there have been cases where it doesn't work properly with PyTorch 2.2.1, 2.2.2, and 2.3.0.

ssotobayashi-m avatar Feb 25 '25 04:02 ssotobayashi-m

with PyTorch 2.2.0, but there have been cases where it doesn't work properly w

please do tell us if you fix the issue.

Ctmax-ui avatar Feb 25 '25 05:02 Ctmax-ui

FYI, in my case, it appeared to hang when calling toTensor in NormalizePAD. https://github.com/JaidedAI/EasyOCR/blob/master/easyocr/recognition.py#L39

However, it doesn't always happen, and since the issue occurred with a certain PIL Image that didn't seem particularly problematic, I still don't really know the cause at this point.

ssotobayashi-m avatar Feb 25 '25 09:02 ssotobayashi-m

First and foremost, it appears to run without any issues on Linux.

I was testing in an Apple M1 environment, and I observed the following behavior as far as my usage was concerned; The Python version did not seem to have a significant impact, so I will omit it for now (I actually conducted experiments using Python 3.9, 3.11, and 3.12.). Additionally, in my environment, the specific points where the program freezes seemed to vary slightly depending on the input data.

Does it depend on the OS version?

Ventura (13.5.2) Sequoia (15.3.1)
PyTorch 2.2.0 OK OK
PyTorch 2.3.0 NG NG

Looking at these results, the OS version does not seem to be a major factor.

Is there a potential issue with the CPU?

Next, I conducted an experiment using Docker to run aarch64 Debian "bullseye" on Sequoia (15.3.1) + M1.

Debian “bullseye” on Sequoia (15.3.1) + M1
PyTorch 2.3.0 OK

Based on this result, the fact that the CPU is M1 also does not seem to be a determining factor.

While the cause remains unknown, in environments where the issue occurs, one possible workaround could be to use Docker or WSL2 on Windows, or Docker on Mac, to create a Linux environment and run EasyOCR within it.

ssotobayashi-m avatar Feb 27 '25 05:02 ssotobayashi-m

ok thanks for the info, lets see if i can run in docker, can you provide the docker file

Ctmax-ui avatar Feb 27 '25 13:02 Ctmax-ui

I will include the Dockerfile that I had ChatGPT generate based on what I needed and then manually refined it. I started the docker container, installed additional necessary libraries inside it, and tested an application including EasyOCR. The reason I am using Python 3.11 instead of the latest version is that, in addition to EasyOCR, I am also using an other library that is not yet compatible with Python 3.12.

FROM python:3.11.11-bullseye

ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update && apt-get install -y \
    git \
    build-essential

RUN python -m pip install --upgrade pip

WORKDIR /work

RUN python -m venv /venv

ENV PATH="/venv/bin:$PATH"

RUN /venv/bin/pip install -U pip matplotlib jupyter jupyterlab

COPY jupyter_lab_config.py /root/.jupyter/

CMD ["python"]

ssotobayashi-m avatar Feb 28 '25 01:02 ssotobayashi-m

I came across some interesting information that might be worth trying. Instead of running python something.py, we just run OMP_NUM_THREADS=1 python something.py (If you use jupyter, run OMP_NUM_THREADS=1 jupyter in the same way). This idea comes from https://github.com/microsoft/LightGBM/issues/6595#issuecomment-2315978807 (also https://github.com/pytorch/pytorch/issues/121101).

In my case, I have been experiencing hang-ups when using a combination of EasyOCR and my custom libraries (using PyTorch >= 2.2.1 with Python 3.11, but maybe >= 2.2.0? with Python 3.12). However, it seems to be resolved by setting OMP_NUM_THREADS=1. I haven't conducted an exhaustive investigation, but anyway it has clearly improved the situation for me.

ssotobayashi-m avatar Apr 01 '25 05:04 ssotobayashi-m

Thanks bro

Ctmax-ui avatar Apr 01 '25 11:04 Ctmax-ui

hey guys - did anyone fixes that issue?

dghoffra avatar Apr 14 '25 13:04 dghoffra

hey guys - did anyone fixes that issue?

Dunno bro.....

Ctmax-ui avatar Apr 15 '25 01:04 Ctmax-ui