Starting to flesh out the python interface documentation a little more.

This commit is contained in:
Davis King 2013-05-26 14:21:02 -04:00
parent f02cf7ca64
commit 5597d9cb20
4 changed files with 95 additions and 0 deletions

View File

@ -4,6 +4,12 @@
# The macro takes the module name as its first argument and then a list of
# source files to compile into the module. See ../tools/python/CMakeLists.txt
# for an example.
#
# It also sets up a macro called install_${module_name}_to() where
# ${module_name} is whatever you named your module. This install_*_to() macro
# takes a folder name and creates an install target that will copy the compiled
# python module to that folder when you run "make install". Note that the path
# given to install_*_to() is relative to your CMakeLists.txt file.
set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH}
"C:/Program Files (x86)/boost/boost_1_*"
@ -54,5 +60,15 @@ macro(add_python_module module_name module_sources )
OUTPUT_NAME ${module_name}
)
endif()
macro(install_${module_name}_to path)
# Determine the path to our CMakeLists.txt file.
string(REPLACE "CMakeLists.txt" "" base_path ${CMAKE_CURRENT_LIST_FILE})
INSTALL(TARGETS ${module_name}_
LIBRARY DESTINATION ${base_path}/${path}
)
endmacro()
endmacro()

View File

@ -0,0 +1,4 @@
mkdir build
cd build
cmake ../../tools/python
cmake --build . --config Release --target install

View File

@ -0,0 +1,73 @@
# You need to compile the dlib python interface before you can use this
# file. To do this, run compile_dlib_python_module.bat. You also need to
# have the boost-python library installed. On Ubuntu, this can be done easily by running
# the command: sudo apt-get install libboost-python-dev
# asfd
import dlib
use_sparse_vects = False
if use_sparse_vects:
samples = dlib.sparse_vectorss()
else:
samples = dlib.vectorss()
segments = dlib.rangess()
if use_sparse_vects:
inside = dlib.sparse_vector()
outside = dlib.sparse_vector()
inside.append(dlib.pair(0,1))
outside.append(dlib.pair(1,1))
else:
inside = dlib.vector([0, 1])
outside = dlib.vector([1, 0])
samples.resize(2)
segments.resize(2)
samples[0].append(outside)
samples[0].append(outside)
samples[0].append(inside)
samples[0].append(inside)
samples[0].append(inside)
samples[0].append(outside)
samples[0].append(outside)
samples[0].append(outside)
segments[0]
segments[0].append(dlib.range(2,5))
samples[1].append(outside)
samples[1].append(outside)
samples[1].append(inside)
samples[1].append(inside)
samples[1].append(inside)
samples[1].append(inside)
samples[1].append(outside)
samples[1].append(outside)
segments[1].append(dlib.range(2,6))
params = dlib.segmenter_params()
#params.be_verbose = True
params.window_size = 1
params.use_high_order_features = False
params.C = 1
print "params:", params
df = dlib.train_sequence_segmenter(samples, segments, params)
print len(df.segment_sequence(samples[0]))
print df.segment_sequence(samples[0])[0]
print df.weights
#res = dlib.test_sequence_segmenter(df, samples, segments)
res = dlib.cross_validate_sequence_segmenter(samples, segments, 2, params)
print res

View File

@ -15,3 +15,5 @@ add_python_module(dlib
src/cca.cpp
src/sequence_segmenter.cpp
)
install_dlib_to(../../python_examples)