-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Comments
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 |
I also encountered the 'Illegal instruction' issue. The error message and my system information are as follows:
|
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. |
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)
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)
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?
The text was updated successfully, but these errors were encountered: