nekro
April 23, 2021, 9:51am
1
I’m building OpenCV 4.5.1 from source with the following configuration:
-D WITH_CUDA=ON \
-D WITH_CUDNN=ON \
-D WITH_CUBLAS=1 \
-D OPENCV_DNN_CUDA=ON \
-D ENABLE_FAST_MATH=1 \
-D CUDA_FAST_MATH=1 \
-D CUDA_ARCH_BIN=7.0 \
-D CUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda-11.0 \
-D OPENCV_EXTRA_MODULES_PATH=/opencv_compile/opencv_contrib-4.5.1/modules \
-D OPENCV_GENERATE_PKGCONFIG=YES \
-D BUILD_opencv_python3=ON \
-D PYTHON3_EXECUTABLE=/usr/bin/python3 \
-D PYTHON3_NUMPY_INCLUDE_DIR=/usr/lib64/python3.6/site-packages/numpy/core/include \
-D PYTHON3_PACKAGES_PATH=/opt/opencv_python \
-D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/opt/opencv .. && \
I’m building this in a Docker image which takes approx. 1hr 45mins and creates a file 8Gb in size.
I need to ship this image to another user.
Is there anyway that the build can be slimmed down?
berak
April 23, 2021, 9:59am
2
which opencv modules do you actually need ? (all of them ?)
if you’re only interested in the python bindings, you should add
-D BUILD_SHARED_LIBS=OFF
to the cmake cmdline, to have cv2 statically linked against the opencv libs
(you neither need those, nor the corresponding .so’s later, then)
it’s also unclear, what exactly you’re shipping
(statically linked cv2 would be ~10mb, dynamically linked ~2mb + ~100mb libs)
((let’s hope, you don’t ship all build artefacts, which indeed would be some GB ))
[edit]
ah, wait this is all without CUDA …
nekro
April 23, 2021, 2:42pm
3
@berak thanks for your reply
I need the following:
Image file reading and writing (imread, imwrite)
Drawing Functions (rectangle, putText, FONT_HERSHEY_SIMPLEX)
Color Space Conversions (cvtColor, COLOR_BGR2RGB)
Deep Neural Network (dnn)
As @berak said if you are processing on the CPU and only need CUDA for the DNN stuff you should be able to remove the remaining CUDA modules
-DBUILD_opencv_cudaarithm=OFF -DBUILD_opencv_cudabgsegm=OFF -DBUILD_opencv_cudafeatures2d=OFF -DBUILD_opencv_cudafilters=OFF -DBUILD_opencv_cudaimgproc=OFF -DBUILD_opencv_cudalegacy=OFF -DBUILD_opencv_cudaobjdetect=OFF -DBUILD_opencv_cudaoptflow=OFF -DBUILD_opencv_cudastereo=OFF -DBUILD_opencv_cudawarping=OFF -DBUILD_opencv_cudacodec=OFF
nekro
April 23, 2021, 8:29pm
7
berak:
what about cuda ???
@berak I need Cuda as I’m using the DNN module for object detection inference on an Nvidia GPU card (v100).
I anticipated your response that’s why I clarified what @berak meant above.
1 Like
nekro
April 24, 2021, 12:27pm
9
@cudawarped I am doing some of the processing on the CPU but need to use the GPU for the DNN module.
Cool you should be able to disable all the other cuda modules then.
nekro
April 26, 2021, 1:58pm
11
@berak @cudawarped thanks both for your guidance.
Build time has reduced from 105mins to 20mins and size of my Docker image from 8Gb to 4Gb. This is much more manageable now and my code still seems to work.