Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,15 @@
.settings

*.pyc
*.pyd

*.o
*.so
*.a
*.dll
*.lib

*~
*~

/build
/python
62 changes: 62 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
1 change: 1 addition & 0 deletions denseinference/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_subdirectory(lib)
3 changes: 1 addition & 2 deletions denseinference/CRFProcessor.py
Original file line number Diff line number Diff line change
@@ -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):
# #
#
Expand Down
3 changes: 3 additions & 0 deletions denseinference/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
add_subdirectory(libDenseCRF)
add_subdirectory(refine_3d)

2 changes: 1 addition & 1 deletion denseinference/lib/Makefile
Original file line number Diff line number Diff line change
@@ -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/

Expand Down
20 changes: 20 additions & 0 deletions denseinference/lib/libDenseCRF/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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})
10 changes: 5 additions & 5 deletions denseinference/lib/libDenseCRF/permutohedral.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 ***/
Expand Down
37 changes: 37 additions & 0 deletions denseinference/lib/refine_3d/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
25 changes: 22 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -35,14 +35,33 @@ numpy, psutil
matplotlib
```

#### Installation
#### Installation (Linux)

```bash
cd denseinferencewrapper
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-folder>/build/denseinference/lib/refine_3d/Release/dense_inference.dll (.so for linux) to <source-folder>/denseinference/lib
4. Rename the extension from .dll/.so to .pyd
- Linux
(To be updated...)
8. Open CMD/Terminal at <source-folder>
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 <boost-dir>/lib64-msvc-14.0 to <python-dir>/Lib/site-packages/denseinference/lib
```

## Usage

```python
Expand Down Expand Up @@ -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
10 changes: 7 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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.'
)