【Mac】安装 PaddleOCR_userwarning: no ccache found. please be aware that
环境:Mac M1 芯片
1、安装
1.1 安装 Anaconda
Anaconda 安装较为简单,直接在 Anaconda 官网 下载pkg文件,根据向导提示完成安装。
Anaconda 用于搭建 Python 虚拟环境,目的是为了避免与之前环境安装库的版本冲突,另外 paddle 对Python 的版本也是有要求的。
创建并激活虚拟环境:
zs@Mac ~ % conda create -y -n paddle python=3.12zs@Mac ~ % conda activate paddle
1.2 安装 paddlepaddle
在 官网 获取安装命令:
(paddle) zs@Mac ~ % conda install paddlepaddle==3.0.0b2 -c paddle
验证:
(paddle) zs@Mac ~ % python>>> import paddle>>> paddle.utils.run_check() Running verify PaddlePaddle program ... I1219 22:02:16.993297 4123495424 interpretercore.cc:237] New Executor is Running.I1219 22:02:17.038717 4123495424 interpreter_util.cc:518] Standalone Executor is Used.PaddlePaddle works well on 1 CPU.PaddlePaddle is installed successfully! Let\'s start deep learning with PaddlePaddle now.
可能报错:
-
TypeError: __array__(): incompatible function arguments. The following argument types are supported
paddle与numpy的版本不兼容,通过降低numpy版本解决。
1.3 安装 PaddleOCR
安装:
(paddle) zs@Mac ~ % pip install -i https://pypi.tuna.tsinghua.edu.cn/simple paddleocr --user
安装依赖:先将 项目依赖 拉下来,然后执行以下命令:
(paddle) zs@Mac ~ % pip install -r requirements.txt
2、Paddle 升级
在 官网快速开始界面复制命令,直接执行,pip、conda 等会自动处理依赖关系,并安装或升级到指定的版本。
3、测试
3.1 命令行
paddleocr --image_dir /path/image.jpg
3.2 脚本测试
编写脚本 test.py
:
from paddleocr import PaddleOCR# 创建识别器ocr = PaddleOCR(use_angle_cls=True, lang=\'ch\')img_path = \'../mv/1.jpg\'# 只需运行一次即可下载模型并将其加载到内存中result = ocr.ocr(img_path, cls=True) for idx in range(len(result)): res = result[idx] for line in res: print(line)
终端执行上述脚本:
(paddle) zs@Mac ~ % python test.py
3.3 警告解决
No ccache found
/opt/anaconda3/envs/paddle/lib/python3.12/site-packages/paddle/utils/cpp_extension/extension_utils.py:686: UserWarning: No ccache found. Please be aware that recompiling all source files may be required. You can download and install ccache from: https://github.com/ccache/ccache/blob/master/doc/INSTALL.md warnings.warn(warning_message)
提示在当前环境中没有找到 ccache。ccache 是一个编译缓存工具,可以显著加快重新编译的速度。如果不介意重新编译所有源文件的时间,可以选择忽略这个警告。如果希望提高编译速度,可以按照提示安装 ccache。
conda install -c conda-forge ccache
Setuptools is replacing distutils
/root/miniconda3/envs/PaddleSpeech/lib/python3.9/site-packages/_distutils_hack/__init__.py:30: UserWarning: Setuptools is replacing distutils. Support for replacing an already imported distutils is deprecated. In the future, this condition will fail. Register concerns at https://github.com/pypa/setuptools/issues/new?template=distutils-deprecation.yml warnings.warn(
这个警告表示 setuptools 正在替换 distutils,并且在未来这种替换可能会失败,setuptools项目中建议通过更新 setuptools 来解决。
python -m pip install --upgrade setuptools
pip is being invoked by an old script wrapper
WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.To avoid this problem you can invoke Python with \'-m pip\' instead of running pip directly.
这个警告表示您正在使用的 pip 是通过一个旧的脚本包装器调用的,这在未来可能会导致问题。建议使用 python -m pip 命令来调用 pip。
5、图片太长导致无法识别
将图片进行裁剪
import osfrom PIL import Imagedef crop_image(path, rows, cols, folder): image = Image.open(path) name, extension = os.path.splitext(os.path.basename(path)) width, height = image.size img_width = width // cols img_height = height // rows for row in range(rows): for col in range(cols): box = (col * img_width, row * img_height, (col + 1) * img_width, (row + 1) * img_height) cropped_image = image.crop(box) output_file = f\"{folder}/{name}_{row}_{col}{extension}\" cropped_image.save(output_file)# 裁剪图像:图片地址、裁剪行数、裁剪列数、裁剪结果保存路径crop_image(\"../photo/example.jpg\", 3, 1, \"../photo\")
8、PaddleOCR模型
模型在本地存放默认地址:/Users/zs/.paddleocr/whl
(paddle) zs@Mac ~ % ls /Users/zs/.paddleocr/whlcls det rec
- det(Detection):
这个文件夹包含用于文本检测的模型。文本检测是 OCR 流程的第一步,它的目的是在图像中找到文本的位置。 - cls(Classification):
这个文件夹包含用于文本方向分类的模型(在某些版本的 PaddleOCR 中可能不存在或不是必需的)。文本方向分类用于确定检测到的文本的方向,以便后续能够正确地识别文本内容。 - rec(Recognition):
这个文件夹包含用于文本识别的模型。文本识别是 OCR 流程的最后一步,它的目的是将检测到的文本图像转换为可编辑的文本内容。
如需更改模型缓存目录,只需设置相应的变量环境即可。
9、PaddleOCR模型推理参数
在使用PaddleOCR进行模型推理时,可以自定义修改参数,来修改模型、数据、预处理、后处理等内容,详细的参数解释如下所示。
9.1 全局信息
9.2 预测引擎相关
9.3 文本检测模型相关
- DB算法相关参数如下:
- EAST算法相关参数如下:
- SAST算法相关参数如下:
- PSE算法相关参数如下:
9.4 文本识别模型相关
9.5 端到端文本检测与识别模型相关
9.6 方向分类器模型相关
20、资料
- Paddle官网
- mac m1 m2 安装 paddlepaddle paddleocr库,避坑指南