123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284 |
- #ifdef NICE_USELIB_OPENMP
- #include <omp.h>
- #endif
- #include "core/basics/Config.h"
- #include "core/basics/StringTools.h"
- #include <vislearning/baselib/ICETools.h>
- #include <semseg/semseg/SemanticSegmentation.h>
- #include <semseg/semseg/SemSegLocal.h>
- #include <semseg/semseg/SemSegCsurka.h>
- #include <semseg/semseg/SemSegNovelty.h>
- #include <semseg/semseg/SemSegNoveltyBinary.h>
- #include <semseg/semseg/SemSegContextTree.h>
- #include "core/image/FilterT.h"
- #include <core/basics/ResourceStatistics.h>
- #include <fstream>
- using namespace OBJREC;
- using namespace NICE;
- using namespace std;
- int main( int argc, char **argv )
- {
- std::set_terminate( __gnu_cxx::__verbose_terminate_handler );
- Config conf( argc, argv );
-
- ResourceStatistics rs;
-
- NICE::MatrixT<double> matTemp;
- std::cerr << "foo " << std::endl;
- std::cerr << matTemp << std::endl;
-
- bool show_result = conf.gB( "debug", "show_results", false );
- bool write_results = conf.gB( "debug", "write_results", false );
- bool write_results_pascal = conf.gB( "debug", "write_results_pascal", false );
- std::string resultdir = conf.gS( "debug", "resultdir", "." );
-
-
- int activeIterations = conf.gI("main", "activeIterations", 1 );
-
- if ( write_results )
- {
- cerr << "Writing Results to " << resultdir << endl;
- }
- MultiDataset md( &conf );
- const ClassNames & classNames = md.getClassNames( "train" );
- string method = conf.gS( "main", "method", "SSCsurka" );
-
- SemSegNoveltyBinary *semseg = NULL;
-
- Timer timer;
- timer.start();
- semseg = new SemSegNoveltyBinary( &conf, &md );
- timer.stop();
-
- std::cerr << "AL time for training: " << timer.getLast() << std::endl;
- const LabeledSet *testFiles = md["test"];
- std::set<int> forbidden_classes;
- std::string forbidden_classes_s = conf.gS( "analysis", "forbidden_classesTrain", "" );
- classNames.getSelection( forbidden_classes_s, forbidden_classes );
-
- std::set<int> forbidden_classesForActiveLearning;
- std::string forbidden_classesForActiveLearning_s = conf.gS( "analysis", "forbidden_classesForActiveLearning", "" );
- classNames.getSelection( forbidden_classesForActiveLearning_s, forbidden_classesForActiveLearning );
-
-
- int positiveClass;
-
-
- std::string positiveClass_s = conf.gS ( "SemSegNoveltyBinary", "positiveClass", "" );
- std::set<int> positiveClassNumberTmp;
- classNames.getSelection ( positiveClass_s, positiveClassNumberTmp );
- switch ( positiveClassNumberTmp.size() )
- {
- case 0:
- {
- positiveClass = 0;
- break;
- }
- case 1:
- {
- positiveClass = *(positiveClassNumberTmp.begin());
- break;
- }
- default:
- {
-
-
- positiveClass = 0;
- break;
- }
- }
-
-
- std::cerr << "number of AL iterations: " << activeIterations << std::endl;
- for (int iterationCount = 0; iterationCount < activeIterations; iterationCount++)
- {
- std::cerr << "SemSeg AL Iteration: " << iterationCount << std::endl;
- semseg->setIterationCountSuffix(iterationCount);
- int fileno = 0;
- std::cerr << "start looping over all files" << std::endl;
- LOOP_ALL_S( *testFiles )
- {
- EACH_INFO( classno, info );
- std::string file = info.img();
- NICE::ImageT<int> lm;
- NICE::MultiChannelImageT<double> probabilities;
- if ( info.hasLocalizationInfo() )
- {
- const LocalizationResult *l_gt = info.localization();
- lm.resize( l_gt->xsize, l_gt->ysize );
-
- l_gt->calcLabeledImage( lm, classNames.getBackgroundClass() );
- }
- ((SemanticSegmentation*)semseg)->semanticseg( file, lm, probabilities );
- fprintf( stderr, "testSemanticSegmentation: Segmentation finished !\n" );
-
-
- NICE::ImageT<int> lm_gt;
- if ( info.hasLocalizationInfo() )
- {
- const LocalizationResult *l_gt = info.localization();
- lm_gt.resize( l_gt->xsize, l_gt->ysize );
- lm_gt.set( 0 );
- fprintf( stderr, "testSemanticSegmentation: Generating Labeled NICE::Image (Ground-Truth)\n" );
- l_gt->calcLabeledImage( lm_gt, classNames.getBackgroundClass() );
- }
- if ( show_result || write_results )
- {
- NICE::ColorImage orig( file );
- NICE::ColorImage rgb;
- NICE::ColorImage rgb_gt;
- classNames.labelToRGB( lm, rgb );
- classNames.labelToRGB( lm_gt, rgb_gt );
- if ( write_results )
- {
-
- std::stringstream out;
- std::vector< std::string > myList;
- StringTools::split ( Globals::getCurrentImgFN (), '/', myList );
- out << resultdir << "/" << myList.back();
- cerr << "Writing to file " << resultdir << "/"<< myList.back() << endl;
-
- std::string noveltyMethodString = conf.gS( "SemSegNoveltyBinary", "noveltyMethod", "gp-variance");
- orig.write ( out.str() + "_orig.ppm" );
- rgb.write ( out.str() + "_" + noveltyMethodString + "_result_run_" + NICE::intToString(iterationCount) + ".ppm" );
- rgb_gt.write ( out.str() + "_groundtruth.ppm" );
- }
- if ( show_result )
- {
- #ifndef NOVISUAL
- showImage( rgb, "Result" );
- showImage( rgb_gt, "Groundtruth" );
- showImage( orig, "Input" );
- #endif
- }
- }
- fileno++;
- }
-
-
-
-
- timer.start();
-
- double score = semseg->getAUCPerformance();
- std::cerr << "auc scores of run : " << iterationCount << " : " << score << std::endl;
-
- long maxMemory;
- rs.getMaximumMemory(maxMemory);
- cerr << "Maximum memory used: " << maxMemory << " KB" << endl;
-
- timer.stop();
- std::cout << "AL time for evaluation: " << timer.getLastAbsolute() << std::endl;
-
-
-
-
-
-
-
- timer.start();
- semseg->addNovelExamples();
-
- timer.stop();
- std::cout << "AL time for incremental update: " << timer.getLastAbsolute() << std::endl;
-
-
-
-
- const Examples * novelExamples = semseg->getNovelExamples();
-
-
- std::set<int> newClassNumbers;
- newClassNumbers.clear();
- for ( uint i = 0 ; i < novelExamples->size() ; i++ )
- {
- if (newClassNumbers.find( (*novelExamples)[i].first ) == newClassNumbers.end() )
- {
- newClassNumbers.insert( (*novelExamples)[i].first );
- }
- }
-
- for (std::set<int>::const_iterator clNoIt = newClassNumbers.begin(); clNoIt != newClassNumbers.end(); clNoIt++)
- {
- if ( forbidden_classes.find ( *clNoIt ) != forbidden_classes.end() )
- {
- forbidden_classes.erase(*clNoIt);
- }
- }
- std::cerr << "iteration finished - start the next round" << std::endl;
-
- }
- delete semseg;
- return 0;
- }
|