Skip to content

Commit d3b9328

Browse files
committed
add action for cpp_infer build
1 parent b3e3588 commit d3b9328

File tree

1 file changed

+187
-0
lines changed

1 file changed

+187
-0
lines changed

.github/workflows/cpp_infer.yml

Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
name: C++ Inference Build
2+
3+
on:
4+
push:
5+
branches: [ "master", "main" ]
6+
paths:
7+
- 'deploy/cpp_infer/**'
8+
- '.github/workflows/cpp_infer.yml'
9+
pull_request:
10+
branches: [ "master", "main" ]
11+
paths:
12+
- 'deploy/cpp_infer/**'
13+
- '.github/workflows/cpp_infer.yml'
14+
workflow_dispatch:
15+
16+
env:
17+
BUILD_TYPE: Release
18+
OPENCV_VERSION: "3.4.7"
19+
20+
jobs:
21+
build:
22+
runs-on: ${{ matrix.os }}
23+
strategy:
24+
fail-fast: false
25+
matrix:
26+
os: [ubuntu-latest, macos-latest, windows-latest]
27+
include:
28+
- os: ubuntu-latest
29+
opencv_source_url: https://paddleocr.bj.bcebos.com/libs/opencv/opencv-3.4.7.tar.gz
30+
paddle_url: https://paddle-inference-lib.bj.bcebos.com/2.5.1/cxx_c/Linux/CPU/x86-64_gcc8.2_avx_mkl/paddle_inference.tgz
31+
- os: macos-latest
32+
opencv_source_url: https://paddleocr.bj.bcebos.com/libs/opencv/opencv-3.4.7.tar.gz
33+
paddle_url: https://paddle-inference-lib.bj.bcebos.com/2.5.1/cxx_c/MacOS/CPU/paddle_inference.tgz
34+
- os: windows-latest
35+
opencv_source_url: https://paddleocr.bj.bcebos.com/libs/opencv/opencv-3.4.7.tar.gz
36+
paddle_url: https://paddle-inference-lib.bj.bcebos.com/2.5.1/cxx_c/Windows/CPU/x86-64_vs2019_avx_mkl/paddle_inference.zip
37+
38+
steps:
39+
- uses: actions/checkout@v3
40+
41+
- name: Install Dependencies (Ubuntu)
42+
if: matrix.os == 'ubuntu-latest'
43+
run: |
44+
sudo apt-get update
45+
sudo apt-get install -y build-essential cmake libgoogle-glog-dev libgflags-dev libprotobuf-dev protobuf-compiler
46+
47+
- name: Install Dependencies (macOS)
48+
if: matrix.os == 'macos-latest'
49+
run: |
50+
brew install cmake protobuf gflags glog
51+
52+
- name: Setup Visual Studio Environment (Windows)
53+
if: matrix.os == 'windows-latest'
54+
uses: microsoft/setup-msbuild@v1.0.2
55+
56+
- name: Install Dependencies (Windows)
57+
if: matrix.os == 'windows-latest'
58+
run: |
59+
choco install cmake protoc wget unzip
60+
61+
- name: Cache OpenCV
62+
id: cache-opencv
63+
uses: actions/cache@v3
64+
with:
65+
path: ${{ github.workspace }}/opencv-install
66+
key: ${{ runner.os }}-opencv-${{ env.OPENCV_VERSION }}
67+
68+
- name: Build OpenCV
69+
if: steps.cache-opencv.outputs.cache-hit != 'true'
70+
shell: bash
71+
run: |
72+
wget ${{ matrix.opencv_source_url }}
73+
tar -xf opencv-3.4.7.tar.gz
74+
cd opencv-3.4.7
75+
mkdir build && cd build
76+
if [[ "${{ matrix.os }}" == "windows-latest" ]]; then
77+
cmake -G "Visual Studio 17 2022" -A x64 .. \
78+
-DCMAKE_INSTALL_PREFIX=${{ github.workspace }}/opencv-install \
79+
-DBUILD_SHARED_LIBS=OFF \
80+
-DWITH_IPP=OFF \
81+
-DBUILD_IPP_IW=OFF \
82+
-DWITH_LAPACK=OFF \
83+
-DWITH_EIGEN=OFF \
84+
-DWITH_ZLIB=ON \
85+
-DBUILD_ZLIB=ON \
86+
-DWITH_JPEG=ON \
87+
-DBUILD_JPEG=ON \
88+
-DWITH_PNG=ON \
89+
-DBUILD_PNG=ON \
90+
-DWITH_TIFF=ON \
91+
-DBUILD_TIFF=ON
92+
else
93+
cmake .. -DCMAKE_INSTALL_PREFIX=${{ github.workspace }}/opencv-install \
94+
-DCMAKE_BUILD_TYPE=Release \
95+
-DBUILD_SHARED_LIBS=OFF \
96+
-DWITH_IPP=OFF \
97+
-DBUILD_IPP_IW=OFF \
98+
-DWITH_LAPACK=OFF \
99+
-DWITH_EIGEN=OFF \
100+
-DCMAKE_INSTALL_LIBDIR=lib64 \
101+
-DWITH_ZLIB=ON \
102+
-DBUILD_ZLIB=ON \
103+
-DWITH_JPEG=ON \
104+
-DBUILD_JPEG=ON \
105+
-DWITH_PNG=ON \
106+
-DBUILD_PNG=ON \
107+
-DWITH_TIFF=ON \
108+
-DBUILD_TIFF=ON
109+
fi
110+
cmake --build . --config Release -j4
111+
cmake --install .
112+
113+
- name: Cache Paddle Inference
114+
id: cache-paddle
115+
uses: actions/cache@v3
116+
with:
117+
path: ${{ github.workspace }}/paddle_inference
118+
key: ${{ runner.os }}-paddle-inference-2.5.1
119+
120+
- name: Download Paddle Inference
121+
if: steps.cache-paddle.outputs.cache-hit != 'true'
122+
run: |
123+
if [[ "${{ matrix.os }}" == "windows-latest" ]]; then
124+
curl -L ${{ matrix.paddle_url }} -o paddle_inference.zip
125+
unzip paddle_inference.zip -d ${{ github.workspace }}/paddle_inference
126+
else
127+
wget ${{ matrix.paddle_url }} -O paddle_inference.tgz
128+
mkdir -p ${{ github.workspace }}/paddle_inference
129+
tar -xf paddle_inference.tgz -C ${{ github.workspace }}/paddle_inference
130+
fi
131+
shell: bash
132+
133+
- name: Configure CMake
134+
shell: bash
135+
run: |
136+
cd deploy/cpp_infer
137+
if [[ "${{ matrix.os }}" == "windows-latest" ]]; then
138+
cmake -G "Visual Studio 17 2022" -A x64 -B build \
139+
-DPADDLE_LIB="${{ github.workspace }}/paddle_inference" \
140+
-DOPENCV_DIR="${{ github.workspace }}/opencv-install" \
141+
-DWITH_MKL=ON \
142+
-DWITH_GPU=OFF
143+
else
144+
cmake -B build \
145+
-DPADDLE_LIB=${{ github.workspace }}/paddle_inference \
146+
-DOPENCV_DIR=${{ github.workspace }}/opencv-install \
147+
-DWITH_MKL=ON \
148+
-DWITH_GPU=OFF \
149+
-DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }}
150+
fi
151+
152+
- name: Build
153+
run: |
154+
cd deploy/cpp_infer/build
155+
cmake --build . --config ${{ env.BUILD_TYPE }} -j4
156+
shell: bash
157+
158+
- name: Test
159+
shell: bash
160+
run: |
161+
cd deploy/cpp_infer
162+
163+
# Verify inference directory exists
164+
if [ ! -d "../../inference/rec_rcnn" ]; then
165+
echo "Warning: Inference model directory not found. Model tests will be skipped."
166+
exit 0
167+
fi
168+
169+
cd build
170+
# Run basic test with sample image
171+
if [[ "${{ matrix.os }}" == "windows-latest" ]]; then
172+
if [ ! -f "Release/ppocr.exe" ]; then
173+
echo "Error: Windows executable not found"
174+
exit 1
175+
fi
176+
./Release/ppocr.exe --det=false --cls=false --rec=true \
177+
--rec_model_dir=../../../inference/rec_rcnn \
178+
--image_dir=../../../doc/imgs_words/ch/word_1.jpg || echo "Test execution completed with warnings"
179+
else
180+
if [ ! -f "ppocr" ]; then
181+
echo "Error: Unix executable not found"
182+
exit 1
183+
fi
184+
./ppocr --det=false --cls=false --rec=true \
185+
--rec_model_dir=../../../inference/rec_rcnn \
186+
--image_dir=../../../doc/imgs_words/ch/word_1.jpg || echo "Test execution completed with warnings"
187+
fi

0 commit comments

Comments
 (0)