Compiling DeepCV (C++)
Compilation of TensorFlow C++ API
TensorFlow C++ API used in this work was built from the source. One can follow step-by-step instructions to build the TensorFlow libraries using GCC 9.3.1 for C++ 14:
-
Install Python 3.7 or a newer version and Bazel 3.7.2
-
Install ProtoBuf 3.9.2 package with
-D_GLIBCXX_USE_CXX11_ABI=0
flag for ABI compatibility -
Download the tarball from https://github.com/tensorflow/tensorflow/releases/tag/v2.7.4 to a local machine
tar -xzvf v2.7.4.tar.gz cd tensorflow-2.7.4/
-
Compile TensorFlow framework
bazel build --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0" \ --config=opt -c opt \ //tensorflow:libtensorflow.so \ //tensorflow:libtensorflow_cc.so \ //tensorflow:libtensorflow_framework.so \ //tensorflow:install_headers
-
Create a single TensorFlow directory for C++ linkage
More details on package dependencies installation and compilation of TensorFlow C++ API are available at https://github.com/rangsimanketkaew/tensorflow_cpp_api.export LIB_TF="/usr/local/tensorflow/" sudo mkdir $LIB_TF sudo cp -r bazel-bin/tensorflow/include/ $LIB_TF sudo cp -r /home/rangsiman/protobuf-3.9.2/include/google/ $LIB_TF/include/ sudo mkdir $LIB_TF/lib sudo cp -r bazel-bin/tensorflow/*.so* $LIB_TF/lib/ sudo cp -r /home/rangsiman/protobuf-3.9.2/lib/*.so* $LIB_TF/lib/
Compilation of PLUMED with DeepCV and TensorFlow
DeepCV is implemented in PLUMED as a standalone module deepcv
. The source code of a modified version of PLUMED is available at https://gitlab.uzh.ch/lubergroup/plumed2-deepcv. The following is instruction for compiling PLUMED with TensorFlow and DeepCV:
# Clone PLUMED2 DeepCV repository to local machine
git clone git@gitlab.uzh.ch:lubergroup/plumed2-deepcv.git
cd plumed2-deepcv/
# Choose variable to directory to install PLUMED2, e.g.
export PREFIX="/home/rangsiman/plumed2-deepcv-install/"
# Set variable to TensorFlow directory for linkage, e.g.
export LIB_TF="/usr/local/tensorflow/"
# Configuring libraries
./configure --prefix=$PREFIX --enable-rpath \
CXXFLAGS="-O3 -D_GLIBCXX_USE_CXX11_ABI=0 -fPIC" \
CPPFLAGS="-I${LIB_TF}/include/ -L${LIB_TF}/lib/" \
LDFLAGS="-L${LIB_TF}/lib/ -ltensorflow_cc -ltensorflow_framework -Wl,-rpath,$LIB_TF/lib/" \
--disable-external-lapack --disable-external-blas \
--disable-python --disable-libsearch --disable-static-patch \
--disable-static-archive --enable-mpi --enable-cxx=14 \
--disable-modules --enable-modules=adjmat+deepcv
# Compile and install in parallel using, e.g., 8 processors
make -j 8 CXXFLAGS="-D_GLIBCXX_USE_CXX11_ABI=0 -std=c++14 -fPIC" 2>&1 | tee make.log
make -j 8 install 2>&1 | tee make_install.log
export LD_LIBRARY_PATH="${LIB_TF}/lib/":"$PREFIX/lib/":$LD_LIBRARY_PATH
Note that the above procedure will compile PLUMED with MPI. Use --disable-mpi
instead if you prefer serial compilation to parallel compilation.
Compilation of DeepCV C++ module
-
Go to DeepCV directory:
cd /path/to/plumed2/src/deepcv/
-
The users can compile source code (
deepcv.cpp
) using either GCC compilerg++
:or use Make (# Set variable to TensorFlow directory for linkage, e.g. export LIB_TF=/usr/local/tensorflow/ # compile g++ -Wall -fPIC -o deepcv.o deepcv.cpp \ -O3 -D_GLIBCXX_USE_CXX11_ABI=0 -std=c++14 -fPIC \ -I${LIB_TF}/include/ -L${LIB_TF}/lib \ -ltensorflow -ltensorflow_cc -ltensorflow_framework
make
):Related header files are required to be in the same directory of source codes, else one needs to edit the absolute or relative path in Makefile.make CXXFLAGS="-std=c++14 -fPIC"
-
Then build a shared object file (
deepcv.so
):g++ -shared -o deepcv.so deepcv.o