Bjoern Froehlich před 13 roky
rodič
revize
5015412af8

+ 1 - 1
progs/testSemanticSegmentation.cpp

@@ -272,7 +272,7 @@ int main( int argc, char **argv )
       double lsum = 0.0;
       for(int r2 = 0; r2 < ( int )M.rows(); r2++)
       {
-        lsum += M(r2,r);
+        lsum += M(r,r2);
       }
       if(lsum != 0.0)
       {

+ 105 - 29
semseg/SemSegContextTree.cpp

@@ -66,6 +66,29 @@ class ClassificationResultAcess: public ValueAccess
     }
 };
 
+class SparseImageAcess: public ValueAccess
+{
+  private:
+    double scale;
+
+  public:
+    virtual double getVal ( const Features &feats, const int &x, const int &y, const int &channel )
+    {
+      //MultiChannelImageT<SparseVector> textonMap;
+      //TODO: implement access
+    }
+
+    virtual string writeInfos()
+    {
+      return "context";
+    }
+
+    virtual ValueTypes getType()
+    {
+      return CONTEXT;
+    }
+};
+
 void Operation::restore ( std::istream &is )
 {
   is >> x1;
@@ -106,6 +129,57 @@ std::string Operation::writeInfos()
   return ss.str();
 }
 
+void Operation::set ( int ws, int c1size, int c2size, int c3size, bool useGaussian )
+{
+  int types = 1;
+  if ( c2size > 0 )
+  {
+    types++;
+  }
+  if ( c3size > 0 )
+  {
+    types++;
+  }
+  
+  types = std::min(types, maxtypes);
+
+  int ft = ( int ) ( ( double ) rand() / ( double ) RAND_MAX * ( double ) types );
+
+  if ( ft > 0 )
+  {
+    ws *= 4;
+  }
+
+  if ( useGaussian )
+  {
+    double sigma = ( double ) ws * 2.0;
+    x1 = randGaussDouble ( sigma ) * ( double ) ws;
+    x2 = randGaussDouble ( sigma ) * ( double ) ws;
+    y1 = randGaussDouble ( sigma ) * ( double ) ws;
+    y2 = randGaussDouble ( sigma ) * ( double ) ws;
+  }
+  else
+  {
+    x1 = ( int ) ( ( double ) rand() / ( double ) RAND_MAX * ( double ) ws ) - ws / 2;
+    x2 = ( int ) ( ( double ) rand() / ( double ) RAND_MAX * ( double ) ws ) - ws / 2;
+    y1 = ( int ) ( ( double ) rand() / ( double ) RAND_MAX * ( double ) ws ) - ws / 2;
+    y2 = ( int ) ( ( double ) rand() / ( double ) RAND_MAX * ( double ) ws ) - ws / 2;
+  }
+
+  if ( ft == RAWFEAT )
+  {
+    values = new MCImageAccess();
+  }
+  else if ( ft == CONTEXT )
+  {
+    values = new ClassificationResultAcess();
+  }
+  else
+  {
+    values = new SparseImageAcess();
+  }
+}
+
 class Minus: public Operation
 {
   public:
@@ -130,7 +204,7 @@ class Minus: public Operation
       if ( values != NULL )
         out += values->writeInfos();
 
-      return out+Operation::writeInfos();
+      return out + Operation::writeInfos();
     }
 
     virtual OperationTypes getOps()
@@ -139,6 +213,8 @@ class Minus: public Operation
     }
 };
 
+
+
 class MinusAbs: public Operation
 {
 
@@ -199,7 +275,7 @@ class Addition: public Operation
       if ( values != NULL )
         out += values->writeInfos();
 
-      return out+Operation::writeInfos();
+      return out + Operation::writeInfos();
     }
 
     virtual OperationTypes getOps()
@@ -232,7 +308,7 @@ class Only1: public Operation
       if ( values != NULL )
         out += values->writeInfos();
 
-      return out+Operation::writeInfos();
+      return out + Operation::writeInfos();
     }
 
     virtual OperationTypes getOps()
@@ -259,7 +335,7 @@ class RelativeXPosition: public Operation
 
     virtual string writeInfos()
     {
-      return "RelativeXPosition"+Operation::writeInfos();
+      return "RelativeXPosition" + Operation::writeInfos();
     }
 
     virtual OperationTypes getOps()
@@ -286,7 +362,7 @@ class RelativeYPosition: public Operation
 
     virtual string writeInfos()
     {
-      return "RelativeYPosition"+Operation::writeInfos();
+      return "RelativeYPosition" + Operation::writeInfos();
     }
 
     virtual OperationTypes getOps()
@@ -340,7 +416,7 @@ class IntegralOps: public Operation
 
     virtual string writeInfos()
     {
-      return "IntegralOps"+Operation::writeInfos();
+      return "IntegralOps" + Operation::writeInfos();
     }
 
     virtual OperationTypes getOps()
@@ -369,7 +445,7 @@ class GlobalFeats: public IntegralOps
 
     virtual string writeInfos()
     {
-      return "GlobalFeats"+Operation::writeInfos();
+      return "GlobalFeats" + Operation::writeInfos();
     }
 
     virtual OperationTypes getOps()
@@ -409,7 +485,7 @@ class IntegralCenteredOps: public IntegralOps
 
     virtual string writeInfos()
     {
-      return "IntegralCenteredOps"+Operation::writeInfos();
+      return "IntegralCenteredOps" + Operation::writeInfos();
     }
 
     virtual OperationTypes getOps()
@@ -449,7 +525,7 @@ class BiIntegralCenteredOps: public IntegralCenteredOps
 
     virtual string writeInfos()
     {
-      return "BiIntegralCenteredOps"+Operation::writeInfos();
+      return "BiIntegralCenteredOps" + Operation::writeInfos();
     }
 
     virtual OperationTypes getOps()
@@ -485,7 +561,7 @@ class HaarHorizontal: public IntegralCenteredOps
 
     virtual string writeInfos()
     {
-      return "HaarHorizontal"+Operation::writeInfos();
+      return "HaarHorizontal" + Operation::writeInfos();
     }
 
     virtual OperationTypes getOps()
@@ -521,7 +597,7 @@ class HaarVertical: public IntegralCenteredOps
 
     virtual string writeInfos()
     {
-      return "HaarVertical"+Operation::writeInfos();
+      return "HaarVertical" + Operation::writeInfos();
     }
 
     virtual OperationTypes getOps()
@@ -557,7 +633,7 @@ class HaarDiag: public IntegralCenteredOps
 
     virtual string writeInfos()
     {
-      return "HaarDiag"+Operation::writeInfos();
+      return "HaarDiag" + Operation::writeInfos();
     }
 
     virtual OperationTypes getOps()
@@ -596,7 +672,7 @@ class Haar3Horiz: public BiIntegralCenteredOps
 
     virtual string writeInfos()
     {
-      return "Haar3Horiz"+Operation::writeInfos();
+      return "Haar3Horiz" + Operation::writeInfos();
     }
 
     virtual OperationTypes getOps()
@@ -635,7 +711,7 @@ class Haar3Vert: public BiIntegralCenteredOps
 
     virtual string writeInfos()
     {
-      return "Haar3Vert"+Operation::writeInfos();
+      return "Haar3Vert" + Operation::writeInfos();
     }
 
     virtual OperationTypes getOps()
@@ -819,10 +895,10 @@ double SemSegContextTree::getBestSplit ( std::vector<NICE::MultiChannelImageT<do
         {
           int cn = labels[iCounter] ( x, y );
           double randD = ( double ) rand() / ( double ) RAND_MAX;
-          
-          if(labelmap.find(cn) == labelmap.end())
+
+          if ( labelmap.find ( cn ) == labelmap.end() )
             continue;
-          
+
           if ( randD < fraction[labelmap[cn]] )
           {
             vector<int> tmp ( 3, 0 );
@@ -880,7 +956,7 @@ double SemSegContextTree::getBestSplit ( std::vector<NICE::MultiChannelImageT<do
 
     if ( useGaussian )
     {
-      double sigma = ( double ) tmpws / 2.0;
+      double sigma = ( double ) tmpws * 2.0;
       x1 = randGaussDouble ( sigma ) * ( double ) tmpws;
       x2 = randGaussDouble ( sigma ) * ( double ) tmpws;
       y1 = randGaussDouble ( sigma ) * ( double ) tmpws;
@@ -1343,8 +1419,8 @@ void SemSegContextTree::train ( const MultiDataset *md )
       {
         featcounter++;
         int cn = labels[iCounter] ( x, y );
-        if(labelmap.find(cn) == labelmap.end())
-            continue;
+        if ( labelmap.find ( cn ) == labelmap.end() )
+          continue;
         a[labelmap[cn]] ++;
       }
     }
@@ -1495,7 +1571,7 @@ void SemSegContextTree::train ( const MultiDataset *md )
                     if ( val < splitval )
                     {
                       currentfeats[iCounter].set ( x, y, left, tree );
-                      if(labelmap.find(labels[iCounter] ( x, y )) != labelmap.end())
+                      if ( labelmap.find ( labels[iCounter] ( x, y ) ) != labelmap.end() )
                         forest[tree][left].dist[labelmap[labels[iCounter] ( x, y ) ]]++;
                       forest[tree][left].featcounter++;
                       SparseVector v;
@@ -1505,7 +1581,7 @@ void SemSegContextTree::train ( const MultiDataset *md )
                     else
                     {
                       currentfeats[iCounter].set ( x, y, right, tree );
-                      if(labelmap.find(labels[iCounter] ( x, y )) != labelmap.end())
+                      if ( labelmap.find ( labels[iCounter] ( x, y ) ) != labelmap.end() )
                         forest[tree][right].dist[labelmap[labels[iCounter] ( x, y ) ]]++;
                       forest[tree][right].featcounter++;
                       //feld im subsampled finden und in diesem rechts hochzählen
@@ -1699,7 +1775,7 @@ void SemSegContextTree::semanticseg ( CachedExample *ce, NICE::Image & segresult
   int xpos = 8;
   //int xpos = 15;
   int ypos = 78;
-  
+
   int xsize;
   int ysize;
   ce->getImageSize ( xsize, ysize );
@@ -1802,11 +1878,11 @@ void SemSegContextTree::semanticseg ( CachedExample *ce, NICE::Image & segresult
               v.insert ( pair<int, double> ( forest[tree][forest[tree][t].right].nodeNumber, 1.0 ) );
               textonMap ( subx, suby ).add ( v );
             }
-            
-            if(x == xpos && y == ypos)
+
+            if ( x == xpos && y == ypos )
             {
               cout << "val: " << val << " decision: " << forest[tree][t].decision << " details: " << forest[tree][t].feat->writeInfos() << endl;
-              
+
             }
           }
         }
@@ -1832,7 +1908,7 @@ void SemSegContextTree::semanticseg ( CachedExample *ce, NICE::Image & segresult
     depth++;
   }
 
-cout << forest[0][currentfeats.get ( xpos, ypos, 0 )].dist << endl;
+  cout << forest[0][currentfeats.get ( xpos, ypos, 0 ) ].dist << endl;
 
   if ( pixelWiseLabeling )
   {
@@ -2026,10 +2102,10 @@ void SemSegContextTree::restore ( std::istream & is, int format )
       is >> forest[t][n].isleaf;
       is >> forest[t][n].depth;
       is >> forest[t][n].featcounter;
-      
+
       is >> forest[t][n].nodeNumber;
       is >> forest[t][n].dist;
-      
+
       int feattype;
       is >> feattype;
       assert ( feattype < NBOPERATIONS );

+ 24 - 20
semseg/SemSegContextTree.h

@@ -44,7 +44,7 @@ class TreeNode
 
     /** how many pixels are in this node */
     int featcounter;
-    
+
     /** unique number */
     int nodeNumber;
 
@@ -67,6 +67,7 @@ enum ValueTypes
 {
   RAWFEAT,
   CONTEXT,
+  SPARSE,
   NBVALUETYPES
 };
 
@@ -104,9 +105,9 @@ class Operation
 {
 
   protected:
-    int x1, y1, x2, y2, channel1, channel2;
+    int x1, y1, x2, y2, channel1, channel2, maxtypes;
     ValueAccess *values;
-    
+
     bool context;
 
   public:
@@ -114,6 +115,7 @@ class Operation
     Operation()
     {
       values = NULL;
+      maxtypes = 1000;
     }
 
     virtual void set ( int _x1, int _y1, int _x2, int _y2, int _channel1, int _channel2, ValueAccess *_values )
@@ -126,12 +128,14 @@ class Operation
       channel2 = _channel2;
       values = _values;
     }
-    
-    void setContext(bool _context)
+
+    virtual void set ( int ws, int c1size, int c2size, int c3size, bool useGaussian );
+
+    void setContext ( bool _context )
     {
       context = _context;
     }
-    
+
     bool getContext()
     {
       return context;
@@ -157,17 +161,17 @@ class Operation
     }
 
     virtual OperationTypes getOps() = 0;
-    
-    virtual void store(std::ostream & os)
+
+    virtual void store ( std::ostream & os )
     {
       os << x1 << " " << x2 << " " << y1 << " " << y2 << " " << channel1 << " " << channel2 << std::endl;
-      if(values == NULL)
+      if ( values == NULL )
         os << -1 << std::endl;
       else
         os << values->getType() << std::endl;
     }
-    
-    virtual void restore(std::istream & is);
+
+    virtual void restore ( std::istream & is );
 };
 
 /** Localization system */
@@ -212,7 +216,7 @@ class SemSegContextTree : public SemanticSegmentation, public NICE::Persistent
 
     /** counter for used operations */
     std::vector<int> opOverview;
-    
+
     /** relative use of context vs raw features per tree level*/
     std::vector<std::vector<double> > contextOverview;
 
@@ -224,7 +228,7 @@ class SemSegContextTree : public SemanticSegmentation, public NICE::Persistent
 
     /** current depth for training */
     int depth;
-    
+
     /** how many splittests */
     int randomTests;
 
@@ -290,7 +294,7 @@ class SemSegContextTree : public SemanticSegmentation, public NICE::Persistent
      * @return void
      **/
     void computeIntegralImage ( const NICE::MultiChannelImageT<unsigned short int> &currentfeats, const NICE::MultiChannelImageT<double> &lfeats, NICE::MultiChannelImageT<double> &integralImage );
-    
+
     /**
      * @brief computes integral image for Sparse Multichannel Image
      *
@@ -329,8 +333,8 @@ class SemSegContextTree : public SemanticSegmentation, public NICE::Persistent
      * @param format has no influence
      * @return void
      **/
-    virtual void restore (std::istream & is, int format = 0);
-    
+    virtual void restore ( std::istream & is, int format = 0 );
+
     /**
      * @brief save all data to is stream
      *
@@ -338,15 +342,15 @@ class SemSegContextTree : public SemanticSegmentation, public NICE::Persistent
      * @param format has no influence
      * @return void
      **/
-    virtual void store (std::ostream & os, int format = 0) const;
-   
+    virtual void store ( std::ostream & os, int format = 0 ) const;
+
     /**
      * @brief clean up
      *
      * @return void
      **/
-    virtual void clear (){}
-    
+    virtual void clear () {}
+
 };
 
 

+ 2 - 0
semseg/SemSegCsurka.cpp

@@ -118,6 +118,8 @@ SemSegCsurka::SemSegCsurka ( const Config *conf,
     classifier = new FPCRandomForests ( conf, "ClassifierForest" );
   else if ( cname == "SMLR" )
     classifier = new FPCSMLR ( conf, "ClassifierSMLR" );
+  else if ( cname == "GPHIK")
+    classifier = new GPHIKClassifier(conf, "ClassiferGPHIK");
   else
     vclassifier = CSGeneric::selectVecClassifier ( conf, "main" );
   //classifier = new FPCSparseMultinomialLogisticRegression(conf, "ClassifierSMLR");

+ 1 - 0
semseg/SemSegCsurka.h

@@ -36,6 +36,7 @@
 
 #include "vislearning/classifier/fpclassifier/randomforest/FPCRandomForests.h"
 #include "vislearning/classifier/fpclassifier/logisticregression/FPCSMLR.h"
+#include "fast-hik/GPHIKClassifier.h"
 
 #include "objrec-froehlichexp/semseg/postsegmentation/PSSImageLevelPrior.h"
 #include "objrec-froehlichexp/semseg/postsegmentation/RelativeLocationPrior.h"

+ 1 - 0
semseg/libdepend.inc

@@ -4,4 +4,5 @@ $(call PKG_DEPEND_INT,objrec/segmentation)
 $(call PKG_DEPEND_INT,objrec/fourier)
 $(call PKG_DEPEND_INT,objrec/features)
 $(call PKG_DEPEND_INT,objrec/semanticsegmentation)
+$(call PKG_DEPEND_INT,fast-hik)
 #$(call PKG_DEPEND_INT,objrec-froehlichexp/classifier)