• PaddleOCR训练部署文档


     Cuda安装

    1. wget https://developer.download.nvidia.com/compute/cuda/11.6.0/local_installers/cuda_11.6.0_510.39.01_linux.run
    2. sh cuda_11.6.0_510.39.01_linux.run
    3. #可能会报错,查看/var/log/nvidia-installer.log ,kill -9 [ID]可以解决
    4. vim ~/.bashrc

    1. source ~/.bashrc
    2. nvcc -V
    3. cp cudnn-linux-x86_64-8.4.1.50_cuda11.6-archive/include/* /usr/local/cuda-11.6/include/
    4. cp cudnn-linux-x86_64-8.4.1.50_cuda11.6-archive/lib/* /usr/local/cuda-11.6/lib64/
    5. chmod +x /usr/local/cuda-11.6/include/cudnn.h
    6. chmod +x /usr/local/cuda-11.6/lib64/libcudnn*
    7. 检测
    8. cat /usr/local/cuda/include/cudnn_version.h | grep CUDNN_MAJOR -A 2

     以文本识别训练为例

    环境使用anconda创建了”paddle”的虚拟环境,该环境适合paddleOCR。

    conda activate paddle

    数据准备

    如图1-1,数据集需要提供train_list.txt,和val_list.txt,具体内容如图1-2,修改配置文件位置图1-3

     图1-1

    图1-2 train_list.txt,和val_list.txt具体内容

    训练模型

    1. git clone https://github.com/PaddlePaddle/PaddleOCR.git
    2. cd PaddleOCR
    3. #下载预训练模型,按需求下载
    4. wget -P ./pretrain_models/ https://paddleocr.bj.bcebos.com/PP-OCRv3/english/en_PP-OCRv3_rec_train.tar
    5. # 解压模型参数
    6. cd pretrain_models
    7. tar -xf en_PP-OCRv3_rec_train.tar && rm -rf en_PP-OCRv3_rec_train.tar
    8. #cd /configs/rec/PP-OCRv3/ ,创建my_en_PP-OCRv3_rec.yml
    9. #注意配置数据集地址

    1. 启动训练:
    2. #cd到PaddleOCR目录下
    3. python3 tools/train.py -c configs/rec/PP-OCRv3/my_en_PP-OCRv3_rec.yml -o Global.pretrained_model=./pretrained_model/en_PPOCRv3_rec_train/best_accuracy
    4. 如果出现中断,重启训练:
    5. python3 tools/train.py -c configs/rec/PP-OCRv3/en_PP-OCRv3_rec.yml -o Global.checkpoints=./your/trained/model
    6. 指标评估
    7. python3 tools/train.py -c configs/rec/PP-OCRv3/en_PP-OCRv3_rec.yml -o Global.checkpoints=./output/v3_en_mobile/best_accuracy
    8. 导出模型
    9. # -c 后面设置训练算法的yml配置文件
    10. # -o 配置可选参数
    11. # Global.pretrained_model 参数设置待转换的训练模型地址,不用添加文件后缀 .pdmodel,.pdopt或.pdparams。
    12. # Global.save_inference_dir参数设置转换的模型将保存的地址。
    13. python3 tools/export_model.py -c configs/rec/PP-OCRv3/en_PP-OCRv3_rec.yml -o Global.pretrained_model=./pretrain_models/en_PP-OCRv3_rec_train/best_accuracy Global.save_inference_dir=./inference/en_PP-OCRv3_rec/
    14. #清除内存
    15. fuser -v /dev/nvidia*
    16. kill -9 [nvidia的PID]

    第二章 部署

    安装Cmake,OpenCV,OpenCV-contribute

    1. yum install mesa-libGL-devel mesa-libGLU-devel
    2. wget https://cmake.org/files/v3.26/cmake-3.26.0-rc4.tar.gz
    3. tar -zxvf cmake-3.26.0-rc.tar.gz
    4. cd cmake-3.26.0-rc
    5. ./bootstrap && make -j4 && make install
    6. cmake --version
    7. #安装opencv
    8. yum localinstall –nogpgcheck https://download1.rpmfusion.org/free/el/rpmfusion-free-release-7.noarch.rpm
    9. yum localinstall –nogpgcheck https://download1.rpmfusion.org/nonfree/el/rpmfusion-nonfree-release-7.noarch.rpm
    10. rpm –import http://li.nux.ro/download/nux/RPM-GPG-KEY-nux.ro
    11. rpm -Uvh http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-1.el7.nux.noarch.rpm
    12. yum -y install ffmpeg ffmpeg-devel
    13. yum install build-essential libgtk2.0-dev libgtk-3-dev libavcodec-dev libavformat-dev libjpeg-dev libswscale-dev libtiff5-dev
    14. git clone https://github.com/opencv/opencv.git
    15. cd opencv
    16. git clone https://github.com/opencv/opencv_contrib.git
    17. #上传缺少文件
    18. cd opencv_contrib/modules/xfeatures2d/src
    19. cd opencv
    20. mkdir build
    21. cd build
    22. #anconda中的lib可能会干扰安装
    23. cmake .. \
    24. -DCMAKE_INSTALL_PREFIX=/opencv4/ \
    25. -DCMAKE_BUILD_TYPE=Release \
    26. -DBUILD_SHARED_LIBS=OFF \
    27. -DWITH_IPP=OFF \
    28. -D WITH_OPENEXR=0 \
    29. -DBUILD_IPP_IW=OFF \
    30. -DWITH_LAPACK=OFF \
    31. -DWITH_EIGEN=OFF \
    32. -DCMAKE_INSTALL_LIBDIR=lib64 \
    33. -DWITH_ZLIB=ON \
    34. -DBUILD_ZLIB=ON \
    35. -DWITH_JPEG=ON \
    36. -DBUILD_JPEG=ON \
    37. -DWITH_PNG=ON \
    38. -DBUILD_PNG=ON \
    39. -DWITH_TIFF=ON \
    40. -DBUILD_TIFF=ON
    41. make -j8 #多次
    42. make install

    预测

    1. git clone https://github.com/PaddlePaddle/Paddle.git
    2. cd Paddle
    3. mkdir build
    4. cd build
    5. cmake .. \
    6. -DPYTHON_INCLUDE_DIR=/usr/bin/python3 \
    7. -DWITH_CONTRIB=OFF \
    8. -DWITH_MKL=ON \
    9. -DWITH_MKLDNN=ON \
    10. -DWITH_TESTING=OFF \
    11. -DCMAKE_BUILD_TYPE=Release \
    12. -DWITH_INFERENCE_API_TEST=OFF \
    13. -DON_INFER=ON \
    14. -DWITH_PYTHON=ON
    15. make -j #时间很长,多次尝试
    16. make inference_lib_dist
    17. sh tools/build.sh
    18. #修改
    19. OPENCV_DIR=/software/opencv4
    20. LIB_DIR=/paddle_inference_install_dir
    21. CUDA_LIB_DIR=/usr/local/cuda/lib64
    22. CUDNN_LIB_DIR=/usr/local/cuda/lib64
    #编译前,需要注意替换args.cpp中的rec_char_dict_path,不然会检测乱码

    1. #编译
    2. sh tools/build.sh
    #可能会出现问题1
    1. cc1plus: error: too many filenames given. Type cc1plus --help for usage
    2. cc1plus: error: too many filenames given. Type cc1plus --help for usage
    3. cc1plus: error: too many filenames given. Type cc1plus --help for usage
    4. cc1plus: error: too many filenames given. Type cc1plus --help for usage
    5. cc1plus: fatal error: CMakeFiles/ppocr.dir/src/postprocess_op.cpp.d: 没有那个文件或目录
    6. cc1plus: fatal error: CMakeFiles/ppocr.dir/src/ocr_rec.cpp.d: 没有那个文件或目录
    7. compilation terminated.
    8. compilation terminated.
    9. cc1plus: error: too many filenames given. Type cc1plus --help for usage
    10. cc1plus: fatal error: CMakeFiles/ppocr.dir/src/main.cpp.d: 没有那个文件或目录
    11. cc1plus: fatal error: CMakeFiles/ppocr.dir/src/ocr_det.cpp.d: 没有那个文件或目录
    12. compilation terminated.
    13. compilation terminated.
    14. cc1plus: error: too many filenames given. Type cc1plus --help for usage
    15. cc1plus: fatal error: CMakeFiles/ppocr.dir/src/ocr_cls.cpp.d: 没有那个文件或目录
    16. compilation terminated.
    17. cc1plus: fatal error: CMakeFiles/ppocr.dir/src/utility.cpp.d: 没有那个文件或目录
    18. compilation terminated.
    解决办法:
    1. #解决办法/PaddleOCR/deploy/cpp_infer/CMakeLists.txt将 "-o3" 改成 "-O3" 就可以了,修改后的结果如下,
    2. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O3 ${FLAG_OPENMP} -std=c++11")

    网速会影响下载third-party导致报错。

    测试

    ./build/ppocr --rec_model_dir=../../inference/en_PP-OCRv3_rec     --image_dir=../../doc/imgs_words/en/word_2.png     --use_angle_cls=false     --det=false     --rec=true

  • 相关阅读:
    3.rsync备份案例
    Linux:实用操作
    TDK | EMC是什么?
    Java日志系列——规范化日志
    MySQL的三种日志文件
    【java+vue】前后端项目架构详细流程
    Java中如何使用JSON-lib包解析Json格式呢?
    【Android学习】Android studio环境搭建-解决下载gradle慢&加载mainfest.xml慢的问题
    JAVA实现冒泡排序
    JavaSSM笔记(二)SpringMvc基础
  • 原文地址:https://blog.csdn.net/mddCSDN/article/details/132738944