Skip to content

Commit

Permalink
Merge branch 'master' into optional_caffe
Browse files Browse the repository at this point in the history
  • Loading branch information
beniz committed Dec 12, 2018
2 parents 42c661f + e8d1442 commit fcb3c88
Show file tree
Hide file tree
Showing 59 changed files with 2,962 additions and 592 deletions.
3 changes: 2 additions & 1 deletion .travis/install.sh
Expand Up @@ -31,7 +31,8 @@ if [ "$TRAVIS_OS_NAME" = 'linux' ]; then
libleveldb-dev \
libsnappy-dev \
liblmdb-dev \
libutfcpp-dev
libutfcpp-dev \
libarchive-dev

# Install ccache symlink wrappers
pushd /usr/local/bin
Expand Down
128 changes: 83 additions & 45 deletions CMakeLists.txt
Expand Up @@ -65,6 +65,7 @@ if (USE_TF)
set(EIGEN3_INCLUDE_DIR ${TENSORFLOW_CC_DIR}/tensorflow/tensorflow/contrib/makefile/downloads/eigen/)
elseif (USE_CAFFE2)
set(PYTORCH_PATH ${CMAKE_BINARY_DIR}/pytorch/src/pytorch)
set(DETECTRON_PATH ${CMAKE_BINARY_DIR}/detectron/src/detectron)
set(EIGEN3_INCLUDE_DIR ${PYTORCH_PATH}/third_party/eigen)
else()
find_package(PkgConfig)
Expand Down Expand Up @@ -191,17 +192,42 @@ if (USE_CAFFE2)
if (CUDA_FOUND AND NOT USE_CPU_ONLY)
list(APPEND CAFFE2_LIB_DEPS -lcaffe2_gpu)
endif()

if (NOT USE_CAFFE)
list(APPEND CAFFE2_LIB_DEPS -lprotobuf)
endif()

set(PYTORCH_SUPPORTED_COMMIT 3749c58) # Release v0.4.0
list(APPEND CAFFE2_PATCHES
${CMAKE_BINARY_DIR}/patches/caffe2/eigen.patch
${CMAKE_BINARY_DIR}/patches/caffe2/logging.patch
${CMAKE_BINARY_DIR}/patches/caffe2/VLOG.patch
include_directories(
${PYTORCH_PATH}
${PYTORCH_PATH}-build
${PYTORCH_PATH}/aten/src
)
set(CAFFE2_PATCHES ${CMAKE_BINARY_DIR}/patches/caffe2)

set(PYTORCH_SUPPORTED_COMMIT ff608a9) # Pre-release v1.0rc1
set(PYTORCH_PATCHES
${CAFFE2_PATCHES}/pytorch/0001-eigen.patch
${CAFFE2_PATCHES}/pytorch/0002-logging.patch
${CAFFE2_PATCHES}/pytorch/0003-collect_proposals.patch
)

set(DETECTRON_SUPPORTED_COMMIT 8181a32) # Nov 7, 2018
set(DETECTRON_PATCHES
${CAFFE2_PATCHES}/detectron/0001-dependencies.patch
${CAFFE2_PATCHES}/detectron/0002-compiled.patch
${CAFFE2_PATCHES}/detectron/0003-ops.patch
${CAFFE2_PATCHES}/detectron/0004-import.patch
)

list(APPEND CAFFE2_OPS
${CAFFE2_PATCHES}/custom_ops/bbox_to_roi_op.h
${CAFFE2_PATCHES}/custom_ops/bbox_to_roi_op.cc
${CAFFE2_PATCHES}/custom_ops/segment_mask_op.h
${CAFFE2_PATCHES}/custom_ops/segment_mask_op.cc
${CAFFE2_PATCHES}/custom_ops/multi_level_roi_op.h
${CAFFE2_PATCHES}/custom_ops/multi_level_roi_op.cc
)

list(APPEND PYTORCH_FLAGS

-DCAFFE2_LINK_LOCAL_PROTOBUF=0
Expand All @@ -214,11 +240,10 @@ if (USE_CAFFE2)

-DBUILD_TEST=OFF
-DBUILD_BINARY=OFF
-DBUILD_PYTHON=OFF
-DBUILD_DOCS=OFF
)

# Only 12 / 28 submodules are currently used by caffe2
# Only a few submodules are currently used by caffe2
# (No need to log, benchmark, compile for IOS, make python libraries, ...)
list(APPEND PYTORCH_SUBMODULES
third_party/cpuinfo
Expand All @@ -232,9 +257,12 @@ if (USE_CAFFE2)
third_party/protobuf
third_party/psimd
third_party/pthreadpool
third_party/pybind11
third_party/python-peachpy
third_party/sleef
)

# Pytorch
set(PYTORCH_COMPLETE ${CMAKE_BINARY_DIR}/CMakeFiles/pytorch-complete)
ExternalProject_Add(
pytorch
Expand All @@ -244,22 +272,47 @@ if (USE_CAFFE2)
GIT_SUBMODULES ${PYTORCH_SUBMODULES}
UPDATE_DISCONNECTED 1
GIT_TAG ${PYTORCH_SUPPORTED_COMMIT}
PATCH_COMMAND test -f ${PYTORCH_COMPLETE} && echo Skipping || wget https://raw.githubusercontent.com/${CAFFE_DD_USER}/caffe/${CAFFE_DD_BRANCH}/src/caffe/proto/caffe.proto -O caffe/proto/caffe.proto && git am ${CAFFE2_PATCHES}
CONFIGURE_COMMAND test -f ${PYTORCH_COMPLETE} && echo Skipping || cmake ${PYTORCH_FLAGS}
PATCH_COMMAND test -f ${PYTORCH_COMPLETE} && echo Skipping || echo cp modules/detectron/*_op.* caffe2/operators | bash && cp ${CAFFE2_OPS} caffe2/operators && git am ${PYTORCH_PATCHES}
CONFIGURE_COMMAND test -f ${PYTORCH_COMPLETE} && echo Skipping || cmake ../pytorch ${PYTORCH_FLAGS}
BUILD_COMMAND test -f ${PYTORCH_COMPLETE} && echo Skipping || make -j${N}
INSTALL_COMMAND ""
BUILD_IN_SOURCE 1
)

# Compilation path
set(PROTOBUF_INCLUDE_DIR ${CMAKE_BINARY_DIR}/protobuf/include)
set(PROTOBUF_LIB_DIR ${CMAKE_BINARY_DIR}/protobuf/lib)
if (NOT EXISTS ${CMAKE_BINARY_DIR}/protobuf)
execute_process(COMMAND mkdir ${CMAKE_BINARY_DIR}/protobuf)
execute_process(COMMAND ln -s ${PYTORCH_PATH}/third_party/protobuf/src ${PROTOBUF_INCLUDE_DIR})
execute_process(COMMAND ln -s ${PYTORCH_PATH}/lib ${PROTOBUF_LIB_DIR})
execute_process(COMMAND ln -s ${PYTORCH_PATH}/bin ${CMAKE_BINARY_DIR}/protobuf/bin)
execute_process(COMMAND ln -s ${PYTORCH_PATH} ${CMAKE_BINARY_DIR}/pytorch_root)
execute_process(COMMAND ln -s ${PYTORCH_PATH}-build/lib ${PROTOBUF_LIB_DIR})
execute_process(COMMAND ln -s ${PYTORCH_PATH}-build/bin ${CMAKE_BINARY_DIR}/protobuf/bin)
endif()

# Detectron
set(DETECTRON_COMPLETE ${CMAKE_BINARY_DIR}/CMakeFiles/detectron-complete)
ExternalProject_Add(
detectron
PREFIX detectron
INSTALL_DIR ${CMAKE_BINARY_DIR}
GIT_REPOSITORY https://github.com/facebookresearch/Detectron
UPDATE_DISCONNECTED 1
GIT_TAG ${DETECTRON_SUPPORTED_COMMIT}
PATCH_COMMAND test -f ${DETECTRON_COMPLETE} && echo Skipping || git am ${DETECTRON_PATCHES}
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
)
add_dependencies(detectron pytorch)

# Python path
if (NOT EXISTS ${CMAKE_BINARY_DIR}/python_path)
execute_process(COMMAND mkdir ${CMAKE_BINARY_DIR}/python_path)
execute_process(COMMAND ln -s ${PYTORCH_PATH}-build
${CMAKE_BINARY_DIR}/python_path/pytorch)
execute_process(COMMAND ln -s ${DETECTRON_PATH}
${CMAKE_BINARY_DIR}/python_path/detectron)
endif()

endif()

if (USE_TF)
Expand Down Expand Up @@ -322,12 +375,6 @@ elseif(USE_CAFFE)
set(USE_SYSLOG 0)
endif()

if (USE_CAFFE2)
set(PYTORCH_LINK 1)
else()
set(PYTORCH_LINK 0)
endif()

# Set protoc path
if (CUDA_FOUND
AND NOT USE_CAFFE_CPU_ONLY
Expand Down Expand Up @@ -382,7 +429,6 @@ elseif(USE_CAFFE)
ln -sf ${CAFFE_DD_CONFIG_FILE} Makefile.config &&
echo "OPENCV_VERSION:=${OPENCV_VERSION}" >> Makefile.config &&
echo "USE_SYSLOG:=${USE_SYSLOG}" >> Makefile.config &&
echo "PYTORCH_LINK:=${PYTORCH_LINK}" >> Makefile.config &&
echo "DEBUG:=${CAFFE_DEBUG}" >> Makefile.config &&
${CAFFE_DD_MAKE} ${CAFFE_DD_MAKE_ARG} -j${N}
)
Expand Down Expand Up @@ -444,6 +490,7 @@ endif()
if (USE_CAFFE2)
if (USE_CAFFE)
add_dependencies(caffe_dd pytorch)
add_dependencies(caffe_dd detectron)
else()
set(CAFFE2_INC_DIR ${PROTOBUF_INCLUDE_DIR})
set(CAFFE2_LIB_DIR ${PROTOBUF_LIB_DIR})
Expand Down Expand Up @@ -509,15 +556,6 @@ include_directories("${PROJECT_BINARY_DIR}")
include_directories(${CAFFE_INC_DIR} ${CAFFE2_INC_DIR} ${XGBOOST_INC_DIR} ${TSNE_INC_DIR})
include_directories(${CMAKE_SOURCE_DIR}/src/backends/caffe ${CMAKE_SOURCE_DIR}/backends/xgb ${CMAKE_SOURCE_DIR}/backends/tf ${CMAKE_SOURCE_DIR}/backends/dlib ${CMAKE_SOURCE_DIR}/backends/tsne)

# Our version of caffe.proto was "injected" into caffe2 and compiled within it
# So two versions of caffe.pb.h were generated (the only difference being the namespace ... name).
# One of them is meant to be used by caffe2, the other one by us.
# Because we can include the one from caffe2, but don't want to,
# PYTORCH_PATH must be checked after CAFFE_INC_DIR
if (USE_CAFFE2)
include_directories(${PYTORCH_PATH})
endif()

# main library, main & tests
include_directories ("${PROJECT_SOURCE_DIR}/src")
add_subdirectory (src)
Expand All @@ -532,23 +570,23 @@ set(COMMON_LINK_DIRS
${TSNE_LIB_DIR}
${DLIB_LIB_DIR})
if (USE_HDF5)
set(COMMON_LINK_LIBS
ddetect ${CUDA_LIB_DEPS} glog gflags ${OpenCV_LIBS} curlpp curl hdf5_cpp ${Boost_LIBRARIES}
${CAFFE_LIB_DEPS}
${CAFFE2_LIB_DEPS}
${TF_LIB_DEPS}
${XGBOOST_LIB_DEPS}
${TSNE_LIB_DEPS}
${DLIB_LIB_DEPS})
set(COMMON_LINK_LIBS
ddetect ${CUDA_LIB_DEPS} glog gflags ${OpenCV_LIBS} curlpp curl hdf5_cpp ${Boost_LIBRARIES} archive
${CAFFE_LIB_DEPS}
${CAFFE2_LIB_DEPS}
${TF_LIB_DEPS}
${XGBOOST_LIB_DEPS}
${TSNE_LIB_DEPS}
${DLIB_LIB_DEPS})
else()
set(COMMON_LINK_LIBS
ddetect ${CUDA_LIB_DEPS} glog gflags ${OpenCV_LIBS} curlpp curl ${Boost_LIBRARIES}
${CAFFE_LIB_DEPS}
${CAFFE2_LIB_DEPS}
${TF_LIB_DEPS}
${XGBOOST_LIB_DEPS}
${TSNE_LIB_DEPS}
${DLIB_LIB_DEPS})
set(COMMON_LINK_LIBS
ddetect ${CUDA_LIB_DEPS} glog gflags ${OpenCV_LIBS} curlpp curl ${Boost_LIBRARIES} archive
${CAFFE_LIB_DEPS}
${CAFFE2_LIB_DEPS}
${TF_LIB_DEPS}
${XGBOOST_LIB_DEPS}
${TSNE_LIB_DEPS}
${DLIB_LIB_DEPS})
endif()
set(HTTP_LINK_LIBS cppnetlib-uri crypto ssl)

Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -242,7 +242,7 @@ Below are instructions for Ubuntu 14.04 LTS and 16.04 LTS. For other Linux and U

Beware of dependencies, typically on Debian/Ubuntu Linux, do:
```
sudo apt-get install build-essential libgoogle-glog-dev libgflags-dev libeigen3-dev libopencv-dev libcppnetlib-dev libboost-dev libboost-iostreams-dev libcurlpp-dev libcurl4-openssl-dev protobuf-compiler libopenblas-dev libhdf5-dev libprotobuf-dev libleveldb-dev libsnappy-dev liblmdb-dev libutfcpp-dev cmake libgoogle-perftools-dev unzip python-setuptools python-dev libspdlog-dev python-six python-enum34
sudo apt-get install build-essential libgoogle-glog-dev libgflags-dev libeigen3-dev libopencv-dev libcppnetlib-dev libboost-dev libboost-iostreams-dev libcurlpp-dev libcurl4-openssl-dev protobuf-compiler libopenblas-dev libhdf5-dev libprotobuf-dev libleveldb-dev libsnappy-dev liblmdb-dev libutfcpp-dev cmake libgoogle-perftools-dev unzip python-setuptools python-dev libspdlog-dev python-six python-enum34 libarchive-dev
```

#### Default build with Caffe
Expand Down
5 changes: 4 additions & 1 deletion clients/python/dd_bench.py
Expand Up @@ -85,11 +85,14 @@
parameters_mllib = {'gpu':args.gpu}
parameters_output = {}
if args.detection:
parameters_output['bbox'] = True

parameters_output['confidence_threshold'] = 0.1
if args.search or args.search_multibox:
parameters_output['search'] = True
parameters_output['rois'] = 'rois'
parameters_output['bbox'] = False
else:
parameters_output['bbox'] = True
if args.search_multibox:
parameters_output['multibox_rois'] = True
elif args.search:
Expand Down

0 comments on commit fcb3c88

Please sign in to comment.