Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Neither CUDA nor MPS are available - defaulting to CPU. Note: This module is much faster with a GPU. Illegal instruction #1323

Open
luisjose1996 opened this issue Oct 17, 2024 · 3 comments

Comments

@luisjose1996
Copy link

import easyocr
import cv2
import matplotlib.pyplot as plt

Create an EasyOCR reader instance

reader = easyocr.Reader(['en'], gpu=False) # Specify the languages you want to use

Function to extract text from an image

def extract_text_from_image(image_path):
# Read the image using OpenCV
image = cv2.imread(image_path)

# Use EasyOCR to extract text
results = reader.readtext(image)

# Extract text and bounding boxes
extracted_text = ""
for (bbox, text, prob) in results:
    extracted_text += f"{text} "
    # Optionally, you can draw bounding boxes on the image
    (top_left, top_right, bottom_right, bottom_left) = bbox
    top_left = tuple(map(int, top_left))
    bottom_right = tuple(map(int, bottom_right))
    cv2.rectangle(image, top_left, bottom_right, (0, 255, 0), 2)

return extracted_text.strip(), image

Example usage

if name == "main":
image_path = "1.png" # Replace with your image path
text, annotated_image = extract_text_from_image(image_path)
print("Extracted Text:", text)

# Display the image with bounding boxes
plt.imshow(cv2.cvtColor(annotated_image, cv2.COLOR_BGR2RGB))
plt.axis('off')  # Hide axes
plt.show()

In this code, I got an issue like "Neither CUDA nor MPS are available - defaulting to CPU. Note: This module is much faster with a GPU. Illegal instruction".
How should I solve this issue?

@romanvelichkin
Copy link

It's not clear what is a problem. Easyocr doesn't scan image, so you don't have image + bbox output? Or image is showed, but you're bothered with a message?

It's a default message if you don't use gpu. You can change gpu=False -> gpu=True to fix it, but you will need GPU for that.

@hankchu6
Copy link

hankchu6 commented Nov 1, 2024

I also encountered the 'Illegal instruction' issue. The error message and my system information are as follows:

>>> reader = easyocr.Reader(['en'], gpu=False, model_storage_directory='models')
>>> img = 'initial_screen.png'
>>> reader.readtext(img)
[W1101 17:08:06.622021815 NNPACK.cpp:61] Could not initialize NNPACK! Reason: Unsupported hardware.
Illegal instruction (core dumped)
ov  1 17:08:06 ct05 kernel: traps: python[2197] trap invalid opcode ip:7ff9b9728a51 sp:7ffcfad76a80 error:0 in libtorch_cpu.so[7ff9b1600000+13dce000]
Nov  1 17:08:06 ct05 systemd[1]: Started Process Core Dump (PID 2211/UID 0).
Nov  1 17:08:13 ct05 systemd-coredump[2212]: Process 2197 (python) of user 0 dumped core.#012#012Module libz.e05c5b49.so.1 without build-id.#012Stack trace of thread 2197:#012#0  0x00007ff9b9728a51 _ZN6fbgemm10FindMinMaxEPKfPfS2_l (libtorch_cpu.so + 0x8128a51)#012#1  0x00007ff9b3a6261f _ZN25PackedLinearWeightsOnednn18apply_dynamic_implILb0EEEN2at6TensorES2_b (libtorch_cpu.so + 0x246261f)#012#2  0x00007ff9b3a599bd _ZN25PackedLinearWeightsOnednn13apply_dynamicEN2at6TensorEb (libtorch_cpu.so + 0x24599bd)#012#3  0x00007ff9b3556740 _ZNK2at6native12_GLOBAL__N_126QuantizedCellParamsDynamic9linear_ihERKNS_6TensorE (libtorch_cpu.so + 0x1f56740)#012#4  0x00007ff9b3569f7a _ZNK2at6native12_GLOBAL__N_122FullBidirectionalLayerISt5tupleIJNS_6TensorES4_EENS1_21QRNNCellParamsWrapperEEclERKS4_RKSt4pairIS5_S5_ERKSA_IS6_S6_E (libtorch_cpu.so + 0x1f69f7a)#012#5  0x00007ff9b356cb34 _ZN2at6nativeL20quantized_lstm_inputERKNS_6TensorEN3c104ListIS1_EENS5_INS4_13intrusive_ptrINS0_12_GLOBAL__N_114CellParamsBaseENS4_6detail34intrusive_target_default_null_typeIS9_EEEEEEbldbbbSt8optionalINS4_10ScalarTypeEEb.constprop.0 (libtorch_cpu.so + 0x1f6cb34)#012#6  0x00007ff9b356d8de _ZN3c104impl31make_boxed_from_unboxed_functorINS0_6detail24WrapFunctionIntoFunctor_INS_26CompileTimeFunctionPointerIFSt5tupleIJN2at6TensorES7_S7_EERKS7_NS_4ListIS7_EENSB_INS_13intrusive_ptrINS6_6native12_GLOBAL__N_114CellParamsBaseENS_6detail34intrusive_target_default_null_typeISG_EEEEEEbldbbbSt8optionalINS_10ScalarTypeEEbEXadL_ZNSE_L20quantized_lstm_inputESA_SC_SL_bldbbbSO_bEEEES8_NS_4guts8typelist8typelistIJSA_SC_SL_bldbbbSO_bEEEEELb0EE4callEPNS_14OperatorKernelERKNS_14OperatorHandleENS_14DispatchKeySetEPSt6vectorINS_6IValueESaIS14_EE (libtorch_cpu.so + 0x1f6d8de)#012#7  0x00007ff9b6c939ab _ZNK3c1014OperatorHandle15redispatchBoxedENS_14DispatchKeySetEPSt6vectorINS_6IValueESaIS3_EE (libtorch_cpu.so + 0x56939ab)#012#8  0x00007ff9b6c91229 _ZN5torch8autogradL39basicAutogradNotImplementedFallbackImplERKN3c1014OperatorHandleENS1_14DispatchKeySetEPSt6vectorINS1_6IValueESaIS7_EE (libtorch_cpu.so + 0x5691229)#012#9  0x00007ff9b316bd48 _ZN3c1011BoxedKernel19make_boxed_functionIXadL_ZN12_GLOBAL__N_117autograd_fallbackERKNS_14OperatorHandleENS_14DispatchKeySetEPSt6vectorINS_6IValueESaIS8_EEEEEEvPNS_14OperatorKernelES5_S6_SB_ (libtorch_cpu.so + 0x1b6bd48)#012#10 0x00007ff9c6cfdd88 _ZNK3c1010Dispatcher9callBoxedERKNS_14OperatorHandleEPSt6vectorINS_6IValueESaIS5_EE (libtorch_python.so + 0xcfdd88)#012#11 0x00007ff9c6a8c796 _ZN5torch3jit24invokeOperatorFromPythonERKSt6vectorISt10shared_ptrINS0_8OperatorEESaIS4_EERKN8pybind114argsERKNS9_6kwargsESt8optionalIN3c1011DispatchKeyEE (libtorch_python.so + 0xa8c796)#012#12 0x00007ff9c6a8caa7 _ZN5torch3jit37_get_operation_for_overload_or_packetERKSt6vectorISt10shared_ptrINS0_8OperatorEESaIS4_EEN3c106SymbolERKN8pybind114argsERKNSB_6kwargsEbSt8optionalINS9_11DispatchKeyEE (libtorch_python.so + 0xa8caa7)#012#13 0x00007ff9c6974fb2 _ZZN8pybind1112cpp_function10initializeIZZN5torch3jit15initJITBindingsEP7_objectENKUlRKSsE215_clES7_EUlRKNS_4argsERKNS_6kwargsEE_NS_6objectEJSB_SE_EJNS_4nameENS_3docEEEEvOT_PFT0_DpT1_EDpRKT2_ENUlRNS_6detail13function_callEE1_4_FUNESW_ (libtorch_python.so + 0x974fb2)#012#14 0x00007ff9c64cf48f _ZN8pybind1112cpp_function10dispatcherEP7_objectS2_S2_ (libtorch_python.so + 0x4cf48f)#012#15 0x00007ff9c8d51c32 cfunction_call (libpython3.9.so.1.0 + 0x151c32)#012#16 0x00007ff9c8d4ff8b PyObject_Call (libpython3.9.so.1.0 + 0x14ff8b)#012#17 0x00007ff9c8d362c7 _PyEval_EvalFrameDefault (libpython3.9.so.1.0 + 0x1362c7)#012#18 0x00007ff9c8d2e9d9 _PyEval_EvalCode (libpython3.9.so.1.0 + 0x12e9d9)#012#19 0x00007ff9c8d41055 _PyFunction_Vectorcall (libpython3.9.so.1.0 + 0x141055)#012#20 0x00007ff9c8d391c5 _PyObject_FastCallDictTstate (libpython3.9.so.1.0 + 0x1391c5)#012#21 0x00007ff9c8d4cce5 _PyObject_Call_Prepend (libpython3.9.so.1.0 + 0x14cce5)#012#22 0x00007ff9c8e1b242 slot_tp_call (libpython3.9.so.1.0 + 0x21b242)#012#23 0x00007ff9c8d39903 _PyObject_MakeTpCall (libpython3.9.so.1.0 + 0x139903)#012#24 0x00007ff9c8d35984 _PyEval_EvalFrameDefault (libpython3.9.so.1.0 + 0x135984)#012#25 0x00007ff9c8d4134b function_code_fastcall (libpython3.9.so.1.0 + 0x14134b)#012#26 0x00007ff9c8d4f643 method_vectorcall (libpython3.9.so.1.0 + 0x14f643)#012#27 0x00007ff9c8d351eb _PyEval_EvalFrameDefault (libpython3.9.so.1.0 + 0x1351eb)#012#28 0x00007ff9c8d2e9d9 _PyEval_EvalCode (libpython3.9.so.1.0 + 0x12e9d9)#012#29 0x00007ff9c8d4f6e5 method_vectorcall (libpython3.9.so.1.0 + 0x14f6e5)#012#30 0x00007ff9c8d351eb _PyEval_EvalFrameDefault (libpython3.9.so.1.0 + 0x1351eb)#012#31 0x00007ff9c8d2e9d9 _PyEval_EvalCode (libpython3.9.so.1.0 + 0x12e9d9)#012#32 0x00007ff9c8d41055 _PyFunction_Vectorcall (libpython3.9.so.1.0 + 0x141055)#012#33 0x00007ff9c8d4f7c5 method_vectorcall (libpython3.9.so.1.0 + 0x14f7c5)#012#34 0x00007ff9c8d332a9 _PyEval_EvalFrameDefault (libpython3.9.so.1.0 + 0x1332a9)#012#35 0x00007ff9c8d2e9d9 _PyEval_EvalCode (libpython3.9.so.1.0 + 0x12e9d9)#012#36 0x00007ff9c8d41055 _PyFunction_Vectorcall (libpython3.9.so.1.0 + 0x141055)#012#37 0x00007ff9c8d4f7c5 method_vectorcall (libpython3.9.so.1.0 + 0x14f7c5)#012#38 0x00007ff9c8d332a9 _PyEval_EvalFrameDefault (libpython3.9.so.1.0 + 0x1332a9)#012#39 0x00007ff9c8d2e9d9 _PyEval_EvalCode (libpython3.9.so.1.0 + 0x12e9d9)#012#40 0x00007ff9c8d3915e _PyObject_FastCallDictTstate (libpython3.9.so.1.0 + 0x13915e)#012#41 0x00007ff9c8d4cc6c _PyObject_Call_Prepend (libpython3.9.so.1.0 + 0x14cc6c)#012#42 0x00007ff9c8e1b242 slot_tp_call (libpython3.9.so.1.0 + 0x21b242)#012#43 0x00007ff9c8d39903 _PyObject_MakeTpCall (libpython3.9.so.1.0 + 0x139903)#012#44 0x00007ff9c8d3580e _PyEval_EvalFrameDefault (libpython3.9.so.1.0 + 0x13580e)#012#45 0x00007ff9c8d4134b function_code_fastcall (libpython3.9.so.1.0 + 0x14134b)#012#46 0x00007ff9c8d4f7c5 method_vectorcall (libpython3.9.so.1.0 + 0x14f7c5)#012#47 0x00007ff9c8d332a9 _PyEval_EvalFrameDefault (libpython3.9.so.1.0 + 0x1332a9)#012#48 0x00007ff9c8d2e9d9 _PyEval_EvalCode (libpython3.9.so.1.0 + 0x12e9d9)#012#49 0x00007ff9c8d41055 _PyFunction_Vectorcall (libpython3.9.so.1.0 + 0x141055)#012#50 0x00007ff9c8d4f7c5 method_vectorcall (libpython3.9.so.1.0 + 0x14f7c5)#012#51 0x00007ff9c8d332a9 _PyEval_EvalFrameDefault (libpython3.9.so.1.0 + 0x1332a9)#012#52 0x00007ff9c8d2e9d9 _PyEval_EvalCode (libpython3.9.so.1.0 + 0x12e9d9)#012#53 0x00007ff9c8d3915e _PyObject_FastCallDictTstate (libpython3.9.so.1.0 + 0x13915e)#012#54 0x00007ff9c8d4cc6c _PyObject_Call_Prepend (libpython3.9.so.1.0 + 0x14cc6c)#012#55 0x00007ff9c8e1b242 slot_tp_call (libpython3.9.so.1.0 + 0x21b242)#012#56 0x00007ff9c8d39903 _PyObject_MakeTpCall (libpython3.9.so.1.0 + 0x139903)#012#57 0x00007ff9c8d3516c _PyEval_EvalFrameDefault (libpython3.9.so.1.0 + 0x13516c)#012#58 0x00007ff9c8d4134b function_code_fastcall (libpython3.9.so.1.0 + 0x14134b)#012#59 0x00007ff9c8d4f7c5 method_vectorcall (libpython3.9.so.1.0 + 0x14f7c5)#012#60 0x00007ff9c8d332a9 _PyEval_EvalFrameDefault (libpython3.9.so.1.0 + 0x1332a9)#012#61 0x00007ff9c8d2e9d9 _PyEval_EvalCode (libpython3.9.so.1.0 + 0x12e9d9)#012#62 0x00007ff9c8d41055 _PyFunction_Vectorcall (libpython3.9.so.1.0 + 0x141055)#012#63 0x00007ff9c8d4f7c5 method_vectorcall (libpython3.9.so.1.0 + 0x14f7c5)#012#012Stack trace of thread 2203:#012#0  0x00007ff9c888691a __futex_abstimed_wait_common (libc.so.6 + 0x8691a)#012#1  0x00007ff9c8889120 pthread_cond_wait@@GLIBC_2.3.2 (libc.so.6 + 0x89120)#012#2  0x00007ff98e35009b blas_thread_server (libopenblasp-r0-01191904.3.27.so + 0x35009b)#012#3  0x00007ff9c8889d82 start_thread (libc.so.6 + 0x89d82)#012#4  0x00007ff9c890ee20 __clone3 (libc.so.6 + 0x10ee20)#012#012Stack trace of thread 2204:#012#0  0x00007ff9c888691a __futex_abstimed_wait_common (libc.so.6 + 0x8691a)#012#1  0x00007ff9c8889120 pthread_cond_wait@@GLIBC_2.3.2 (libc.so.6 + 0x89120)#012#2  0x00007ff98e35009b blas_thread_server (libopenblasp-r0-01191904.3.27.so + 0x35009b)#012#3  0x00007ff9c8889d82 start_thread (libc.so.6 + 0x89d82)#012#4  0x00007ff9c890ee20 __clone3 (libc.so.6 + 0x10ee20)#012#012Stack trace of thread 2205:#012#0  0x00007ff9c7418b21 n/a (libgomp-a34b3233.so.1 + 0x18
Nov  1 17:08:13 ct05 systemd[1]: [email protected]: Deactivated successfully.
Nov  1 17:08:13 ct05 systemd[1]: [email protected]: Consumed 5.035s CPU time.
easyocr                  1.7.1

processor       : 0
vendor_id       : GenuineIntel
cpu family      : 6
model           : 191
model name      : Intel(R) Core(TM) i5-14500
stepping        : 2
microcode       : 0xffffffff
cpu MHz         : 2611.200
cache size      : 24576 KB
physical id     : 0
siblings        : 4
core id         : 0
cpu cores       : 4
apicid          : 0
initial apicid  : 0
fpu             : yes
fpu_exception   : yes
cpuid level     : 22
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx rdtscp lm constant_tsc rep_good nopl xtopology nonstop_tsc cpuid tsc_known_freq pni pclmulqdq ssse3 cx16 sse4_1 sse4_2 movbe popcnt aes rdrand hypervisor lahf_lm abm 3dnowprefetch ibrs_enhanced fsgsbase bmi1 bmi2 invpcid rdseed clflushopt arat md_clear flush_l1d arch_capabilities
bugs            : spectre_v1 spectre_v2 spec_store_bypass swapgs retbleed eibrs_pbrsb rfds bhi
bogomips        : 5222.40
clflush size    : 64
cache_alignment : 64
address sizes   : 46 bits physical, 48 bits virtual

@kulikala
Copy link

kulikala commented Nov 6, 2024

Hi there! I’ve successfully configured this module to run on the CPU only. Below is a working Dockerfile setup:

FROM python:3.8-slim AS compile-image

# if you forked EasyOCR, you can pass in your own GitHub username to use your fork
# i.e. GH_USERNAME=myname
ARG GH_USERNAME="JaidedAI"
ARG GH_VERSION="v1.7.1"
ARG PIP_PILLOW="9.3.0"
ARG PIP_TORCH="1.12.1"
ARG PIP_TORCHVISION="0.13.1"
ARG MODEL_HOME="/root/.EasyOCR/model"
ARG SERVICE_HOME="/home/EasyOCR"
ARG LANG_MODELS="pre-v1.1.6/craft_mlt_25k,v1.3/english_g2"

# Configure apt and install packages
RUN apt-get update -y \
    && apt-get install -y \
        git \
        curl \
        unzip \
    # cleanup
    && apt-get autoremove -y \
    && apt-get clean -y \
    && rm -rf /var/lib/apt/lists

# Download models
RUN mkdir -p "${MODEL_HOME}" \
    && cd "${MODEL_HOME}" \
    && IFS=',' L_ARR="${LANG_MODELS}" \
    && for l in ${L_ARR}; do \
        curl -L -O "https://github.com/JaidedAI/EasyOCR/releases/download/${l}.zip" \
        ; done \
    && unzip '*.zip'

# Clone EasyOCR repo
RUN mkdir "${SERVICE_HOME}" \
    && git clone "https://github.com/${GH_USERNAME}/EasyOCR.git" "${SERVICE_HOME}" \
    && cd "${SERVICE_HOME}" \
    && git remote add upstream "https://github.com/JaidedAI/EasyOCR.git" \
    && git fetch upstream tag "${GH_VERSION}" \
    && git checkout tags/"${GH_VERSION}"

# Update pip
RUN cd "${SERVICE_HOME}" \
    && python -m pip install \
        --upgrade \
        pip

# Install torch/torchvision
RUN cd "${SERVICE_HOME}" \
    && python -m pip install \
        --index-url https://download.pytorch.org/whl/cpu \
        --use-deprecated=legacy-resolver \
        Pillow=="${PIP_PILLOW}" \
        torch=="${PIP_TORCH}" \
        torchvision=="${PIP_TORCHVISION}"

# Build
RUN cd "${SERVICE_HOME}" \
    && python setup.py build_ext --inplace -j $(nproc) \
    && python -m pip install -e .

########

FROM python:3.8-slim AS production-image

ARG MODEL_HOME="/root/.EasyOCR/model"
ARG SERVICE_HOME="/home/EasyOCR"
ARG PIP_LOCATION="/usr/local/lib/python3.8/site-packages"

# Copy models
COPY --from=compile-image "${MODEL_HOME}" "${MODEL_HOME}"

# Copy home
COPY --from=compile-image "${SERVICE_HOME}" "${SERVICE_HOME}"

# Copy site packages
COPY --from=compile-image "${PIP_LOCATION}" "${PIP_LOCATION}"

# Copy executables
COPY --from=compile-image /usr/local/bin /usr/local/bin

Please note that changing versions may lead to build or runtime failures.
Hope this is helpful!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants