From 938eed70da5e246e395a6b30b547c5c5c52649b7 Mon Sep 17 00:00:00 2001 From: Jacky Ko Date: Wed, 2 Aug 2017 19:46:42 +0800 Subject: [PATCH 1/7] Windows version using cmake --- .gitignore | 7 ++- CMakeLists.txt | 62 +++++++++++++++++++ denseinference/CMakeLists.txt | 1 + denseinference/CRFProcessor.py | 9 ++- denseinference/lib/CMakeLists.txt | 3 + denseinference/lib/Makefile | 2 +- denseinference/lib/libDenseCRF/CMakeLists.txt | 20 ++++++ .../lib/libDenseCRF/permutohedral.h | 10 +-- denseinference/lib/refine_3d/CMakeLists.txt | 37 +++++++++++ readme.md | 15 ++++- setup.py | 6 +- 11 files changed, 159 insertions(+), 13 deletions(-) create mode 100644 CMakeLists.txt create mode 100644 denseinference/CMakeLists.txt create mode 100644 denseinference/lib/CMakeLists.txt create mode 100644 denseinference/lib/libDenseCRF/CMakeLists.txt create mode 100644 denseinference/lib/refine_3d/CMakeLists.txt diff --git a/.gitignore b/.gitignore index df79104..32bc52b 100644 --- a/.gitignore +++ b/.gitignore @@ -8,5 +8,10 @@ *.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..ecf1764 100644 --- a/denseinference/CRFProcessor.py +++ b/denseinference/CRFProcessor.py @@ -1,9 +1,14 @@ -__author__ = 'Marc Bickel' +__author__ = 'Marc Bickel, modified by Jacky Ko' import numpy as np import psutil -from denseinference.lib import dense_inference as di +from ctypes import * + +di = cdll.LoadLibrary("lib/dense_inference.dll") + +# from denseinference.lib import dense_inference as di +# 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..4b8c04f --- /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 2) +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..6513131 100644 --- a/readme.md +++ b/readme.md @@ -35,7 +35,7 @@ numpy, psutil matplotlib ``` -#### Installation +#### Installation (Linux) ```bash cd denseinferencewrapper @@ -43,6 +43,19 @@ make all sudo pip install . ``` +#### 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. Open .sln file in build folder +6. Build Release version +7. Copy /build/denseinference/lib/refine_3d/Release/dense_inference.dll to /denseinference +8. Open CMD at +9. pip install . (Permission error will occur if .sln file is open) +10. Copy boost_python-vc140-mt-1_64.dll at /lib64-msvc-14.0 to /Lib/site-packages/denseinference + ## Usage ```python diff --git a/setup.py b/setup.py index 2ddae20..fcc257d 100644 --- a/setup.py +++ b/setup.py @@ -3,11 +3,11 @@ name="DenseInferenceWrapper", version="1.0.0", packages=find_packages(), - package_data={'': ['lib/dense_inference.so']}, + package_data={'': ['lib/dense_inference.dll']}, 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 From 8d618cc8c775e2faaeffbe08fc354353eb8b50d0 Mon Sep 17 00:00:00 2001 From: Jacky Ko Date: Wed, 2 Aug 2017 19:47:14 +0800 Subject: [PATCH 2/7] readme update --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 6513131..ee48c6c 100644 --- a/readme.md +++ b/readme.md @@ -22,7 +22,7 @@ for more information. #### Requirements ``` -make, g++, boost-python +make, g++, boost-python, cmake ``` #### Requirements Python From 10fada865f2fb11fbedd59cdea3bde5205dff30a Mon Sep 17 00:00:00 2001 From: Jacky Ko Date: Wed, 2 Aug 2017 19:49:15 +0800 Subject: [PATCH 3/7] readme update --- readme.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/readme.md b/readme.md index ee48c6c..e89eb5c 100644 --- a/readme.md +++ b/readme.md @@ -44,7 +44,7 @@ sudo pip install . ``` #### 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) @@ -55,6 +55,7 @@ sudo pip install . 8. Open CMD at 9. pip install . (Permission error will occur if .sln file is open) 10. Copy boost_python-vc140-mt-1_64.dll at /lib64-msvc-14.0 to /Lib/site-packages/denseinference +``` ## Usage From 8f0b9d54ab216d70957cc7191411ec01768e63a9 Mon Sep 17 00:00:00 2001 From: Jacky Date: Wed, 2 Aug 2017 23:03:17 +0800 Subject: [PATCH 4/7] readme updated, not functioning --- denseinference/CRFProcessor.py | 11 +++++++---- denseinference/lib/refine_3d/CMakeLists.txt | 2 +- readme.md | 20 ++++++++++++-------- setup.py | 9 ++++++++- 4 files changed, 28 insertions(+), 14 deletions(-) diff --git a/denseinference/CRFProcessor.py b/denseinference/CRFProcessor.py index ecf1764..5c80e9c 100644 --- a/denseinference/CRFProcessor.py +++ b/denseinference/CRFProcessor.py @@ -2,14 +2,17 @@ import numpy as np import psutil - from ctypes import * +from sys import platform -di = cdll.LoadLibrary("lib/dense_inference.dll") +if platform == "linux" or platform == "linux2": + di_lib = 'lib/dense_inference.so' +elif platform == "win32": + di_lib = 'lib/dense_inference.dll' -# from denseinference.lib import dense_inference as di -# import dense_inference as di +di = cdll.LoadLibrary(di_lib) +# from denseinference.lib import dense_inference as di class CRF3DProcessor(object): # # diff --git a/denseinference/lib/refine_3d/CMakeLists.txt b/denseinference/lib/refine_3d/CMakeLists.txt index 4b8c04f..01f09ce 100644 --- a/denseinference/lib/refine_3d/CMakeLists.txt +++ b/denseinference/lib/refine_3d/CMakeLists.txt @@ -10,7 +10,7 @@ endif() set(CMAKE_BUILD_TYPE Release) #python -SET(Python_ADDITIONAL_VERSIONS 2) +# SET(Python_ADDITIONAL_VERSIONS 3) FIND_PACKAGE(PythonInterp REQUIRED) find_package(PythonLibs REQUIRED) include_directories(${PYTHON_INCLUDE_DIRS}) diff --git a/readme.md b/readme.md index e89eb5c..d3fa9bb 100644 --- a/readme.md +++ b/readme.md @@ -22,7 +22,7 @@ for more information. #### Requirements ``` -make, g++, boost-python, cmake +make, g++, boost-python, cmake, python 2 (python 3 has been tested with compliation fail), MSVC2015 (for windows) ``` #### Requirements Python @@ -43,18 +43,22 @@ make all sudo pip install . ``` -#### Installation (Tested on Windows with MSVC2015) +#### 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. Open .sln file in build folder -6. Build Release version -7. Copy /build/denseinference/lib/refine_3d/Release/dense_inference.dll to /denseinference -8. Open CMD at +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 + - 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 at /lib64-msvc-14.0 to /Lib/site-packages/denseinference +10. Copy boost_python-vc140-mt-1_64.dll (.so for linux) at /lib64-msvc-14.0 to /Lib/site-packages/denseinference ``` ## Usage @@ -88,4 +92,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 fcc257d..b026d22 100644 --- a/setup.py +++ b/setup.py @@ -1,9 +1,16 @@ from setuptools import setup, find_packages +from sys import platform + +if platform == "linux" or platform == "linux2": + package_data = 'lib/dense_inference.so' +elif platform == "win32": + package_data = 'lib/dense_inference.dll' + setup( name="DenseInferenceWrapper", version="1.0.0", packages=find_packages(), - package_data={'': ['lib/dense_inference.dll']}, + package_data={'': [package_data]}, include_package_data=True, url='', license='', From 56cf246297bbfb15bacbf073354907d58d98068a Mon Sep 17 00:00:00 2001 From: Jacky Date: Wed, 2 Aug 2017 23:29:00 +0800 Subject: [PATCH 5/7] update --- denseinference/CRFProcessor.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/denseinference/CRFProcessor.py b/denseinference/CRFProcessor.py index 5c80e9c..6610523 100644 --- a/denseinference/CRFProcessor.py +++ b/denseinference/CRFProcessor.py @@ -2,17 +2,17 @@ import numpy as np import psutil -from ctypes import * -from sys import platform +# from ctypes import * +# from sys import platform -if platform == "linux" or platform == "linux2": - di_lib = 'lib/dense_inference.so' -elif platform == "win32": - di_lib = 'lib/dense_inference.dll' +# if platform == "linux" or platform == "linux2": + # di_lib = 'lib/dense_inference.so' +# elif platform == "win32": +# di_lib = 'lib/dense_inference.dll' -di = cdll.LoadLibrary(di_lib) +# di = cdll.LoadLibrary(di_lib) -# from denseinference.lib import dense_inference as di +from denseinference.lib import dense_inference as di class CRF3DProcessor(object): # # From 1b26935b266abfe0310f7625d45afe28190b4b68 Mon Sep 17 00:00:00 2001 From: Jacky Ko Date: Thu, 3 Aug 2017 10:59:16 +0800 Subject: [PATCH 6/7] readme added pyd --- .gitignore | 1 + denseinference/CRFProcessor.py | 9 --------- readme.md | 3 ++- setup.py | 5 +---- 4 files changed, 4 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index 32bc52b..6647b70 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ .settings *.pyc +*.pyd *.o *.so diff --git a/denseinference/CRFProcessor.py b/denseinference/CRFProcessor.py index 6610523..1d0cea9 100644 --- a/denseinference/CRFProcessor.py +++ b/denseinference/CRFProcessor.py @@ -2,15 +2,6 @@ import numpy as np import psutil -# from ctypes import * -# from sys import platform - -# if platform == "linux" or platform == "linux2": - # di_lib = 'lib/dense_inference.so' -# elif platform == "win32": -# di_lib = 'lib/dense_inference.dll' - -# di = cdll.LoadLibrary(di_lib) from denseinference.lib import dense_inference as di diff --git a/readme.md b/readme.md index d3fa9bb..5e7f5ec 100644 --- a/readme.md +++ b/readme.md @@ -54,11 +54,12 @@ sudo pip install . 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 +10. Copy boost_python-vc140-mt-1_64.dll (.so for linux) at /lib64-msvc-14.0 to /Lib/site-packages/denseinference/lib ``` ## Usage diff --git a/setup.py b/setup.py index b026d22..febeb87 100644 --- a/setup.py +++ b/setup.py @@ -1,10 +1,7 @@ from setuptools import setup, find_packages from sys import platform -if platform == "linux" or platform == "linux2": - package_data = 'lib/dense_inference.so' -elif platform == "win32": - package_data = 'lib/dense_inference.dll' +package_data = 'lib/dense_inference.pyd' setup( name="DenseInferenceWrapper", From d01609afcd9c7536c492db94e62569b25b012280 Mon Sep 17 00:00:00 2001 From: Jacky Ko Date: Thu, 3 Aug 2017 11:04:54 +0800 Subject: [PATCH 7/7] readme updated --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 5e7f5ec..6ede656 100644 --- a/readme.md +++ b/readme.md @@ -22,7 +22,7 @@ for more information. #### Requirements ``` -make, g++, boost-python, cmake, python 2 (python 3 has been tested with compliation fail), MSVC2015 (for windows) +make, g++, boost-python, cmake, python 2 (python 3 has been tested with compilation fail), MSVC2015 (for windows) ``` #### Requirements Python