Browse Source

current version

Bjoern Froehlich 13 years ago
parent
commit
22dab1af2d
2 changed files with 143 additions and 157 deletions
  1. 5 19
      semseg/SemSegCsurka.cpp
  2. 138 138
      semseg/SemanticSegmentation.cpp

+ 5 - 19
semseg/SemSegCsurka.cpp

@@ -64,9 +64,7 @@ SemSegCsurka::SemSegCsurka ( const Config *conf,
   usecolorfeats = conf->gB ( "SemSegCsurka", "usecolorfeats", false );
 
   string rsMethod = conf->gS ( "SemSegCsurka", "segmentation", "meanshift" );
-
-
-
+  
   g = NULL;
   k = NULL;
   relloc = NULL;
@@ -1489,32 +1487,21 @@ void SemSegCsurka::classifyregions ( CachedExample *ce, NICE::Image & segresult,
   {
     clog << "[log] SemSegCsruka::classifyregions: Wahrscheinlichkeitskarten erstellen: classifier != NULL" << endl;
 //#pragma omp parallel for
-    
-    int equalcounter = 0;
-    
-    
     for ( int s = 0; s < scalesize; s++ )
     {
 //#pragma omp parallel for
       for ( int i = s; i < ( int ) pce.size(); i += scalesize )
       {
         ClassificationResult r = classifier->classify ( pce[i].second );
-        
-        bool equal = true;
-        
-        double prev = r.scores[0];
-        
+              
         for ( int j = 0 ; j < r.scores.size(); j++ )
         {
           if ( useclass[j] == 0 )
             continue;
           fV[j] += r.scores[j];
           preMap.set ( pce[i].second.x, pce[i].second.y, r.scores[j], j + s*klassen );
-          if(r.scores[j] != prev)
-            equal = false;
         }
-        if(equal)
-          equalcounter++;
+
         if(s == 0 && i == pce.size()/2)
         {
           cout << "scores: ";
@@ -1529,14 +1516,13 @@ void SemSegCsurka::classifyregions ( CachedExample *ce, NICE::Image & segresult,
         
       }
     }
-    cout << equalcounter << " elements are equaly classified" << endl;
   }
   else
   {
-////#pragma omp parallel for
+//#pragma omp parallel for
     for ( int s = 0; s < scalesize; s++ )
     {
-////#pragma omp parallel for
+//#pragma omp parallel for
       for ( int i = s; i < ( int ) pce.size(); i += scalesize )
       {
         ClassificationResult r = vclassifier->classify ( * ( pce[i].second.vec ) );

+ 138 - 138
semseg/SemanticSegmentation.cpp

@@ -1,4 +1,4 @@
-/** 
+/**
 * @file SemanticSegmentation.cpp
 * @brief abstract interface for semantic segmentation algorithms
 * @author Erik Rodner
@@ -15,146 +15,146 @@ using namespace OBJREC;
 using namespace std;
 using namespace NICE;
 
-void SemanticSegmentation::convertLSetToSparseExamples(Examples &examples, LabeledSetVector &lvec)
+void SemanticSegmentation::convertLSetToSparseExamples ( Examples &examples, LabeledSetVector &lvec )
 {
-	#ifdef DEBUG_PRINTS
-	cout << "SemSegRegionBased::convertLSetToExamples starts" << endl;
-	#endif
-	for( map< int, vector<NICE::Vector *> >::iterator iter = lvec.begin(); iter != lvec.end(); ++iter ) 
-	{
-		for(int j = 0; j < (int)iter->second.size(); j++)
-		{
-			Vector &tmp = *(iter->second[j]);
-			int dim = tmp.size();
-			SparseVector *vec = new SparseVector(dim);
-			for(int j = 0; j < dim; j++)
-			{
-				if(tmp[j] != 0.0)
-				{
-					(*vec)[j] = tmp[j];
-				}
-			}
-			Example ex;
-			ex.svec = vec;
-			examples.push_back(pair<int, Example> ( iter->first, ex));
-		}
-	}	
-	lvec.clear();
-	#ifdef DEBUG_PRINTS
-	cout << "SemSegRegionBased::convertLSetToExamples finished" << endl;
-	#endif
+#ifdef DEBUG_PRINTS
+  cout << "SemSegRegionBased::convertLSetToExamples starts" << endl;
+#endif
+  for ( map< int, vector<NICE::Vector *> >::iterator iter = lvec.begin(); iter != lvec.end(); ++iter )
+  {
+    for ( int j = 0; j < ( int ) iter->second.size(); j++ )
+    {
+      Vector &tmp = * ( iter->second[j] );
+      int dim = tmp.size();
+      SparseVector *vec = new SparseVector ( dim );
+      for ( int j = 0; j < dim; j++ )
+      {
+        if ( tmp[j] != 0.0 )
+        {
+          ( *vec ) [j] = tmp[j];
+        }
+      }
+      Example ex;
+      ex.svec = vec;
+      examples.push_back ( pair<int, Example> ( iter->first, ex ) );
+    }
+  }
+  lvec.clear();
+#ifdef DEBUG_PRINTS
+  cout << "SemSegRegionBased::convertLSetToExamples finished" << endl;
+#endif
 }
 
-void SemanticSegmentation::convertLSetToExamples(Examples &examples, LabeledSetVector &lvec)
+void SemanticSegmentation::convertLSetToExamples ( Examples &examples, LabeledSetVector &lvec )
 {
-	#ifdef DEBUG_PRINTS
-	cout << "SemSegRegionBased::convertLSetToExamples starts" << endl;
-	#endif
-	for( map< int, vector<NICE::Vector *> >::iterator iter = lvec.begin(); iter != lvec.end(); ++iter ) 
-	{
-		for(int j = 0; j < iter->second.size(); j++)
-		{
-			NICE::Vector *vec = new NICE::Vector(*(iter->second[j]));
-			Example ex(vec);
-			examples.push_back(pair<int, Example> ( iter->first, ex));
-		}
-	}	
-	lvec.clear();
-	#ifdef DEBUG_PRINTS
-	cout << "SemSegRegionBased::convertLSetToExamples finished" << endl;
-	#endif
+#ifdef DEBUG_PRINTS
+  cout << "SemSegRegionBased::convertLSetToExamples starts" << endl;
+#endif
+  for ( map< int, vector<NICE::Vector *> >::iterator iter = lvec.begin(); iter != lvec.end(); ++iter )
+  {
+    for ( int j = 0; j < iter->second.size(); j++ )
+    {
+      NICE::Vector *vec = new NICE::Vector ( * ( iter->second[j] ) );
+      Example ex ( vec );
+      examples.push_back ( pair<int, Example> ( iter->first, ex ) );
+    }
+  }
+  lvec.clear();
+#ifdef DEBUG_PRINTS
+  cout << "SemSegRegionBased::convertLSetToExamples finished" << endl;
+#endif
 }
 
-void SemanticSegmentation::convertExamplesToLSet(Examples &examples, LabeledSetVector &lvec)
+void SemanticSegmentation::convertExamplesToLSet ( Examples &examples, LabeledSetVector &lvec )
 {
-	#ifdef DEBUG_PRINTS
-	cout << "SemSegRegionBased::convertExamplesToLSet starts" << endl;
-	#endif
-	lvec.clear();
-	for(int i = 0; i < (int)examples.size(); i++)
-	{
-		if(examples[i].second.vec != NULL)
-		{
-			lvec.add(examples[i].first, *examples[i].second.vec);
-			delete examples[i].second.vec;
-			examples[i].second.vec = NULL;
-		}
-		else
-		{
-			if(examples[i].second.svec != NULL)
-			{
-				throw("Transform SVEC to VEC not yet implemented");
-			}
-			else
-			{
-				throw("no features for LabeledSet");
-			}
-		}
-
-	}
-	examples.clear();  
-	#ifdef DEBUG_PRINTS
-	cout << "SemSegRegionBased::convertExamplesToLSet finished" << endl;
-	#endif
+#ifdef DEBUG_PRINTS
+  cout << "SemSegRegionBased::convertExamplesToLSet starts" << endl;
+#endif
+  lvec.clear();
+  for ( int i = 0; i < ( int ) examples.size(); i++ )
+  {
+    if ( examples[i].second.vec != NULL )
+    {
+      lvec.add ( examples[i].first, *examples[i].second.vec );
+      delete examples[i].second.vec;
+      examples[i].second.vec = NULL;
+    }
+    else
+    {
+      if ( examples[i].second.svec != NULL )
+      {
+        throw ( "Transform SVEC to VEC not yet implemented" );
+      }
+      else
+      {
+        throw ( "no features for LabeledSet" );
+      }
+    }
+
+  }
+  examples.clear();
+#ifdef DEBUG_PRINTS
+  cout << "SemSegRegionBased::convertExamplesToLSet finished" << endl;
+#endif
 }
 
-void SemanticSegmentation::convertExamplesToVVector(VVector &feats,Examples &examples, vector<int> &label)
+void SemanticSegmentation::convertExamplesToVVector ( VVector &feats, Examples &examples, vector<int> &label )
 {
-	#ifdef DEBUG_PRINTS
-	cout << "SemSegRegionBased::convertExamplesToVVector starts" << endl;
-	#endif
-	feats.clear();
-	label.clear();
-	for(int i = 0; i < (int)examples.size(); i++)
-	{
-		label.push_back(examples[i].first);
-		feats.push_back(*examples[i].second.vec);
-		delete examples[i].second.vec;
-		examples[i].second.vec = NULL;
-	}
-	examples.clear();
-	#ifdef DEBUG_PRINTS
-	cout << "SemSegRegionBased::convertExamplesToVVector finished" << endl;
-	#endif
+#ifdef DEBUG_PRINTS
+  cout << "SemSegRegionBased::convertExamplesToVVector starts" << endl;
+#endif
+  feats.clear();
+  label.clear();
+  for ( int i = 0; i < ( int ) examples.size(); i++ )
+  {
+    label.push_back ( examples[i].first );
+    feats.push_back ( *examples[i].second.vec );
+    delete examples[i].second.vec;
+    examples[i].second.vec = NULL;
+  }
+  examples.clear();
+#ifdef DEBUG_PRINTS
+  cout << "SemSegRegionBased::convertExamplesToVVector finished" << endl;
+#endif
 }
 
-void SemanticSegmentation::convertVVectorToExamples(VVector &feats,Examples &examples, vector<int> &label)
+void SemanticSegmentation::convertVVectorToExamples ( VVector &feats, Examples &examples, vector<int> &label )
 {
-	#ifdef DEBUG_PRINTS
-	cout << "SemSegRegionBased::convertVVectorToExamples starts" << endl;
-	#endif
-	for(int i = 0; i < (int)feats.size(); i++)
-	{
-		NICE::Vector *v = new NICE::Vector(feats[i]);
-		Example ex(v);
-		ex.position = 0; //TODO: hier mal was besseres überlegen, damit Klassifikator wieder Bildspezifisch lernt
-		examples.push_back (pair<int, Example> ( label[i], ex));
-		feats[i].clear();
-	}
-	feats.clear();
-	label.clear();
-	#ifdef DEBUG_PRINTS
-	cout << "SemSegRegionBased::convertVVectorToExamples finished" << endl;
-	#endif
+#ifdef DEBUG_PRINTS
+  cout << "SemSegRegionBased::convertVVectorToExamples starts" << endl;
+#endif
+  for ( int i = 0; i < ( int ) feats.size(); i++ )
+  {
+    NICE::Vector *v = new NICE::Vector ( feats[i] );
+    Example ex ( v );
+    ex.position = 0; //TODO: hier mal was besseres überlegen, damit Klassifikator wieder Bildspezifisch lernt
+    examples.push_back ( pair<int, Example> ( label[i], ex ) );
+    feats[i].clear();
+  }
+  feats.clear();
+  label.clear();
+#ifdef DEBUG_PRINTS
+  cout << "SemSegRegionBased::convertVVectorToExamples finished" << endl;
+#endif
 }
 
-SemanticSegmentation::SemanticSegmentation( const Config *conf,
-					    const ClassNames *classNames )
+SemanticSegmentation::SemanticSegmentation ( const Config *conf,
+    const ClassNames *classNames )
 {
-    this->classNames = classNames;
+  this->classNames = classNames;
 
-    Preprocess::Init ( conf );
+  Preprocess::Init ( conf );
 
-    std::string imagetype_s = conf->gS("main", "imagetype", "rgb");
+  std::string imagetype_s = conf->gS ( "main", "imagetype", "rgb" );
 
-    if (imagetype_s == "rgb")
-          imagetype = IMAGETYPE_RGB;
-    else if ( imagetype_s == "gray" )
-          imagetype = IMAGETYPE_GRAY; 
-    else {
-	fprintf (stderr, "SemanticSegmentation:: unknown image type option\n");
-	exit(-1);
-    }
+  if ( imagetype_s == "rgb" )
+    imagetype = IMAGETYPE_RGB;
+  else if ( imagetype_s == "gray" )
+    imagetype = IMAGETYPE_GRAY;
+  else {
+    fprintf ( stderr, "SemanticSegmentation:: unknown image type option\n" );
+    exit ( -1 );
+  }
 }
 
 SemanticSegmentation::~SemanticSegmentation()
@@ -162,22 +162,22 @@ SemanticSegmentation::~SemanticSegmentation()
 }
 
 void SemanticSegmentation::semanticseg ( const std::string & filename,
-			   NICE::Image & segresult,
-			   NICE::MultiChannelImageT<double> & probabilities)
+    NICE::Image & segresult,
+    NICE::MultiChannelImageT<double> & probabilities )
 {
-    Globals::setCurrentImgFN(filename);
-    CachedExample *ce;
-    if ( imagetype == IMAGETYPE_RGB ) 
-    {
-	NICE::ColorImage img = Preprocess::ReadImgAdvRGB ( filename );
-	ce = new CachedExample ( img );
-    } else {
-
-	NICE::Image img = Preprocess::ReadImgAdv ( filename );
-	ce = new CachedExample ( img );
-    }
-    fprintf (stderr, "Starting Semantic Segmentation !\n");
-    semanticseg ( ce, segresult, probabilities);
-    delete ce;
+  Globals::setCurrentImgFN ( filename );
+  CachedExample *ce;
+  if ( imagetype == IMAGETYPE_RGB )
+  {
+    NICE::ColorImage img = Preprocess::ReadImgAdvRGB ( filename );
+    ce = new CachedExample ( img );
+  } else {
+
+    NICE::Image img = Preprocess::ReadImgAdv ( filename );
+    ce = new CachedExample ( img );
+  }
+  fprintf ( stderr, "Starting Semantic Segmentation !\n" );
+  semanticseg ( ce, segresult, probabilities );
+  delete ce;
 }