[opengm] 159/386: Update dataset constructor on python side to set up the weights vector as well

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Wed Aug 31 08:37:01 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 5f57813563ffc2062800fd78bb9c1b2aa03f0bff
Author: Carsten Haubold <carstenhaubold at googlemail.com>
Date:   Fri Dec 19 13:49:34 2014 +0100

    Update dataset constructor on python side to set up the weights vector as well
---
 fubar/real_example.py                             | 21 ++-------------------
 src/interfaces/python/opengm/learning/__init__.py | 13 +++++++++----
 2 files changed, 11 insertions(+), 23 deletions(-)

diff --git a/fubar/real_example.py b/fubar/real_example.py
index 429473a..f21fe37 100644
--- a/fubar/real_example.py
+++ b/fubar/real_example.py
@@ -14,21 +14,13 @@ def makeGt(shape):
     gt[0:shape[0]/2,:] = 0
     return gt
 
-
-
-weightVals = numpy.ones(nWeights)
-weights = opengm.learning.Weights(weightVals)
-
 uWeightIds = numpy.arange(4,dtype='uint64').reshape(2,2)
-
-
 print uWeightIds
 
 bWeightIds = numpy.array([4,5,6],dtype='uint64')
 
-dataset = learning.createDataset(loss='h')
-dataset.setWeights(weights)
-
+dataset = learning.createDataset(numWeights=nWeights, loss='h')
+weights = dataset.getWeights()
 
 def makeFeatures(gt):
     random  = numpy.random.rand(*gt.shape)-0.5
@@ -58,18 +50,11 @@ for mi in range(nModels):
 
     # print unaries, binaries
 
-
     for x in range(shape[0]):
         for y in range(shape[1]):
-            #uFeat = numpy.append(unaries[x,y,:], [1]).astype(opengm.value_type)
             uFeat = unaries[x,y,:].astype("float64")
             uFeat = numpy.repeat(uFeat[:,numpy.newaxis],2,axis=1).T
             uFeat[1,:]=1
-            #sys.exit()
-            #print(unaries[x,y,:])
-            #print(unaries.shape)
-            #print(uFeat)
-            #print(uFeat.shape)
 
             lu = opengm.LUnaryFunction(weights=weights,numberOfLabels=nLables, features=uFeat, weightIds=uWeightIds)
 
@@ -95,8 +80,6 @@ for mi in range(nModels):
     dataset.pushBackInstance(gm,gtFlat.astype(opengm.label_type))
     backGt = dataset.getGT(0)
 
-    #print "back",backGt
-    #sys.exit()
 
 # for grid search learner
 lowerBounds = numpy.ones(nWeights)*-1.0
diff --git a/src/interfaces/python/opengm/learning/__init__.py b/src/interfaces/python/opengm/learning/__init__.py
index 5a41368..67b4892 100644
--- a/src/interfaces/python/opengm/learning/__init__.py
+++ b/src/interfaces/python/opengm/learning/__init__.py
@@ -24,18 +24,23 @@ if opengmConfig.withCplex or opengmConfig.withGurobi :
     StructMaxMargin_Bundle_HammingLoss.learn = _extendedLearn
     StructMaxMargin_Bundle_GeneralizedHammingLoss = _extendedLearn
         
-def createDataset(loss='hamming', numInstances=0):
-    
+def createDataset(numWeights, loss='hamming', numInstances=0):
+    weightVals = numpy.ones(numWeights)
+    weights = Weights(weightVals)
+
     if loss not in ['hamming','h','gh','generalized-hamming']:
         raise RuntimeError("loss must be 'hamming' /'h' or 'generalized-hamming'/'gh' ")    
 
     if loss in ['hamming','h']:
-        return DatasetWithHammingLoss(int(numInstances))
+        dataset = DatasetWithHammingLoss(int(numInstances))
     elif loss in ['generalized-hamming','gh']:
-        return DatasetWithGeneralizedHammingLoss(int(numInstances))
+        dataset = DatasetWithGeneralizedHammingLoss(int(numInstances))
     else:
         raise RuntimeError("loss must be 'hamming' /'h' or 'generalized-hamming'/'gh' ")   
 
+    dataset.setWeights(weights)
+    return dataset
+
 
 
 

-- 
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