拉取基础镜像
-
docker pull python:3.8
-
设置
pip
源
pip config set global.index-url https://mirror.baidu.com/pypi/simple
-
设置
apt
源
mv /etc/apt/sources.list /etc/apt/sources.list.bak
将以下内容写入/etc/apt/sources.list
echo '
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free
# deb https://mirrors.tuna.tsinghua.edu.cn/debian-security bullseye-security main contrib non-free
# # deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security bullseye-security main contrib non-free
deb https://security.debian.org/debian-security bullseye-security main contrib non-free
# deb-src https://security.debian.org/debian-security bullseye-security main contrib non-free
' > /etc/apt/sources.list
apt update
安装基础工具
apt install cmake patchelf -y
安装paddlepaddle
-
git clone https://github.com/PaddlePaddle/Paddle.git
若需指定版本:git clone --single-branch -b v2.2.2 --recursive https://github.com/PaddlePaddle/Paddle.git
-
cd Paddle/python && pip install -r requirements.txt && pip install protobuf==3.20.3
-
cd Paddle
-
mkdir build && cd build
-
ulimit -n 4096
# 链接过程中打开文件数较多,可能超过系统默认限制导致编译出错,设置进程允许打开的最大文件数 -
cmake
编译选项表
cmake .. \
-D PY_VERSION=3 \
-D PYTHON_EXECUTABLE=`which python3` \
-D WITH_ARM=ON \
-D WITH_TESTING=OFF \
-D CMAKE_BUILD_TYPE=Release \
-D ON_INFER=ON \
-D WITH_XBYAK=OFF \
-D CMAKE_CXX_FLAGS="-Wno-error -w" \
-D WITH_GPU=OFF \
-D WITH_NCCL=OFF \
-D WITH_RCCL=OFF \
-D WITH_AVX=OFF
-
make TARGET=ARMV8 -j$(nproc)
# 注意,因为处理器为ARM架构,如果不加TARGET=ARMV8则会在编译的时候报错。 -
cd Paddle/build/python/dist && pip install paddlepaddle-2.2.2-cp38-cp38-linux_aarch64.whl
-
python -c "import paddle.fluid as fluid; fluid.install_check.run_check()"
# 如果出现Your Paddle Fluid is installed succesfully!
,说明您已成功安装。
安装 paddleocr
git clone
paddleocrcd PaddleOCR && pip install -r requirements.txt && pip install "opencv-python-headless<4.3" && python setup.py install && pip install numpy==1.23
至此paddleocr安装成功,下面的编译安装opencv用不上。供可能需要opencv高版本的使用。
编译安装 opencv
【可选】
-
git clone
opencv & opencv_contrib -
cd opencv && mkdir build && cd build
-
cmake
# 需要修改OPENCV_EXTRA_MODULES_PATH为opencv_contrib的绝对路径
cmake .. \
-DCMAKE_SYSTEM_PROCESSOR=arm64 \
-DCMAKE_OSX_ARCHITECTURES=arm64 \
-DWITH_OPENJPEG=OFF \
-DWITH_IPP=OFF \
-D CMAKE_BUILD_TYPE=RELEASE \
-D BUILD_opencv_xfeatures2d=OFF \
-D CMAKE_INSTALL_PREFIX=$(python3 -c "import sys; print(sys.prefix)") \
-D ENABLE_NEON=ON \
-D OPENCV_GENERATE_PKGCONFIG=ON \
-D BUILD_opencv_python2=OFF \
-D BUILD_opencv_python3=ON \
-D OPENCV_ENABLE_NONFREE=ON \
-D OPENCV_PYTHON3_INSTALL_PATH=$(python3 -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())") \
-D PYTHON_EXECUTABLE=`which python3` \
-D OPENCV_EXTRA_MODULES_PATH=/data/hisw_ai/opencv_contrib/modules
# -D BUILD_opencv_xfeatures2d=OFF # 这个模块开启时会自动下载一些模型,有些模型在国外服务器,如果用不到里面的算法,这里不推荐打开。
# -D ENABLE_NEON=ON # NEON指令是针对ARM平台的加速指令,在ARMv7及以上支持
# -D OPENCV_GENERATE_PKGCONFIG=ON # 此选项方便调用OpenCV库
make -j$(nproc)
- 编译完后安装
make install