getRelevantClasses.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. // Beispielhafter Aufruf: BUILD_x86_64/progs/testSemanticSegmentation -config <CONFIGFILE>
  2. /**
  3. * @file testSemanticSegmentation.cpp
  4. * @brief test semantic segmentation routines
  5. * @author Erik Rodner
  6. * @date 03/20/2008
  7. */
  8. #ifdef NICE_USELIB_OPENMP
  9. #include <omp.h>
  10. #endif
  11. #include "core/basics/Config.h"
  12. #include <core/basics/StringTools.h>
  13. #include <vislearning/baselib/ICETools.h>
  14. #include "vislearning/cbaselib/MultiDataset.h"
  15. #include "core/image/MultiChannelImageT.h"
  16. #include <fstream>
  17. using namespace OBJREC;
  18. using namespace NICE;
  19. using namespace std;
  20. /**
  21. test semantic segmentation routines
  22. */
  23. int main( int argc, char **argv )
  24. {
  25. Config conf( argc, argv );
  26. MultiDataset md( &conf );
  27. const ClassNames & classNames = md.getClassNames( "train" );
  28. const LabeledSet *testFiles = md["test"];
  29. set<int> forbidden_classes;
  30. std::string forbidden_classes_s = conf.gS( "analysis", "forbidden_classes", "" );
  31. classNames.getSelection( forbidden_classes_s, forbidden_classes );
  32. LOOP_ALL_S( *testFiles )
  33. {
  34. EACH_INFO( classno, info );
  35. std::string file = info.img();
  36. NICE::Image lm;
  37. NICE::MultiChannelImageT<double> probabilities;
  38. if ( info.hasLocalizationInfo() )
  39. {
  40. const LocalizationResult *l_gt = info.localization();
  41. lm.resize( l_gt->xsize, l_gt->ysize );
  42. lm.set( 0 );
  43. l_gt->calcLabeledImage( lm, classNames.getBackgroundClass() );
  44. }
  45. NICE::Image lm_gt;
  46. if ( info.hasLocalizationInfo() )
  47. {
  48. const LocalizationResult *l_gt = info.localization();
  49. lm_gt.resize( l_gt->xsize, l_gt->ysize );
  50. lm_gt.set( 0 );
  51. fprintf( stderr, "testSemanticSegmentation: Generating Labeled NICE::Image (Ground-Truth)\n" );
  52. l_gt->calcLabeledImage( lm_gt, classNames.getBackgroundClass() );
  53. }
  54. set<int> classes;
  55. for ( int x = 0; x < lm_gt.width(); x++ )
  56. {
  57. for ( int y = 0; y < lm_gt.height(); y++ )
  58. {
  59. classes.insert( lm_gt.getPixel( x, y ) );
  60. }
  61. }
  62. // write allowed classes
  63. string cndir = conf.gS( "SemSegCsurka", "cndir", "" );
  64. std::vector< std::string > list;
  65. StringTools::split( file, '/', list );
  66. cout << cndir << "/" << list.back() << ".dat" << endl;
  67. string cname = list.back();
  68. if ( cndir != "" )
  69. {
  70. string fname = cndir + "/" + cname + ".dat";
  71. cout << fname << endl;
  72. ofstream outfile( fname.c_str() );
  73. set<int>::iterator theIterator;
  74. for ( theIterator = classes.begin(); theIterator != classes.end(); theIterator++ ) {
  75. outfile << *theIterator << endl;
  76. }
  77. }
  78. else
  79. {
  80. cerr << "please define directory for writing filenames in config: SemSegCsurka::cndir" << endl;
  81. exit( -1 );
  82. }
  83. }
  84. return 0;
  85. }