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

[Bug] mmocr not working on mac anymore (MacBook M3 chip) #2045

Open
2 tasks done
R4Ajeti opened this issue May 14, 2024 · 2 comments
Open
2 tasks done

[Bug] mmocr not working on mac anymore (MacBook M3 chip) #2045

R4Ajeti opened this issue May 14, 2024 · 2 comments
Assignees

Comments

@R4Ajeti
Copy link

R4Ajeti commented May 14, 2024

Prerequisite

Task

I'm using the official example scripts/configs for the officially supported tasks/models/datasets.

Branch

main branch https://github.com/open-mmlab/mmocr

Environment

python mmocr/utils/collect_env.py
sys.platform: darwin
Python: 3.12.1 (main, Apr 10 2024, 22:20:38) [Clang 15.0.0 (clang-1500.3.9.4)]
CUDA available: False
MUSA available: False
numpy_random_seed: 2147483648
GCC: Apple clang version 15.0.0 (clang-1500.3.9.4)
PyTorch: 2.2.2
PyTorch compiling details: PyTorch built with:

  • GCC 4.2
  • C++ Version: 201703
  • clang 14.0.3
  • OpenMP 201811
  • LAPACK is enabled (usually provided by MKL)
  • NNPACK is enabled
  • CPU capability usage: NO AVX
  • Build settings: BLAS_INFO=accelerate, BUILD_TYPE=Release, CXX_COMPILER=/Applications/Xcode_14.3.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++, CXX_FLAGS= -fvisibility-inlines-hidden -DUSE_PTHREADPOOL -DNDEBUG -DUSE_KINETO -DLIBKINETO_NOCUPTI -DLIBKINETO_NOROCTRACER -DUSE_PYTORCH_QNNPACK -DUSE_XNNPACK -DUSE_PYTORCH_METAL_EXPORT -DSYMBOLICATE_MOBILE_DEBUG_HANDLE -DUSE_COREML_DELEGATE -O2 -fPIC -Wall -Wextra -Werror=return-type -Werror=non-virtual-dtor -Werror=braced-scalar-init -Werror=range-loop-construct -Werror=bool-operation -Wnarrowing -Wno-missing-field-initializers -Wno-type-limits -Wno-array-bounds -Wno-unknown-pragmas -Wno-unused-parameter -Wno-unused-function -Wno-unused-result -Wno-strict-overflow -Wno-strict-aliasing -Wvla-extension -Wsuggest-override -Wnewline-eof -Winconsistent-missing-override -Winconsistent-missing-destructor-override -Wno-pass-failed -Wno-error=pedantic -Wno-error=old-style-cast -Wno-error=inconsistent-missing-override -Wno-error=inconsistent-missing-destructor-override -Wconstant-conversion -Wno-invalid-partial-specialization -Wno-missing-braces -Qunused-arguments -fcolor-diagnostics -faligned-new -Wno-unused-but-set-variable -fno-math-errno -fno-trapping-math -Werror=format -DUSE_MPS -Wno-unused-private-field -Wno-missing-braces, LAPACK_INFO=accelerate, TORCH_VERSION=2.2.2, USE_CUDA=OFF, USE_CUDNN=OFF, USE_EIGEN_FOR_BLAS=ON, USE_EXCEPTION_PTR=1, USE_GFLAGS=OFF, USE_GLOG=OFF, USE_MKL=OFF, USE_MKLDNN=OFF, USE_MPI=OFF, USE_NCCL=OFF, USE_NNPACK=ON, USE_OPENMP=ON, USE_ROCM=OFF, USE_ROCM_KERNEL_ASSERT=OFF,

TorchVision: 0.17.2
OpenCV: 4.9.0
MMEngine: 0.10.4
MMOCR: 1.0.1+2caab0a

Reproduces the problem - code sample

Device: MacBook M3 chip

Following installation using this link:
https://github.com/open-mmlab/mmocr

Also following discussion from here:
open-mmlab/mmcv#204

Nothing worked for me to make OCR work.

The installation process is going all just fine but the package is not working when It comes to OCR samples.

I am getting this error:
File "../env/lib/python3.12/site-packages/mmcv/utils/ext_loader.py", line 13, in load_ext
ext = importlib.import_module('mmcv.' + name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "
File "../.pyenv/versions/3.12.1/lib/python3.12/importlib/init.py", line 90, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ModuleNotFoundError: No module named 'mmcv._ext'"

$ pip list | grep mm
Is giving me

mmcv 2.1.0
mmdet 3.3.0
mmengine 0.10.4
mmocr 1.0.1 ../repositories/mmocr

What am I doing wrong?
Does anyone, have any experience on mac releted to this one?

BTW: I am using python3.12.1

Reproduces the problem - command or script

from mmocr.apis import MMOCRInferencer
from mmocr.utils import poly2bbox
import numpy as np
import time
import cv2

Load models into memory

ocr = MMOCRInferencer(det='DBNet', rec=None, device='cpu') # Time taken: 1.3455498218536377 seconds

Perform inference

startTime = time.time()
aaa = ocr('../mmocr/images/00_04_24_000-00_04_24_375.jpg')
print(aaa["predictions"])
print([poly2bbox(poly) for poly in aaa["predictions"][0]["det_polygons"]])
print(f"Time taken: {time.time() - startTime} seconds")

img = cv2.imread('images/00_04_24_000-00_04_24_375.jpg', cv2.IMREAD_COLOR)

window_name = 'Image'

for text_lines_one in aaa["predictions"][0]["det_polygons"]:
# Polygon corner points coordinates
pts = np.array(text_lines_one,
np.int32)

pts = pts.reshape((-1, 1, 2))

isClosed = True

# Blue color in BGR
color = (255, 0, 0)

# Line thickness of 2 px
thickness = 2

# Using cv2.polylines() method
# Draw a Blue polygon with 
# thickness of 1 px
image = cv2.polylines(img, [pts], 
                isClosed, color, thickness)

Displaying the image

while(1):

cv2.imshow('image', image)
if cv2.waitKey(20) & 0xFF == 27:
    break

cv2.destroyAllWindows()

Reproduces the problem - error message

I am using "DBNet"

Additional information

Device: MacBook M3 chip

Following installation using this link:
https://github.com/open-mmlab/mmocr

Also following discussion from here:
open-mmlab/mmcv#204

Nothing worked for me to make OCR work.

The installation process is going all just fine but the package is not working when It comes to OCR samples.

I am getting this error:
File "../env/lib/python3.12/site-packages/mmcv/utils/ext_loader.py", line 13, in load_ext
ext = importlib.import_module('mmcv.' + name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "
File "../.pyenv/versions/3.12.1/lib/python3.12/importlib/init.py", line 90, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ModuleNotFoundError: No module named 'mmcv._ext'"

$ pip list | grep mm
Is giving me

mmcv 2.1.0
mmdet 3.3.0
mmengine 0.10.4
mmocr 1.0.1 ../repositories/mmocr

What am I doing wrong?
Does anyone, have any experience on mac releted to this one?

BTW: I am using python3.12.1

@R4Ajeti
Copy link
Author

R4Ajeti commented May 14, 2024

I found a temporary fix while debugging:

  1. go to file: "env/lib/python3.12/site-packages/mmcv/utils/ext_loader.py"
  2. change line 13 - 17 with this code:

From:

ext = importlib.import_module('mmcv.' + name)
        
        for fun in funcs:
            assert hasattr(ext, fun), f'{fun} miss in module {name}'
        return ext

to:

if not name == "_ext":
            ext = importlib.import_module('mmcv.' + name)
            
            for fun in funcs:
                assert hasattr(ext, fun), f'{fun} miss in module {name}'
            return ext

@zhouzaida
Copy link
Member

Hi @R4Ajeti , how did you install mmcv?
You could try to uninstall mmcv and follow the below commands to install it again.

pip install openmim
mim install mmcv==2.1.0

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

3 participants