diff --git a/.gitignore b/.gitignore index df79104..6647b70 100644 --- a/.gitignore +++ b/.gitignore @@ -4,9 +4,15 @@ .settings *.pyc +*.pyd *.o *.so *.a +*.dll +*.lib -*~ \ No newline at end of file +*~ + +/build +/python \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..538b428 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,62 @@ +cmake_minimum_required (VERSION 2.8.3) +project (DenseInferenceWrapper) + +if(POLICY CMP0020) + cmake_policy(SET CMP0020 NEW) +endif() + +set(CMAKE_BUILD_TYPE Release) + +#python +find_package(PythonLibs REQUIRED) +include_directories(${PYTHON_INCLUDE_DIRS}) + +# include_directories(${CMAKE_BINARY_DIR}) + +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib) +set(CMAKE_BINARY_DIR ${PROJECT_SOURCE_DIR}/bin) + +link_directories(${PROJECT_SOURCE_DIR}/lib) +add_subdirectory(denseinference) + +# SET( +# CXX_SRC +# ${CMAKE_SOURCE_DIR}/codes/cxx/main.cxx +# ) + +# SET( +# CXX_HDR +# ) + +# SET(Python_SRC_DIR ${CMAKE_SOURCE_DIR}/codes/python) + +# FILE(GLOB Python_SRC ${Python_SRC_DIR}/*.py) + +# add_executable(PythonCxxEmbedding ${CXX_SRC} ${Python_SRC}) +# target_link_libraries(PythonCxxEmbedding ${PYTHON_LIBRARIES}) + +# #Grouping in MSVC +# SOURCE_GROUP("Headers" FILES ${CXX_HDR}) +# SOURCE_GROUP("Sources" FILES ${CXX_SRC}) +# SOURCE_GROUP("Python Sources" FILES ${Python_SRC}) + +# #copy python files to build directory +# macro(copy_python_files srcDir destDir) +# message(STATUS "Configuring python files") +# make_directory(${destDir}) + +# file(GLOB templateFiles RELATIVE ${srcDir} ${srcDir}/*) +# foreach(templateFile ${templateFiles}) +# set(srcTemplatePath ${srcDir}/${templateFile}) +# if(NOT IS_DIRECTORY ${srcTemplatePath}) +# # message(STATUS "Configuring file ${templateFile}") +# configure_file( +# ${srcTemplatePath} +# ${destDir}/${templateFile} +# @ONLY) +# endif(NOT IS_DIRECTORY ${srcTemplatePath}) +# endforeach(templateFile) +# endmacro(copy_python_files) + +# copy_python_files(${Python_SRC_DIR} ${CMAKE_BINARY_DIR}/Debug) +# copy_python_files(${Python_SRC_DIR} ${CMAKE_BINARY_DIR}/RELEASE) \ No newline at end of file diff --git a/denseinference/CMakeLists.txt b/denseinference/CMakeLists.txt new file mode 100644 index 0000000..8570eeb --- /dev/null +++ b/denseinference/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(lib) \ No newline at end of file diff --git a/denseinference/CRFProcessor.py b/denseinference/CRFProcessor.py index 6cd8784..1d0cea9 100644 --- a/denseinference/CRFProcessor.py +++ b/denseinference/CRFProcessor.py @@ -1,11 +1,10 @@ -__author__ = 'Marc Bickel' +__author__ = 'Marc Bickel, modified by Jacky Ko' import numpy as np import psutil from denseinference.lib import dense_inference as di - class CRF3DProcessor(object): # # # diff --git a/denseinference/lib/CMakeLists.txt b/denseinference/lib/CMakeLists.txt new file mode 100644 index 0000000..3d2cafb --- /dev/null +++ b/denseinference/lib/CMakeLists.txt @@ -0,0 +1,3 @@ +add_subdirectory(libDenseCRF) +add_subdirectory(refine_3d) + diff --git a/denseinference/lib/Makefile b/denseinference/lib/Makefile index a5948b3..240a7ed 100644 --- a/denseinference/lib/Makefile +++ b/denseinference/lib/Makefile @@ -1,7 +1,7 @@ # update the path variables CC = g++ -CFLAGS = -W -Wall -O2 -DNDEBUG +CFLAGS = -W -Wall -O2 -DNDEBUG #CFLAGS = -W -Wall -g LIB_ROOT = denseinference/lib/ diff --git a/denseinference/lib/libDenseCRF/CMakeLists.txt b/denseinference/lib/libDenseCRF/CMakeLists.txt new file mode 100644 index 0000000..5aad74f --- /dev/null +++ b/denseinference/lib/libDenseCRF/CMakeLists.txt @@ -0,0 +1,20 @@ +cmake_minimum_required (VERSION 2.8.3) +project(libDenseCRF) + +MESSAGE(STATUS "Configuring ${PROJECT_NAME}...") + +if(POLICY CMP0020) + cmake_policy(SET CMP0020 NEW) +endif() + +set(CMAKE_BUILD_TYPE Release) + +#python +find_package(PythonLibs REQUIRED) +include_directories(${PYTHON_INCLUDE_DIRS}) + +FILE(GLOB LibDenseCRF_SRC *.cpp) +FILE(GLOB LibDenseCRF_HDR *.h) + +add_library(${PROJECT_NAME} STATIC ${LibDenseCRF_SRC} ${LibDenseCRF_HDR}) +target_link_libraries(${PROJECT_NAME}) \ No newline at end of file diff --git a/denseinference/lib/libDenseCRF/permutohedral.h b/denseinference/lib/libDenseCRF/permutohedral.h index 5dfad58..82e6b98 100644 --- a/denseinference/lib/libDenseCRF/permutohedral.h +++ b/denseinference/lib/libDenseCRF/permutohedral.h @@ -46,11 +46,11 @@ # endif #endif -#ifdef WIN32 -static float round( float v ) { - return floor( v+0.5f ); -} -#endif +//#ifdef WIN32 +//static float round( float v ) { +// return floor( v+0.5f ); +//} +//#endif /************************************************/ /*** Hash Table ***/ diff --git a/denseinference/lib/refine_3d/CMakeLists.txt b/denseinference/lib/refine_3d/CMakeLists.txt new file mode 100644 index 0000000..01f09ce --- /dev/null +++ b/denseinference/lib/refine_3d/CMakeLists.txt @@ -0,0 +1,37 @@ +cmake_minimum_required (VERSION 3.3) +project(dense_inference) + +MESSAGE(STATUS "Configuring ${PROJECT_NAME}...") + +if(POLICY CMP0020) + cmake_policy(SET CMP0020 NEW) +endif() + +set(CMAKE_BUILD_TYPE Release) + +#python +# SET(Python_ADDITIONAL_VERSIONS 3) +FIND_PACKAGE(PythonInterp REQUIRED) +find_package(PythonLibs REQUIRED) +include_directories(${PYTHON_INCLUDE_DIRS}) +get_filename_component(Python_Root ${PYTHON_EXECUTABLE} DIRECTORY) + +#FindBoost +find_package(Boost COMPONENTS python REQUIRED) +include_directories(${Boost_INCLUDE_DIRS}) + +FILE(GLOB DenseInference_SRC *.cpp) +FILE(GLOB DenseInference_HDR *.h) + +# numpy +SET(NUMPY_INCLUDE "${Python_Root}/Lib/site-packages/numpy/core/include" CACHE PATH "Path to numpy include folder") +if(NOT NUMPY_INCLUDE) + message(FATAL_ERROR "numpy is not found") +endif() +include_directories(${NUMPY_INCLUDE}) + +include_directories(${CMAKE_SOURCE_DIR}) + + +add_library(${PROJECT_NAME} SHARED ${DenseInference_SRC} ${DenseInference_HDR}) +target_link_libraries(${PROJECT_NAME} ${PYTHON_LIBRARY} ${Boost_LIBRARIES} libDenseCRF) \ No newline at end of file diff --git a/readme.md b/readme.md index c01b4db..6ede656 100644 --- a/readme.md +++ b/readme.md @@ -22,7 +22,7 @@ for more information. #### Requirements ``` -make, g++, boost-python +make, g++, boost-python, cmake, python 2 (python 3 has been tested with compilation fail), MSVC2015 (for windows) ``` #### Requirements Python @@ -35,7 +35,7 @@ numpy, psutil matplotlib ``` -#### Installation +#### Installation (Linux) ```bash cd denseinferencewrapper @@ -43,6 +43,25 @@ make all sudo pip install . ``` +#### CMake Installation (Tested on Windows with MSVC2015) +``` +1. Create a build folder anywhere +2. CMake with specifying source and build folder +3. Configure (Python, Boost, Numpy) +4. Generate +5. build + - Windows + 1. Open .sln file in build folder + 2. Build Release version + 3. Copy /build/denseinference/lib/refine_3d/Release/dense_inference.dll (.so for linux) to /denseinference/lib + 4. Rename the extension from .dll/.so to .pyd + - Linux + (To be updated...) +8. Open CMD/Terminal at +9. pip install . (Permission error will occur if .sln file is open) +10. Copy boost_python-vc140-mt-1_64.dll (.so for linux) at /lib64-msvc-14.0 to /Lib/site-packages/denseinference/lib +``` + ## Usage ```python @@ -74,4 +93,4 @@ result = pro.set_data_and_run(img, feature_tensor) - **param img**: Normalized input as ndarray. (W, H, D), [0, 1] - **param label**: Continuous label tensor as ndarray. (W, H, D, L), [0, 1] -- **return**: Hard labeled result as ndarray. (W, H, D), [0, L], dtype=int16 +- **return**: Hard labeled result as ndarray. (W, H, D), [0, L], dtype=int16 \ No newline at end of file diff --git a/setup.py b/setup.py index 2ddae20..febeb87 100644 --- a/setup.py +++ b/setup.py @@ -1,13 +1,17 @@ from setuptools import setup, find_packages +from sys import platform + +package_data = 'lib/dense_inference.pyd' + setup( name="DenseInferenceWrapper", version="1.0.0", packages=find_packages(), - package_data={'': ['lib/dense_inference.so']}, + package_data={'': [package_data]}, include_package_data=True, url='', license='', - author='Marc Bickel', - author_email='marc.bickel@mytum.de', + author='Marc Bickel, Jacky Ko', + author_email='marc.bickel@mytum.de, jackkykokoko@gmail.com', description='Wrapper for Kraehenbuehls DenseCRF for 3D image data.' ) \ No newline at end of file