forked from LKKlein/paddleocr-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
178 lines (151 loc) · 6.17 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
FROM --platform=linux/amd64 golang:bookworm AS paddle-amd64
LABEL maintainer="TeCHiScy <[email protected]>"
# note: need >= 16GiB memory to build in docker
ENV BUILD="git \
sudo \
build-essential \
cmake \
pkg-config \
python3-yaml \
python3-jinja2"
RUN sed -i 's/deb.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list.d/debian.sources && \
apt-get update && \
apt-get install -y --no-install-recommends ${BUILD} && \
apt-get autoremove -y && apt-get autoclean -y
RUN cd /tmp && git clone -b v2.6.2 --depth=1 https://github.com/PaddlePaddle/Paddle.git && \
cd Paddle && git checkout v2.6.2 && \
mkdir build && cd build && \
sed -i 's/--build ./--build . --parallel 1/' ../cmake/external/gflags.cmake && \
sed -i 's/--build ./--build . --parallel 1/' ../cmake/external/gloo.cmake && \
sed -i 's/make/make -j1/' ../cmake/external/xxhash.cmake && \
cmake .. \
-DCMAKE_BUILD_TYPE=RELEASE \
-DCMAKE_INSTALL_PREFIX=/usr/local \
-DWITH_PYTHON=OFF \
-DWITH_GPU=OFF \
-DWITH_TESTING=OFF \
-DWITH_MKL=ON \
-DWITH_MKLDNN=ON \
-DON_INFER=ON \
-DWITH_CRYPTO=OFF && \
ulimit -n 102400 && \
make -j8 inference_lib_dist
FROM --platform=linux/arm64 golang:bookworm AS paddle-arm64
ENV BUILD="git \
sudo \
build-essential \
cmake \
pkg-config \
python3-yaml \
python3-jinja2"
RUN sed -i 's/deb.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list.d/debian.sources && \
apt-get update && \
apt-get install -y --no-install-recommends ${BUILD} && \
apt-get autoremove -y && apt-get autoclean -y
RUN cd /tmp && git clone -b v2.6.2 --depth=1 https://github.com/PaddlePaddle/Paddle.git && \
cd Paddle && git checkout v2.6.2 && \
mkdir build && cd build && \
sed -i 's/--build ./--build . --parallel 1/' ../cmake/external/gflags.cmake && \
sed -i 's/--build ./--build . --parallel 1/' ../cmake/external/gloo.cmake && \
sed -i 's/make/make -j1/' ../cmake/external/xxhash.cmake && \
sed -i '109a set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=class-memaccess")\n' ../CMakeLists.txt && \
cmake .. \
-DCMAKE_BUILD_TYPE=RELEASE \
-DCMAKE_INSTALL_PREFIX=/usr/local \
-DWITH_PYTHON=OFF \
-DWITH_GPU=OFF \
-DWITH_TESTING=OFF \
-DON_INFER=ON \
-DWITH_ARM=ON \
-DWITH_CRYPTO=OFF && \
ulimit -n 102400 && \
make -j8 inference_lib_dist
RUN mkdir -p /tmp/Paddle/build/paddle_inference_c_install_dir/third_party/install/mklml/lib && \
mkdir -p /tmp/Paddle/build/paddle_inference_install_dir/third_party/install/mkldnn/lib
FROM paddle-${TARGETARCH} AS gocv
ARG OPENCV_VERSION=4.10.0
ENV OPENCV_VERSION=$OPENCV_VERSION
ENV BUILD="git \
build-essential \
cmake \
unzip \
wget \
pkg-config"
ENV DEV="libswscale-dev \
libtbbmalloc2 \
libtbb-dev \
libjpeg62-turbo-dev \
libpng-dev \
libtiff-dev"
RUN apt-get update && \
apt-get install -y --no-install-recommends ${BUILD} ${DEV} && \
apt-get autoremove -y && apt-get autoclean -y
RUN mkdir /tmp/opencv && \
cd /tmp/opencv && \
wget -O opencv.zip https://github.com/opencv/opencv/archive/${OPENCV_VERSION}.zip && \
unzip opencv.zip && \
wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/${OPENCV_VERSION}.zip && \
unzip opencv_contrib.zip && \
mkdir /tmp/opencv/opencv-${OPENCV_VERSION}/build && cd /tmp/opencv/opencv-${OPENCV_VERSION}/build && \
cmake .. \
-DCMAKE_BUILD_TYPE=RELEASE \
-DCMAKE_INSTALL_PREFIX=/usr/local \
-DOPENCV_EXTRA_MODULES_PATH=/tmp/opencv/opencv_contrib-${OPENCV_VERSION}/modules \
-DBUILD_TESTS=NO \
-DBUILD_PERF_TESTS=NO \
-DBUILD_EXAMPLES=NO \
-DBUILD_opencv_apps=NO \
-DWITH_FFMPEG=NO \
-DBUILD_JAVA=NO \
-DBUILD_FAT_JAVA_LIB=NO \
-DBUILD_opencv_python2=NO \
-DBUILD_opencv_python3=NO \
-DWITH_1394=NO \
-DWITH_ANDROID_MEDIANDK=NO \
-DWITH_GTK=NO \
-DOPENCV_GENERATE_PKGCONFIG=YES && \
make -j8 && \
make install && \
cd && rm -rf /tmp/opencv
FROM golang:bookworm AS builder
COPY --from=gocv /usr/local/lib /usr/local/lib
COPY --from=gocv /usr/local/lib/pkgconfig/opencv4.pc /usr/local/lib/pkgconfig/opencv4.pc
COPY --from=gocv /usr/local/include/opencv4/opencv2 /usr/local/include/opencv4/opencv2
COPY --from=gocv /tmp/Paddle/build/paddle_inference_c_install_dir /paddle_inference_c_install_dir
COPY --from=gocv /tmp/Paddle/build/paddle_inference_install_dir /paddle_inference_install_dir
ENV DEV="libswscale-dev \
libtbbmalloc2 \
libtbb-dev \
libjpeg62-turbo-dev \
libpng-dev \
libtiff-dev \
libomp-dev"
RUN sed -i 's/deb.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list.d/debian.sources && \
apt-get update && \
apt-get install -y --no-install-recommends ${DEV} && \
apt-get autoremove -y && apt-get autoclean -y
COPY ./ /build
ENV LD_LIBRARY_PATH=/usr/local/lib:/usr/local/lib:/paddle_inference_install_dir/paddle/lib:/paddle_inference_install_dir/third_party/install/mkldnn/lib
RUN cd /build && \
go mod tidy && \
ln -s /paddle_inference_c_install_dir ${GOPATH}/pkg/mod/github.com/paddlepaddle/paddle/paddle/fluid/inference/goapi\@v0.0.0-20241018162839-3b9f747fe7ea/paddle_inference_c && \
go build demo.go
FROM debian:bookworm-slim AS runner
COPY --from=gocv /usr/local/lib /usr/local/lib
COPY --from=gocv /tmp/Paddle/build/paddle_inference_install_dir/paddle/lib /usr/local/lib
COPY --from=gocv /tmp/Paddle/build/paddle_inference_install_dir/third_party/install/mkldnn/lib /usr/local/lib
COPY --from=gocv /tmp/Paddle/build/paddle_inference_c_install_dir/third_party/install/mklml/lib /usr/local/lib
COPY --from=gocv /tmp/Paddle/build/paddle_inference_c_install_dir/paddle/lib/libpaddle_inference_c.so /usr/local/lib/libpaddle_inference_c.so
COPY --from=builder /build/demo /app/demo
COPY ./model /app/model
COPY ./config /app/config
ENV DEV="libjpeg62-turbo \
libwebp-dev \
libpng-dev \
libtiff-dev \
libgomp1"
RUN sed -i 's/deb.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list.d/debian.sources && \
apt-get update && \
apt-get install -y --no-install-recommends ${DEV} && \
apt-get autoremove -y && apt-get autoclean -y
WORKDIR /app