[opengm] 166/386: more learners can be used
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Wed Aug 31 08:37:12 UTC 2016
This is an automated email from the git hooks/post-receive script.
ghisvail-guest pushed a commit to branch debian/master
in repository opengm.
commit fa7be11b4e5c22d99bed933108e5ce9ef0904a1c
Author: DerThorsten <thorsten.beier at iwr.uni-heidelberg.de>
Date: Fri Dec 19 15:02:41 2014 +0100
more learners can be used
---
fubar/real_example_2.py | 18 ++++++--
include/opengm/learning/gridsearch-learning.hxx | 23 +++++++----
.../python/opengm/learning/CMakeLists.txt | 48 ++++++++++++++++++++++
src/interfaces/python/opengm/learning/helper.hxx | 24 +++++++++++
.../python/opengm/learning/pyGridSearchLearner.cxx | 1 +
.../opengm/learning/pyStructMaxMarginLearner.cxx | 1 +
6 files changed, 103 insertions(+), 12 deletions(-)
diff --git a/fubar/real_example_2.py b/fubar/real_example_2.py
index a2974d8..d0b4230 100644
--- a/fubar/real_example_2.py
+++ b/fubar/real_example_2.py
@@ -3,10 +3,11 @@ import opengm.learning as learning
from opengm import numpy
import vigra
import pylab as plt
+import pylab
-nModels =1
+nModels = 3
nLables = 2
-shape = [10, 10]
+shape = [20, 20]
numVar = shape[0]*shape[1]
sSmooth = [1.0, 1.5]
@@ -34,13 +35,22 @@ dataset = learning.createDataset(numWeights=nWeights, loss='h')
weights = dataset.getWeights()
def makeFeatures(gt):
- random = numpy.random.rand(*gt.shape)-0.5
+ random = (numpy.random.rand(*gt.shape)-0.5)*5.0
randGt = random + gt
#vigra.imshow(randGt)
#plt.colorbar()
#vigra.show()
+ f = pylab.figure()
+ for n, a in enumerate([gt, randGt]):
+ f.add_subplot(2, 1, n) # this line outputs images on top of each other
+ # f.add_subplot(1, 2, n) # this line outputs images side-by-side
+ pylab.imshow(a,cmap='gray')
+ pylab.title('Double image')
+ pylab.show()
+
+
feat = []
for sigma in sSmooth:
@@ -121,7 +131,7 @@ nTestPoints =numpy.ones(nWeights).astype('uint64')*5
learner = learning.gridSearchLearner(dataset=dataset,lowerBounds=lowerBounds, upperBounds=upperBounds,nTestPoints=nTestPoints)
#learner = learning.structMaxMarginLearner(dataset, 1.0, 0.001, 0)
-learner.learn(infCls=opengm.inference.Icm,
+learner.learn(infCls=opengm.inference.TrwsExternal,
parameter=opengm.InfParam())
for w in range(nWeights):
diff --git a/include/opengm/learning/gridsearch-learning.hxx b/include/opengm/learning/gridsearch-learning.hxx
index 3105c3d..def2990 100644
--- a/include/opengm/learning/gridsearch-learning.hxx
+++ b/include/opengm/learning/gridsearch-learning.hxx
@@ -86,17 +86,24 @@ namespace opengm {
loss += lossFunction.loss(dataset_.getModel(m),confs[m].begin(), confs[m].end(), gt.begin(), gt.end());
}
- // *call visitor*
- for(size_t p=0; p<dataset_.getNumberOfWeights(); ++p){
- std::cout << modelPara[p] <<" ";
- }
- std::cout << " ==> ";
- std::cout << loss << std::endl;
+
+
// **************
if(loss<bestLoss){
- bestLoss=loss;
- bestModelPara=modelPara;
+
+ // *call visitor*
+ for(size_t p=0; p<dataset_.getNumberOfWeights(); ++p){
+ std::cout << modelPara[p] <<" ";
+ }
+ std::cout << " ==> ";
+ std::cout << loss << std::endl;
+
+ bestLoss=loss;
+ bestModelPara=modelPara;
+ if(loss<=0.000000001){
+ search = false;
+ }
}
//Increment Parameter
for(size_t p=0; p<dataset_.getNumberOfWeights(); ++p){
diff --git a/src/interfaces/python/opengm/learning/CMakeLists.txt b/src/interfaces/python/opengm/learning/CMakeLists.txt
index dbc2703..0ca1ec1 100644
--- a/src/interfaces/python/opengm/learning/CMakeLists.txt
+++ b/src/interfaces/python/opengm/learning/CMakeLists.txt
@@ -64,6 +64,54 @@ ENDIF()
target_link_libraries(_learning ${HDF5_CORE_LIBRARY} ${HDF5_LIBRARIES} )
+
+
+if(WITH_LIBDAI)
+ target_link_libraries(_learning ${LIBDAI_LIBRARY})
+ target_link_libraries(_learning ${GMPXX_LIBRARY})
+ target_link_libraries(_learning ${GMP_LIBRARY})
+endif()
+
+if(WITH_QPBO)
+ target_link_libraries(_learning external-library-qpbo-shared)
+endif()
+
+if(WITH_MAXFLOW)
+ target_link_libraries(_learning external-library-maxflow-shared)
+endif()
+
+if(WITH_MAXFLOW_IBFS)
+ target_link_libraries(_learning external-library-maxflow-ibfs-shared)
+endif()
+
+if(WITH_TRWS)
+ target_link_libraries(_learning external-library-trws-shared)
+endif()
+
+
+if(WITH_FASTPD)
+ target_link_libraries(_learning external-library-fastpd-shared)
+endif()
+
+if(WITH_AD3)
+ target_link_libraries(_learning external-library-ad3-shared )
+endif()
+
+#SET(LINK_FLAGS "${LINK_FLAGS} -PIC")
+#SET_TARGET_PROPERTIES(_learning PROPERTIES LINK_FLAGS "-fPIC")
+#add_definitions(-fPIC)
+
+if(WITH_CONICBUNDLE)
+ #target_link_libraries(_learning ${CONICBUNDLE_LIBRARY})
+endif()
+
+if(WITH_MRF)
+ target_link_libraries(_learning external-library-mrf-shared)
+endif()
+
+
+
+
if(WITH_CPLEX)
if(WIN32)
target_link_libraries(_learning wsock32.lib ${CPLEX_ILOCPLEX_LIBRARY} ${CPLEX_LIBRARY} ${CPLEX_CONCERT_LIBRARY})
diff --git a/src/interfaces/python/opengm/learning/helper.hxx b/src/interfaces/python/opengm/learning/helper.hxx
index 08832fd..bb29616 100644
--- a/src/interfaces/python/opengm/learning/helper.hxx
+++ b/src/interfaces/python/opengm/learning/helper.hxx
@@ -8,6 +8,7 @@
#include <opengm/python/numpyview.hxx>
#include <opengm/inference/icm.hxx>
+#include <opengm/inference/lazyflipper.hxx>
#include <opengm/learning/gridsearch-learning.hxx>
#include <opengm/inference/messagepassing/messagepassing.hxx>
@@ -15,6 +16,15 @@
#include <opengm/inference/lpcplex.hxx>
#endif
+#ifdef WITH_QPBO
+#include <opengm/inference/external/qpbo.hxx>
+#endif
+
+#ifdef WITH_TRWS
+#include <opengm/inference/external/trws.hxx>
+#endif
+
+
namespace opengm{
template<class LEARNER>
@@ -41,19 +51,33 @@ public:
typedef opengm::Minimizer ACC;
typedef opengm::ICM<GMType, ACC> IcmInf;
+ typedef opengm::LazyFlipper<GMType, ACC> LazyFlipperInf;
typedef opengm::BeliefPropagationUpdateRules<GMType, ACC> UpdateRulesType;
typedef opengm::MessagePassing<GMType, ACC, UpdateRulesType, opengm::MaxDistance> BpInf;
#ifdef WITH_CPLEX
typedef opengm::LPCplex<GMType, ACC> Cplex;
#endif
+#ifdef WITH_QPBO
+ typedef opengm::external::QPBO<GMType> QpboExternal;
+#endif
+#ifdef WITH_QPBO
+ typedef opengm::external::TRWS<GMType> TrwsExternal;
+#endif
c
.def("_learn",&pyLearnWithInf<IcmInf>)
+ .def("_learn",&pyLearnWithInf<LazyFlipperInf>)
.def("_learn",&pyLearnWithInf<BpInf>)
#ifdef WITH_CPLEX
.def("_learn",&pyLearnWithInf<Cplex>)
#endif
+#ifdef WITH_QPBO
+ .def("_learn",&pyLearnWithInf<QpboExternal>)
+#endif
+#ifdef WITH_TRWS
+ .def("_learn",&pyLearnWithInf<TrwsExternal>)
+#endif
;
}
};
diff --git a/src/interfaces/python/opengm/learning/pyGridSearchLearner.cxx b/src/interfaces/python/opengm/learning/pyGridSearchLearner.cxx
index 20cf28d..9e4eccf 100644
--- a/src/interfaces/python/opengm/learning/pyGridSearchLearner.cxx
+++ b/src/interfaces/python/opengm/learning/pyGridSearchLearner.cxx
@@ -4,6 +4,7 @@
#include <opengm/python/converter.hxx>
#include <opengm/python/numpyview.hxx>
+#define DefaultErrorFn DefaultErrorFn_TrwsExternalB
#include "helper.hxx"
namespace bp = boost::python;
diff --git a/src/interfaces/python/opengm/learning/pyStructMaxMarginLearner.cxx b/src/interfaces/python/opengm/learning/pyStructMaxMarginLearner.cxx
index f710220..8173733 100644
--- a/src/interfaces/python/opengm/learning/pyStructMaxMarginLearner.cxx
+++ b/src/interfaces/python/opengm/learning/pyStructMaxMarginLearner.cxx
@@ -9,6 +9,7 @@
#include <opengm/inference/icm.hxx>
#include <opengm/learning/struct-max-margin.hxx>
+#define DefaultErrorFn DefaultErrorFn_TrwsExternalA
#include "helper.hxx"
namespace bp = boost::python;
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/opengm.git
More information about the debian-science-commits
mailing list