12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240 |
- #include <sstream>
- #include <iostream>
- #include "core/image/FilterT.h"
- #include "core/basics/numerictools.h"
- #include "core/basics/StringTools.h"
- #include "core/basics/Timer.h"
- #include <vislearning/classifier/fpclassifier/gphik/FPCGPHIK.h>
- #include "vislearning/baselib/ICETools.h"
- #include "vislearning/baselib/Globals.h"
- #include "vislearning/features/fpfeatures/SparseVectorFeature.h"
- #include "segmentation/GenericRegionSegmentationMethodSelection.h"
- #include "SemSegNovelty.h"
- using namespace std;
- using namespace NICE;
- using namespace OBJREC;
- SemSegNovelty::SemSegNovelty ( )
- : SemanticSegmentation ( )
- {
- this->forbidden_classesTrain.clear();
- this->forbidden_classesActiveLearning.clear();
- this->classesInUse.clear();
-
- this->globalMaxUncert = -numeric_limits<double>::max();
-
- //we don't have queried any region so far
- this->queriedRegions.clear();
-
- this->featExtract = new LocalFeatureColorWeijer ();
-
- // those two guys need to be NULL, since only one of them will be active later on
- this->classifier = NULL;
- this->vclassifier = NULL;
-
- // this one here as well
- this->regionSeg = NULL;
- }
- SemSegNovelty::SemSegNovelty ( const Config * _conf,
- const MultiDataset *md )
- {
- ///////////
- // same code as in empty constructor - duplication can be avoided with C++11 allowing for constructor delegation
- ///////////
- this->forbidden_classesTrain.clear();
- this->forbidden_classesActiveLearning.clear();
- this->classesInUse.clear();
-
- this->globalMaxUncert = -numeric_limits<double>::max();
-
- //we don't have queried any region so far
- this->queriedRegions.clear();
-
- this->featExtract = new LocalFeatureColorWeijer ();
-
- // those two guys need to be NULL, since only one of them will be active later on
- this->classifier = NULL;
- this->vclassifier = NULL;
-
- // this one here as well
- this->regionSeg = NULL;
-
- ///////////
- // here comes the new code part different from the empty constructor
- ///////////
- this->setClassNames ( & ( md->getClassNames ( "train" ) ) );
-
- this->initFromConfig( _conf );
- }
- SemSegNovelty::~SemSegNovelty()
- {
- if(newTrainExamples.size() > 0)
- {
- // show most uncertain region
- if (b_visualizeALimages)
- showImage(maskedImg);
-
- //incorporate new information into the classifier
- if (classifier != NULL)
- {
- //NOTE dangerous!
- classifier->addMultipleExamples(newTrainExamples);
- }
-
- //store the classifier, such that we can read it again in the next round (if we like that)
- classifier->save ( cache + "/classifier.data" );
- }
-
- // clean-up
-
- ///////////////////////////////
- // FEATURE EXTRACTION //
- ///////////////////////////////
- if ( featExtract != NULL )
- delete featExtract;
- ///////////////////////////////
- // CLASSIFICATION STUFF //
- ///////////////////////////////
- if ( classifier != NULL )
- delete classifier;
- if ( vclassifier != NULL )
- delete vclassifier;
-
- ///////////////////////////////
- // SEGMENTATION STUFF //
- ///////////////////////////////
- if ( this->regionSeg != NULL )
- delete this->regionSeg;
- }
- void SemSegNovelty::initFromConfig(const Config* conf, const string _confSection)
- {
- //first of all, call method of parent object
- SemanticSegmentation::initFromConfig( conf );
-
- featExtract->initFromConfig ( conf );
- //save and read segmentation results from files
- this->reuseSegmentation = conf->gB ( "FPCPixel", "reuseSegmentation", true );
- //save the classifier to a file
- this->save_classifier = conf->gB ( "FPCPixel", "save_classifier", true );
- //read the classifier from a file
- this->read_classifier = conf->gB ( "FPCPixel", "read_classifier", false );
- //write uncertainty results in the same folder as done for the segmentation results
- resultdir = conf->gS("debug", "resultdir", "result");
- cache = conf->gS ( "cache", "root", "" );
- cache = conf->getAbsoluteFilenameRelativeToThisConfig(cache);
- this->findMaximumUncert = conf->gB(_confSection, "findMaximumUncert", true);
- this->whs = conf->gI ( _confSection, "window_size", 10 );
- //distance to next descriptor during training
- this->trainWSize = conf->gI ( _confSection, "train_window_size", 10 );
- //distance to next descriptor during testing
- this->testWSize = conf->gI (_confSection, "test_window_size", 10);
- // select your segmentation method here
- this->s_rsMethode = conf->gS ( _confSection, "segmentation", "none" );
-
- if( this->s_rsMethode == "none" )
- {
- regionSeg = NULL;
- }
- else
- {
- RegionSegmentationMethod *tmpRegionSeg = GenericRegionSegmentationMethodSelection::selectRegionSegmentationMethod( conf, this->s_rsMethode );
- if ( reuseSegmentation )
- regionSeg = new RSCache ( conf, tmpRegionSeg );
- else
- regionSeg = tmpRegionSeg;
- }
-
- //define which measure for "novelty" we want to use
- noveltyMethodString = conf->gS( _confSection, "noveltyMethod", "gp-variance");
- if (noveltyMethodString.compare("gp-variance") == 0) // novel = large variance
- {
- this->noveltyMethod = GPVARIANCE;
- this->mostNoveltyWithMaxScores = true;
- }
- else if (noveltyMethodString.compare("gp-uncertainty") == 0) //novel = large uncertainty (mean / var)
- {
- this->noveltyMethod = GPUNCERTAINTY;
- this->mostNoveltyWithMaxScores = false;
- globalMaxUncert = numeric_limits<double>::max();
- }
- else if (noveltyMethodString.compare("gp-mean") == 0) //novel = small mean
- {
- this->noveltyMethod = GPMINMEAN;
- this->mostNoveltyWithMaxScores = false;
- globalMaxUncert = numeric_limits<double>::max();
- }
- else if (noveltyMethodString.compare("gp-meanRatio") == 0) //novel = small difference between mean of most plausible class and mean of snd
- // most plausible class (not useful in binary settings)
- {
- this->noveltyMethod = GPMEANRATIO;
- this->mostNoveltyWithMaxScores = false;
- globalMaxUncert = numeric_limits<double>::max();
- }
- else if (noveltyMethodString.compare("gp-weightAll") == 0) // novel = large weight in alpha vector after updating the model (can be predicted exactly)
- {
- this->noveltyMethod = GPWEIGHTALL;
- this->mostNoveltyWithMaxScores = true;
- }
- else if (noveltyMethodString.compare("gp-weightRatio") == 0) // novel = small difference between weights for alpha vectors
- // with assumptions of GT label to be the most
- // plausible against the second most plausible class
- {
- this->noveltyMethod = GPWEIGHTRATIO;
- this->mostNoveltyWithMaxScores = false;
- globalMaxUncert = numeric_limits<double>::max();
- }
- else if (noveltyMethodString.compare("random") == 0)
- {
- initRand();
- this->noveltyMethod = RANDOM;
- }
- else
- {
- this->noveltyMethod = GPVARIANCE;
- this->mostNoveltyWithMaxScores = true;
- }
-
- b_visualizeALimages = conf->gB(_confSection, "visualizeALimages", false);
-
-
- classifierString = conf->gS ( _confSection, "classifier", "GPHIKClassifier" );
- classifier = NULL;
- vclassifier = NULL;
- if ( classifierString.compare("GPHIKClassifier") == 0)
- {
- //just to make sure, that we do NOT perform an optimization after every iteration step
- //this would just take a lot of time, which is not desired so far
- //TODO edit this!
- //this->conf->sB( "GPHIKClassifier", "performOptimizationAfterIncrement", false );
- classifier = new FPCGPHIK ( conf, "GPHIKClassifier" );
- }
- else
- vclassifier = GenericClassifierSelection::selectVecClassifier ( conf, classifierString );
-
-
-
-
- //check the same thing for the training classes - this is very specific to our setup
- std::string forbidden_classesTrain_s = conf->gS ( "analysis", "donttrainTrain", "" );
- if ( forbidden_classesTrain_s == "" )
- {
- forbidden_classesTrain_s = conf->gS ( "analysis", "forbidden_classesTrain", "" );
- }
- this->classNames->getSelection ( forbidden_classesTrain_s, forbidden_classesTrain );
- }
- void SemSegNovelty::visualizeRegion(const NICE::ColorImage &img, const NICE::Matrix ®ions, int region, NICE::ColorImage &outimage)
- {
- std::vector<uchar> color;
- color.push_back(255);
- color.push_back(0);
- color.push_back(0);
-
- int width = img.width();
- int height = img.height();
-
- outimage.resize(width,height);
-
- for(int y = 0; y < height; y++)
- {
- for(int x = 0; x < width; x++)
- {
- if(regions(x,y) == region)
- {
- for(int c = 0; c < 3; c++)
- {
- outimage(x,y,c) = color[c];
- }
- }
- else
- {
- for(int c = 0; c < 3; c++)
- {
- outimage(x,y,c) = img(x,y,c);
- }
- }
- }
- }
- }
- void SemSegNovelty::train ( const MultiDataset *md )
- {
- if ( this->read_classifier )
- {
- try
- {
- if ( this->classifier != NULL )
- {
- string classifierdst = "/classifier.data";
- fprintf ( stderr, "SemSegNovelty:: Reading classifier data from %s\n", ( cache + classifierdst ).c_str() );
- classifier->read ( cache + classifierdst );
- }
- else
- {
- string classifierdst = "/veccl.data";
- fprintf ( stderr, "SemSegNovelty:: Reading classifier data from %s\n", ( cache + classifierdst ).c_str() );
- vclassifier->read ( cache + classifierdst );
- }
-
- fprintf ( stderr, "SemSegNovelty:: successfully read\n" );
- }
- catch ( char *str )
- {
- cerr << "error reading data: " << str << endl;
- }
- }
- else
- {
- const LabeledSet train = * ( *md ) ["train"];
- const LabeledSet *trainp = &train;
- ////////////////////////
- // feature extraction //
- ////////////////////////
-
- ProgressBar pb ( "Local Feature Extraction" );
- pb.show();
- int imgnb = 0;
- Examples examples;
- examples.filename = "training";
- int featdim = -1;
- classesInUse.clear();
-
- LOOP_ALL_S ( *trainp )
- {
- //EACH_S(classno, currentFile);
- EACH_INFO ( classno, info );
- std::string currentFile = info.img();
- CachedExample *ce = new CachedExample ( currentFile );
- const LocalizationResult *locResult = info.localization();
- if ( locResult->size() <= 0 )
- {
- fprintf ( stderr, "WARNING: NO ground truth polygons found for %s !\n",
- currentFile.c_str() );
- continue;
- }
- int xsize, ysize;
- ce->getImageSize ( xsize, ysize );
- Image labels ( xsize, ysize );
- labels.set ( 0 );
- locResult->calcLabeledImage ( labels, ( *classNames ).getBackgroundClass() );
- NICE::ColorImage img;
- try {
- img = ColorImage ( currentFile );
- } catch ( Exception ) {
- cerr << "SemSegNovelty: error opening image file <" << currentFile << ">" << endl;
- continue;
- }
- Globals::setCurrentImgFN ( currentFile );
- MultiChannelImageT<double> feats;
- // extract features
- featExtract->getFeats ( img, feats );
- featdim = feats.channels();
- feats.addChannel(featdim);
- for (int c = 0; c < featdim; c++)
- {
- ImageT<double> tmp = feats[c];
- ImageT<double> tmp2 = feats[c+featdim];
- NICE::FilterT<double, double, double>::gradientStrength (tmp, tmp2);
- }
- featdim += featdim;
- // compute integral images
- for ( int c = 0; c < featdim; c++ )
- {
- feats.calcIntegral ( c );
- }
- for ( int y = 0; y < ysize; y += trainWSize)
- {
- for ( int x = 0; x < xsize; x += trainWSize )
- {
- int classnoTmp = labels.getPixel ( x, y );
-
- if ( forbidden_classesTrain.find ( classnoTmp ) != forbidden_classesTrain.end() )
- {
- continue;
- }
-
- if (classesInUse.find(classnoTmp) == classesInUse.end())
- {
- classesInUse.insert(classnoTmp);
- }
-
- Example example;
- example.vec = NULL;
- example.svec = new SparseVector ( featdim );
- for ( int f = 0; f < featdim; f++ )
- {
- double val = feats.getIntegralValue ( x - whs, y - whs, x + whs, y + whs, f );
- if ( val > 1e-10 )
- ( *example.svec ) [f] = val;
- }
- example.svec->normalize();
- example.position = imgnb;
- examples.push_back ( pair<int, Example> ( classnoTmp, example ) );
- }
- }
-
-
-
- delete ce;
- imgnb++;
- pb.update ( trainp->count() );
- }
-
-
- numberOfClasses = classesInUse.size();
- std::cerr << "numberOfClasses: " << numberOfClasses << std::endl;
- std::cerr << "classes in use: " << std::endl;
- for (std::set<int>::const_iterator it = classesInUse.begin(); it != classesInUse.end(); it++)
- {
- std::cerr << *it << " ";
- }
- std::cerr << std::endl;
- pb.hide();
- //////////////////////
- // train classifier //
- //////////////////////
- FeaturePool fp;
- Feature *f = new SparseVectorFeature ( featdim );
- f->explode ( fp );
- delete f;
- if ( classifier != NULL )
- {
- std::cerr << "train FP-classifier with " << examples.size() << " examples" << std::endl;
- classifier->train ( fp, examples );
- std::cerr << "training finished" << std::endl;
- }
- else
- {
- LabeledSetVector lvec;
- convertExamplesToLSet ( examples, lvec );
- vclassifier->teach ( lvec );
- // if ( usegmm )
- // convertLSetToSparseExamples ( examples, lvec );
- // else
- std::cerr << "classifierString: " << classifierString << std::endl;
- if (this->classifierString.compare("nn") == 0)
- {
- convertLSetToExamples ( examples, lvec, true /* only remove pointers to the data in the LSet-struct*/);
- }
- else
- {
- convertLSetToExamples ( examples, lvec, false /* remove all training examples of the LSet-struct */);
- }
- vclassifier->finishTeaching();
- }
- fp.destroy();
- if ( save_classifier )
- {
- if ( classifier != NULL )
- classifier->save ( cache + "/classifier.data" );
- else
- vclassifier->save ( cache + "/veccl.data" );
- }
- ////////////
- //clean up//
- ////////////
- for ( int i = 0; i < ( int ) examples.size(); i++ )
- {
- examples[i].second.clean();
- }
- examples.clear();
- cerr << "SemSeg training finished" << endl;
- }
- }
- void SemSegNovelty::semanticseg (
- CachedExample *ce,
- NICE::ImageT<int> & segresult,
- NICE::MultiChannelImageT<double> & probabilities )
- {
- Timer timer;
- timer.start();
-
- //segResult contains the GT labels when this method is called
- // we simply store them in labels, to have an easy access to the GT information lateron
- NICE::ImageT<int> labels = segresult;
- //just to be sure that we do not have a GT-biased result :)
- segresult.set(0);
- int featdim = -1;
- std::string currentFile = Globals::getCurrentImgFN();
- int xsize, ysize;
- ce->getImageSize ( xsize, ysize );
- probabilities.reInit( xsize, ysize, this->classNames->getMaxClassno() + 1);
- probabilities.setAll ( -std::numeric_limits<double>::max() );
-
- NICE::ColorImage img;
- try {
- img = ColorImage ( currentFile );
- } catch ( Exception ) {
- cerr << "SemSegNovelty: error opening image file <" << currentFile << ">" << endl;
- return;
- }
- // MultiChannelImageT<double> m_CurrentImageFeatures;
- // extract features
- m_CurrentImageFeatures.freeData();
- featExtract->getFeats ( img, m_CurrentImageFeatures );
- featdim = m_CurrentImageFeatures.channels();
- m_CurrentImageFeatures.addChannel(featdim);
- for (int c = 0; c < featdim; c++)
- {
- ImageT<double> tmp = m_CurrentImageFeatures[c];
- ImageT<double> tmp2 = m_CurrentImageFeatures[c+featdim];
- NICE::FilterT<double, double, double>::gradientStrength (tmp, tmp2);
- }
- featdim += featdim;
- // compute integral images
- for ( int c = 0; c < featdim; c++ )
- {
- m_CurrentImageFeatures.calcIntegral ( c );
- }
-
- timer.stop();
- std::cout << "AL time for preparation: " << timer.getLastAbsolute() << std::endl;
-
- timer.start();
- //classification results currently only needed to be computed separately if we use the vclassifier, i.e., the nearest neighbor used
- // for the "novel feature learning" approach
- //in all other settings, such as active sem seg in general, we do this within the novelty-computation-methods
- if ( classifier == NULL )
- {
- this->computeClassificationResults( m_CurrentImageFeatures, segresult, probabilities, xsize, ysize, featdim);
- }
- // timer.stop();
- //
- // std::cerr << "classification results computed" << std::endl;
-
- FloatImage noveltyImage ( xsize, ysize );
- noveltyImage.set ( 0.0 );
-
- switch (noveltyMethod)
- {
- case GPVARIANCE:
- {
- this->computeNoveltyByVariance( noveltyImage, m_CurrentImageFeatures, segresult, probabilities, xsize, ysize, featdim );
- break;
- }
- case GPUNCERTAINTY:
- {
- this->computeNoveltyByGPUncertainty( noveltyImage, m_CurrentImageFeatures, segresult, probabilities, xsize, ysize, featdim );
- break;
- }
- case GPMINMEAN:
- {
- std::cerr << "compute novelty using the minimum mean" << std::endl;
- this->computeNoveltyByGPMean( noveltyImage, m_CurrentImageFeatures, segresult, probabilities, xsize, ysize, featdim );
- break;
- }
- case GPMEANRATIO:
- {
- this->computeNoveltyByGPMeanRatio( noveltyImage, m_CurrentImageFeatures, segresult, probabilities, xsize, ysize, featdim );
- break;
- }
- case GPWEIGHTALL:
- {
- this->computeNoveltyByGPWeightAll( noveltyImage, m_CurrentImageFeatures, segresult, probabilities, xsize, ysize, featdim );
- break;
- }
- case GPWEIGHTRATIO:
- {
- this->computeNoveltyByGPWeightRatio( noveltyImage, m_CurrentImageFeatures, segresult, probabilities, xsize, ysize, featdim );
- break;
- }
- case RANDOM:
- {
- this->computeNoveltyByRandom( noveltyImage, m_CurrentImageFeatures, segresult, probabilities, xsize, ysize, featdim );
- break;
- }
- default:
- {
- //do nothing, keep the image constant to 0.0
- break;
- }
-
- }
-
- timer.stop();
- std::cout << "AL time for novelty score computation: " << timer.getLastAbsolute() << std::endl;
-
- if (b_visualizeALimages)
- {
- ColorImage imgrgbTmp (xsize, ysize);
- ICETools::convertToRGB ( noveltyImage, imgrgbTmp );
- showImage(imgrgbTmp, "Novelty Image without Region Segmentation");
- }
-
-
- timer.start();
-
- //Regionen ermitteln
- if(regionSeg != NULL)
- {
- NICE::Matrix mask;
- int amountRegions = regionSeg->segRegions ( img, mask );
-
- //compute probs per region
- std::vector<std::vector<double> > regionProb(amountRegions, std::vector<double>(probabilities.channels(), -std::numeric_limits<double>::max() ));
- std::vector<double> regionNoveltyMeasure (amountRegions, 0.0);
- std::vector<int> regionCounter(amountRegions, 0);
- std::vector<int> regionCounterNovelty(amountRegions, 0);
- for ( int y = 0; y < ysize; y += testWSize) //y++)
- {
- for (int x = 0; x < xsize; x += testWSize) //x++)
- {
- int r = mask(x,y);
- regionCounter[r]++;
- for(int j = 0; j < probabilities.channels(); j++)
- {
- if( regionProb[r][j] == -std::numeric_limits<double>::max() )
- regionProb[r][j] = 0.0f;
- regionProb[r][j] += probabilities ( x, y, j );
- }
-
- if ( forbidden_classesActiveLearning.find( labels(x,y) ) == forbidden_classesActiveLearning.end() )
- {
- //count the amount of "novelty" for the corresponding region
- regionNoveltyMeasure[r] += noveltyImage(x,y);
- regionCounterNovelty[r]++;
- }
- }
- }
-
- //find best class per region
- std::vector<int> bestClassPerRegion(amountRegions,0);
-
- double maxNoveltyScore = -numeric_limits<double>::max();
- if (!mostNoveltyWithMaxScores)
- {
- maxNoveltyScore = numeric_limits<double>::max();
- }
-
- int maxUncertRegion = -1;
-
- //loop over all regions and compute averaged novelty scores
- for(int r = 0; r < amountRegions; r++)
- {
-
- //check for the most plausible class per region
- double maxval = -numeric_limits<double>::max();
-
- //loop over all classes
- for(int c = 0; c < probabilities.channels(); c++)
- {
- regionProb[r][c] /= regionCounter[r];
-
- if( (maxval < regionProb[r][c]) ) //&& (regionProb[r][c] != 0.0) )
- {
- maxval = regionProb[r][c];
- bestClassPerRegion[r] = c;
- }
- }
-
- //if the region only contains unvalid information (e.g., background) skip it
- if (regionCounterNovelty[r] == 0)
- {
- continue;
- }
-
- //normalize summed novelty scores to region size
- regionNoveltyMeasure[r] /= regionCounterNovelty[r];
-
- //did we find a region that has a higher score as the most novel region known so far within this image?
- if( ( mostNoveltyWithMaxScores && (maxNoveltyScore < regionNoveltyMeasure[r]) ) // if we look for large novelty scores, e.g., variance
- || ( !mostNoveltyWithMaxScores && (maxNoveltyScore > regionNoveltyMeasure[r]) ) ) // if we look for small novelty scores, e.g., min mean
- {
- //did we already query a region of this image? -- and it was this specific region
- if ( (queriedRegions.find( currentFile ) != queriedRegions.end() ) && ( queriedRegions[currentFile].find(r) != queriedRegions[currentFile].end() ) )
- {
- continue;
- }
- else //only accept the region as novel if we never queried it before
- {
- maxNoveltyScore = regionNoveltyMeasure[r];
- maxUncertRegion = r;
- }
- }
- }
-
- // after finding the most novel region for the current image, check whether this region is also the most novel with respect
- // to all previously seen test images
- // if so, store the corresponding features, since we want to "actively" query them to incorporate useful information
- if(findMaximumUncert)
- {
- if( ( mostNoveltyWithMaxScores && (maxNoveltyScore > globalMaxUncert) )
- || ( !mostNoveltyWithMaxScores && (maxNoveltyScore < globalMaxUncert) ) )
- {
- //current most novel region of the image has "higher" novelty score then previous most novel region of all test images worked on so far
- // -> save new important features of this region
- Examples examples;
- for ( int y = 0; y < ysize; y += testWSize )
- {
- for ( int x = 0; x < xsize; x += testWSize)
- {
- if(mask(x,y) == maxUncertRegion)
- {
- int classnoTmp = labels(x,y);
- if ( forbidden_classesActiveLearning.find(classnoTmp) != forbidden_classesActiveLearning.end() )
- continue;
- Example t_Example(NULL, x, y);
- t_Example.vec = NULL;
- t_Example.svec = new SparseVector ( featdim );
- for ( int f = 0; f < featdim; f++ )
- {
- // double val = ( *example.svec ) [f];
- double val = m_CurrentImageFeatures.getIntegralValue ( x - whs, y - whs, x + whs, y + whs, f );
- if ( val > 1e-10 )
- ( *t_Example.svec ) [f] = val;
- }
- examples.push_back ( pair<int, Example> ( classnoTmp, t_Example ) );
- }
- }
- }
-
- if(examples.size() > 0)
- {
- std::cerr << "found " << examples.size() << " new examples in the queried region" << std::endl << std::endl;
- // sauber aufräumen
- for( int i=0; i< newTrainExamples.size(); i++)
- {
- delete newTrainExamples.at(i).second.svec;
- newTrainExamples.at(i).second.svec = NULL;
- }
- newTrainExamples.clear();
- newTrainExamples = examples;
- globalMaxUncert = maxNoveltyScore;
- //prepare for later visualization
- // if (b_visualizeALimages)
- visualizeRegion(img,mask,maxUncertRegion,maskedImg);
- }
- else
- {
- std::cerr << "the queried region has no valid information" << std::endl << std::endl;
- }
-
- //save filename and region index
- currentRegionToQuery.first = currentFile;
- currentRegionToQuery.second = maxUncertRegion;
- }
- }
- //write back best results per region
- //i.e., write normalized novelty scores for every region into the novelty image
- for ( int y = 0; y < ysize; y++)
- {
- for (int x = 0; x < xsize; x++)
- {
- int r = mask(x,y);
- for(int j = 0; j < probabilities.channels(); j++)
- {
- probabilities ( x, y, j ) = regionProb[r][j];
- }
- segresult(x,y) = bestClassPerRegion[r];
- // write novelty scores for every segment into the "final" image
- noveltyImage(x,y) = regionNoveltyMeasure[r];
- }
- }
- } // if regionSeg != null
-
- timer.stop();
- std::cout << "AL time for determination of novel regions: " << timer.getLastAbsolute() << std::endl;
- if (b_visualizeALimages)
- {
- timer.start();
- std::stringstream out;
- std::vector< std::string > list2;
- StringTools::split ( Globals::getCurrentImgFN (), '/', list2 );
- out << resultdir << "/" << list2.back();
- noveltyImage.writeRaw(out.str() + "_run_" + NICE::intToString(this->iterationCountSuffix) + "_" + noveltyMethodString+".rawfloat");
- ColorImage imgrgb ( xsize, ysize );
- ICETools::convertToRGB ( noveltyImage, imgrgb );
- showImage(imgrgb, "Novelty Image");
- timer.stop();
- cout << "AL time for writing the raw novelty image: " << timer.getLastAbsolute() << endl;
- }
- }
- inline void SemSegNovelty::computeClassificationResults( const NICE::MultiChannelImageT<double> & feats,
- NICE::ImageT<int> & segresult,
- NICE::MultiChannelImageT<double> & probabilities,
- const int & xsize,
- const int & ysize,
- const int & featdim
- )
- {
- std::cerr << "featdim: " << featdim << std::endl;
-
- if ( classifier != NULL )
- {
-
- #pragma omp parallel for
- for ( int y = 0; y < ysize; y += testWSize )
- {
- Example example;
- example.vec = NULL;
- example.svec = new SparseVector ( featdim );
- for ( int x = 0; x < xsize; x += testWSize)
- {
- for ( int f = 0; f < featdim; f++ )
- {
- double val = feats.getIntegralValue ( x - whs, y - whs, x + whs, y + whs, f );
- if ( val > 1e-10 )
- ( *example.svec ) [f] = val;
- }
- example.svec->normalize();
- ClassificationResult cr = classifier->classify ( example );
- int xs = std::max(0, x - testWSize/2);
- int xe = std::min(xsize - 1, x + testWSize/2);
- int ys = std::max(0, y - testWSize/2);
- int ye = std::min(ysize - 1, y + testWSize/2);
- for (int yl = ys; yl <= ye; yl++)
- {
- for (int xl = xs; xl <= xe; xl++)
- {
- for ( int j = 0 ; j < cr.scores.size(); j++ )
- {
- probabilities ( xl, yl, j ) = cr.scores[j];
- }
- segresult ( xl, yl ) = cr.classno;
- }
- }
-
- example.svec->clear();
- }
- delete example.svec;
- example.svec = NULL;
- }
- }
- else //vclassifier
- {
- std::cerr << "compute classification results with vclassifier" << std::endl;
- #pragma omp parallel for
- for ( int y = 0; y < ysize; y += testWSize )
- {
- for ( int x = 0; x < xsize; x += testWSize)
- {
- NICE::Vector v(featdim);
- for ( int f = 0; f < featdim; f++ )
- {
- double val = feats.getIntegralValue ( x - whs, y - whs, x + whs, y + whs, f );
- v[f] = val;
- }
- v.normalizeL1();
- ClassificationResult cr = vclassifier->classify ( v );
- int xs = std::max(0, x - testWSize/2);
- int xe = std::min(xsize - 1, x + testWSize/2);
- int ys = std::max(0, y - testWSize/2);
- int ye = std::min(ysize - 1, y + testWSize/2);
- for (int yl = ys; yl <= ye; yl++)
- {
- for (int xl = xs; xl <= xe; xl++)
- {
- for ( int j = 0 ; j < cr.scores.size(); j++ )
- {
- probabilities ( xl, yl, j ) = cr.scores[j];
- }
- segresult ( xl, yl ) = cr.classno;
- }
- }
- }
- }
- }
- }
- // compute novelty images depending on the strategy chosen
- void SemSegNovelty::computeNoveltyByRandom( NICE::FloatImage & noveltyImage,
- const NICE::MultiChannelImageT<double> & feats,
- NICE::ImageT<int> & segresult,
- NICE::MultiChannelImageT<double> & probabilities,
- const int & xsize, const int & ysize, const int & featdim )
- {
- #pragma omp parallel for
- for ( int y = 0; y < ysize; y += testWSize )
- {
- Example example;
- example.vec = NULL;
- example.svec = new SparseVector ( featdim );
- for ( int x = 0; x < xsize; x += testWSize)
- {
- for ( int f = 0; f < featdim; f++ )
- {
- double val = feats.getIntegralValue ( x - whs, y - whs, x + whs, y + whs, f );
- if ( val > 1e-10 )
- ( *example.svec ) [f] = val;
- }
- example.svec->normalize();
- ClassificationResult cr = classifier->classify ( example );
-
- int xs = std::max(0, x - testWSize/2);
- int xe = std::min(xsize - 1, x + testWSize/2);
- int ys = std::max(0, y - testWSize/2);
- int ye = std::min(ysize - 1, y + testWSize/2);
-
- double randVal = randDouble();
- for (int yl = ys; yl <= ye; yl++)
- {
- for (int xl = xs; xl <= xe; xl++)
- {
- for ( int j = 0 ; j < cr.scores.size(); j++ )
- {
- probabilities ( xl, yl, j ) = cr.scores[j];
- }
- segresult ( xl, yl ) = cr.classno;
- noveltyImage ( xl, yl ) = randVal;
- }
- }
- }
- }
- }
- void SemSegNovelty::computeNoveltyByVariance( NICE::FloatImage & noveltyImage,
- const NICE::MultiChannelImageT<double> & feats,
- NICE::ImageT<int> & segresult,
- NICE::MultiChannelImageT<double> & probabilities,
- const int & xsize, const int & ysize, const int & featdim )
- {
- #pragma omp parallel for
- for ( int y = 0; y < ysize; y += testWSize )
- {
- Example example;
- example.vec = NULL;
- example.svec = new SparseVector ( featdim );
- for ( int x = 0; x < xsize; x += testWSize)
- {
- for ( int f = 0; f < featdim; f++ )
- {
- double val = feats.getIntegralValue ( x - whs, y - whs, x + whs, y + whs, f );
- if ( val > 1e-10 )
- ( *example.svec ) [f] = val;
- }
- example.svec->normalize();
- ClassificationResult cr = classifier->classify ( example );
-
- int xs = std::max(0, x - testWSize/2);
- int xe = std::min(xsize - 1, x + testWSize/2);
- int ys = std::max(0, y - testWSize/2);
- int ye = std::min(ysize - 1, y + testWSize/2);
- for (int yl = ys; yl <= ye; yl++)
- {
- for (int xl = xs; xl <= xe; xl++)
- {
- for ( int j = 0 ; j < cr.scores.size(); j++ )
- {
- probabilities ( xl, yl, j ) = cr.scores[j];
- }
- segresult ( xl, yl ) = cr.classno;
- noveltyImage ( xl, yl ) = cr.uncertainty;
- }
- }
-
- example.svec->clear();
- }
- delete example.svec;
- example.svec = NULL;
- }
- }
- void SemSegNovelty::computeNoveltyByGPUncertainty( NICE::FloatImage & noveltyImage,
- const NICE::MultiChannelImageT<double> & feats,
- NICE::ImageT<int> & segresult,
- NICE::MultiChannelImageT<double> & probabilities,
- const int & xsize, const int & ysize, const int & featdim )
- {
-
- double gpNoise = 0.01;
- //TODO getMethod for GPHIK
- //conf->gD("GPHIK", "noise", 0.01);
-
-
- #pragma omp parallel for
- for ( int y = 0; y < ysize; y += testWSize )
- {
- Example example;
- example.vec = NULL;
- example.svec = new SparseVector ( featdim );
- for ( int x = 0; x < xsize; x += testWSize)
- {
- for ( int f = 0; f < featdim; f++ )
- {
- double val = feats.getIntegralValue ( x - whs, y - whs, x + whs, y + whs, f );
- if ( val > 1e-10 )
- ( *example.svec ) [f] = val;
- }
- example.svec->normalize();
- ClassificationResult cr = classifier->classify ( example );
-
- double maxMeanAbs ( 0.0 );
-
- for ( int j = 0 ; j < cr.scores.size(); j++ )
- {
- if ( forbidden_classesTrain.find ( j ) != forbidden_classesTrain.end() )
- {
- continue;
- }
- //check for larger abs mean
- if (abs(cr.scores[j]) > maxMeanAbs)
- {
- maxMeanAbs = abs(cr.scores[j]);
- }
-
- }
- double firstTerm (1.0 / sqrt(cr.uncertainty+gpNoise));
-
- //compute the heuristic GP-UNCERTAINTY, as proposed by Kapoor et al. in IJCV 2010
- // GP-UNCERTAINTY : |mean| / sqrt(var^2 + gpnoise^2)
- double gpUncertaintyVal = maxMeanAbs*firstTerm; //firstTerm = 1.0 / sqrt(r.uncertainty+gpNoise))
- int xs = std::max(0, x - testWSize/2);
- int xe = std::min(xsize - 1, x + testWSize/2);
- int ys = std::max(0, y - testWSize/2);
- int ye = std::min(ysize - 1, y + testWSize/2);
- for (int yl = ys; yl <= ye; yl++)
- {
- for (int xl = xs; xl <= xe; xl++)
- {
- for ( int j = 0 ; j < cr.scores.size(); j++ )
- {
- probabilities ( xl, yl, j ) = cr.scores[j];
- }
- segresult ( xl, yl ) = cr.classno;
- noveltyImage ( xl, yl ) = gpUncertaintyVal;
- }
- }
-
- example.svec->clear();
- }
- delete example.svec;
- example.svec = NULL;
- }
- }
- void SemSegNovelty::computeNoveltyByGPMean( NICE::FloatImage & noveltyImage,
- const NICE::MultiChannelImageT<double> & feats,
- NICE::ImageT<int> & segresult,
- NICE::MultiChannelImageT<double> & probabilities,
- const int & xsize, const int & ysize, const int & featdim )
- {
- double gpNoise = 0.01;
- //TODO getMethod for GPHIK
- //conf->gD("GPHIK", "noise", 0.01);
-
- #pragma omp parallel for
- for ( int y = 0; y < ysize; y += testWSize )
- {
- Example example;
- example.vec = NULL;
- example.svec = new SparseVector ( featdim );
- for ( int x = 0; x < xsize; x += testWSize)
- {
- for ( int f = 0; f < featdim; f++ )
- {
- double val = feats.getIntegralValue ( x - whs, y - whs, x + whs, y + whs, f );
- if ( val > 1e-10 )
- ( *example.svec ) [f] = val;
- }
- example.svec->normalize();
- ClassificationResult cr = classifier->classify ( example );
- double minMeanAbs ( numeric_limits<double>::max() );
-
- for ( int j = 0 ; j < probabilities.channels(); j++ )
- {
- if ( forbidden_classesTrain.find ( j ) != forbidden_classesTrain.end() )
- {
- continue;
- }
- //check whether we found a class with higher smaller abs mean than the current minimum
- if (abs( cr.scores[j] ) < minMeanAbs)
- {
- minMeanAbs = abs(cr.scores[j]);
- }
- }
- // compute results when we take the lowest mean value of all classes
- double gpMeanVal = minMeanAbs;
-
- int xs = std::max(0, x - testWSize/2);
- int xe = std::min(xsize - 1, x + testWSize/2);
- int ys = std::max(0, y - testWSize/2);
- int ye = std::min(ysize - 1, y + testWSize/2);
- for (int yl = ys; yl <= ye; yl++)
- {
- for (int xl = xs; xl <= xe; xl++)
- {
- for ( int j = 0 ; j < cr.scores.size(); j++ )
- {
- probabilities ( xl, yl, j ) = cr.scores[j];
- }
- segresult ( xl, yl ) = cr.classno;
- noveltyImage ( xl, yl ) = gpMeanVal;
- }
- }
- }
- }
- }
- void SemSegNovelty::computeNoveltyByGPMeanRatio( NICE::FloatImage & noveltyImage,
- const NICE::MultiChannelImageT<double> & feats,
- NICE::ImageT<int> & segresult,
- NICE::MultiChannelImageT<double> & probabilities,
- const int & xsize, const int & ysize, const int & featdim )
- {
- double gpNoise = 0.01;
- //TODO getMethod for GPHIK
- //conf->gD("GPHIK", "noise", 0.01);
-
- #pragma omp parallel for
- for ( int y = 0; y < ysize; y += testWSize )
- {
- Example example;
- example.vec = NULL;
- example.svec = new SparseVector ( featdim );
- for ( int x = 0; x < xsize; x += testWSize)
- {
- for ( int f = 0; f < featdim; f++ )
- {
- double val = feats.getIntegralValue ( x - whs, y - whs, x + whs, y + whs, f );
- if ( val > 1e-10 )
- ( *example.svec ) [f] = val;
- }
- example.svec->normalize();
- ClassificationResult cr = classifier->classify ( example );
- double maxMean ( -numeric_limits<double>::max() );
- double sndMaxMean ( -numeric_limits<double>::max() );
-
- for ( int j = 0 ; j < cr.scores.size(); j++ )
- {
- if ( forbidden_classesTrain.find ( j ) != forbidden_classesTrain.end() )
- {
- continue;
- }
-
- //check for larger mean without abs as well
- if (cr.scores[j] > maxMean)
- {
- sndMaxMean = maxMean;
- maxMean = cr.scores[j];
- }
- // and also for the second highest mean of all classes
- else if (cr.scores[j] > sndMaxMean)
- {
- sndMaxMean = cr.scores[j];
- }
- }
-
- //look at the difference in the absolut mean values for the most plausible class
- // and the second most plausible class
- double gpMeanRatioVal= maxMean - sndMaxMean;
- int xs = std::max(0, x - testWSize/2);
- int xe = std::min(xsize - 1, x + testWSize/2);
- int ys = std::max(0, y - testWSize/2);
- int ye = std::min(ysize - 1, y + testWSize/2);
- for (int yl = ys; yl <= ye; yl++)
- {
- for (int xl = xs; xl <= xe; xl++)
- {
- for ( int j = 0 ; j < cr.scores.size(); j++ )
- {
- probabilities ( xl, yl, j ) = cr.scores[j];
- }
- segresult ( xl, yl ) = cr.classno;
- noveltyImage ( xl, yl ) = gpMeanRatioVal;
- }
- }
-
- example.svec->clear();
- }
- delete example.svec;
- example.svec = NULL;
- }
- }
- void SemSegNovelty::computeNoveltyByGPWeightAll( NICE::FloatImage & noveltyImage,
- const NICE::MultiChannelImageT<double> & feats,
- NICE::ImageT<int> & segresult,
- NICE::MultiChannelImageT<double> & probabilities,
- const int & xsize, const int & ysize, const int & featdim )
- {
- double gpNoise = 0.01;
- //TODO getMethod for GPHIK
- //conf->gD("GPHIK", "noise", 0.01);
-
- #pragma omp parallel for
- for ( int y = 0; y < ysize; y += testWSize )
- {
- Example example;
- example.vec = NULL;
- example.svec = new SparseVector ( featdim );
- for ( int x = 0; x < xsize; x += testWSize)
- {
- for ( int f = 0; f < featdim; f++ )
- {
- double val = feats.getIntegralValue ( x - whs, y - whs, x + whs, y + whs, f );
- if ( val > 1e-10 )
- ( *example.svec ) [f] = val;
- }
- example.svec->normalize();
- ClassificationResult cr = classifier->classify ( example );
-
- double firstTerm (1.0 / sqrt(cr.uncertainty+gpNoise));
-
- double gpWeightAllVal ( 0.0 );
- if ( numberOfClasses > 2)
- {
- //compute the weight in the alpha-vector for every sample after assuming it to be
- // added to the training set.
- // Thereby, we measure its "importance" for the current model
- //
- //double firstTerm is already computed
- //
- //the second term is only needed when computing impacts
- //double secondTerm; //this is the nasty guy :/
-
- //--- compute the third term
- // this is the difference between predicted label and GT label
- std::vector<double> diffToPositive; diffToPositive.clear();
- std::vector<double> diffToNegative; diffToNegative.clear();
- double diffToNegativeSum(0.0);
-
- for ( int j = 0 ; j < cr.scores.size(); j++ )
- {
- if ( forbidden_classesTrain.find ( j ) != forbidden_classesTrain.end() )
- {
- continue;
- }
-
- // look at the difference to plus 1
- diffToPositive.push_back(abs(cr.scores[j] - 1));
- // look at the difference to -1
- diffToNegative.push_back(abs(cr.scores[j] + 1));
- //sum up the difference to -1
- diffToNegativeSum += abs(cr.scores[j] - 1);
- }
- //let's subtract for every class its diffToNegative from the sum, add its diffToPositive,
- //and use this as the third term for this specific class.
- //the final value is obtained by minimizing over all classes
- //
- // originally, we minimize over all classes after building the final score
- // however, the first and the second term do not depend on the choice of
- // y*, therefore we minimize here already
- double thirdTerm (numeric_limits<double>::max()) ;
- for(uint tmpCnt = 0; tmpCnt < diffToPositive.size(); tmpCnt++)
- {
- double tmpVal ( diffToPositive[tmpCnt] + (diffToNegativeSum-diffToNegative[tmpCnt]) );
- if (tmpVal < thirdTerm)
- thirdTerm = tmpVal;
- }
- gpWeightAllVal = thirdTerm*firstTerm;
- }
- else //binary scenario
- {
- gpWeightAllVal = std::min( abs(cr.scores[*classesInUse.begin()]+1), abs(cr.scores[*classesInUse.begin()]-1) );
- gpWeightAllVal *= firstTerm;
- }
- int xs = std::max(0, x - testWSize/2);
- int xe = std::min(xsize - 1, x + testWSize/2);
- int ys = std::max(0, y - testWSize/2);
- int ye = std::min(ysize - 1, y + testWSize/2);
- for (int yl = ys; yl <= ye; yl++)
- {
- for (int xl = xs; xl <= xe; xl++)
- {
- for ( int j = 0 ; j < cr.scores.size(); j++ )
- {
- probabilities ( xl, yl, j ) = cr.scores[j];
- }
- segresult ( xl, yl ) = cr.classno;
- noveltyImage ( xl, yl ) = gpWeightAllVal;
- }
- }
-
-
- example.svec->clear();
- }
- delete example.svec;
- example.svec = NULL;
- }
- }
- void SemSegNovelty::computeNoveltyByGPWeightRatio( NICE::FloatImage & noveltyImage,
- const NICE::MultiChannelImageT<double> & feats,
- NICE::ImageT<int> & segresult,
- NICE::MultiChannelImageT<double> & probabilities,
- const int & xsize, const int & ysize, const int & featdim )
- {
- double gpNoise = 0.01;
- //TODO getMethod for GPHIK
- //conf->gD("GPHIK", "noise", 0.01);
-
- #pragma omp parallel for
- for ( int y = 0; y < ysize; y += testWSize )
- {
- Example example;
- example.vec = NULL;
- example.svec = new SparseVector ( featdim );
- for ( int x = 0; x < xsize; x += testWSize)
- {
- for ( int f = 0; f < featdim; f++ )
- {
- double val = feats.getIntegralValue ( x - whs, y - whs, x + whs, y + whs, f );
- if ( val > 1e-10 )
- ( *example.svec ) [f] = val;
- }
- example.svec->normalize();
- ClassificationResult cr = classifier->classify ( example );
-
- double firstTerm (1.0 / sqrt(cr.uncertainty+gpNoise));
- double gpWeightRatioVal ( 0.0 );
- if ( numberOfClasses > 2)
- {
- //compute the weight in the alpha-vector for every sample after assuming it to be
- // added to the training set.
- // Thereby, we measure its "importance" for the current model
- //
- //double firstTerm is already computed
- //
- //the second term is only needed when computing impacts
- //double secondTerm; //this is the nasty guy :/
-
- //--- compute the third term
- // this is the difference between predicted label and GT label
- std::vector<double> diffToPositive; diffToPositive.clear();
- std::vector<double> diffToNegative; diffToNegative.clear();
- double diffToNegativeSum(0.0);
-
- for ( int j = 0 ; j < cr.scores.size(); j++ )
- {
- if ( forbidden_classesTrain.find ( j ) != forbidden_classesTrain.end() )
- {
- continue;
- }
-
- // look at the difference to plus 1
- diffToPositive.push_back(abs(cr.scores[j] - 1));
- }
- //let's subtract for every class its diffToNegative from the sum, add its diffToPositive,
- //and use this as the third term for this specific class.
- //the final value is obtained by minimizing over all classes
- //
- // originally, we minimize over all classes after building the final score
- // however, the first and the second term do not depend on the choice of
- // y*, therefore we minimize here already
-
- //now look on the ratio of the resulting weights for the most plausible
- // against the second most plausible class
- double thirdTermMostPlausible ( 0.0 ) ;
- double thirdTermSecondMostPlausible ( 0.0 ) ;
- for(uint tmpCnt = 0; tmpCnt < diffToPositive.size(); tmpCnt++)
- {
- if (diffToPositive[tmpCnt] > thirdTermMostPlausible)
- {
- thirdTermSecondMostPlausible = thirdTermMostPlausible;
- thirdTermMostPlausible = diffToPositive[tmpCnt];
- }
- else if (diffToPositive[tmpCnt] > thirdTermSecondMostPlausible)
- {
- thirdTermSecondMostPlausible = diffToPositive[tmpCnt];
- }
- }
- //compute the resulting score
- gpWeightRatioVal = (thirdTermMostPlausible - thirdTermSecondMostPlausible)*firstTerm;
- //finally, look for this feature how it would affect to whole model (summarized by weight-vector alpha), if we would
- //use it as an additional training example
- //TODO this would be REALLY computational demanding. Do we really want to do this?
- // gpImpactAll[s] ( pce[i].second.x, pce[i].second.y ) = thirdTerm*firstTerm*secondTerm;
- // gpImpactRatio[s] ( pce[i].second.x, pce[i].second.y ) = (thirdTermMostPlausible - thirdTermSecondMostPlausible)*firstTerm*secondTerm;
- }
- else //binary scenario
- {
- gpWeightRatioVal = std::min( abs(cr.scores[*classesInUse.begin()]+1), abs(cr.scores[*classesInUse.begin()]-1) );
- gpWeightRatioVal *= firstTerm;
- }
- int xs = std::max(0, x - testWSize/2);
- int xe = std::min(xsize - 1, x + testWSize/2);
- int ys = std::max(0, y - testWSize/2);
- int ye = std::min(ysize - 1, y + testWSize/2);
- for (int yl = ys; yl <= ye; yl++)
- {
- for (int xl = xs; xl <= xe; xl++)
- {
- for ( int j = 0 ; j < cr.scores.size(); j++ )
- {
- probabilities ( xl, yl, j ) = cr.scores[j];
- }
- segresult ( xl, yl ) = cr.classno;
- noveltyImage ( xl, yl ) = gpWeightRatioVal;
- }
- }
-
- example.svec->clear();
- }
- delete example.svec;
- example.svec = NULL;
- }
- }
- void SemSegNovelty::addNewExample(const NICE::Vector& v_newExample, const int & newClassNo)
- {
- //accept the new class as valid information
- if ( forbidden_classesTrain.find ( newClassNo ) != forbidden_classesTrain.end() )
- {
- forbidden_classesTrain.erase(newClassNo);
- numberOfClasses++;
- }
- if ( classesInUse.find ( newClassNo ) == classesInUse.end() )
- {
- classesInUse.insert( newClassNo );
- }
-
-
- //then add it to the classifier used
- if ( classifier != NULL )
- {
- if (this->classifierString.compare("GPHIKClassifier") == 0)
- {
- Example newExample;
- SparseVector svec ( v_newExample );
- newExample.svec = &svec;
- static_cast<FPCGPHIK*>(classifier)->addExample ( newExample, newClassNo );
- }
- }
- else //vclassifier
- {
- if (this->classifierString.compare("nn") == 0)
- {
- vclassifier->teach ( newClassNo, v_newExample );
- }
- }
- }
- void SemSegNovelty::addNovelExamples()
- {
- Timer timer;
-
- //show the image that contains the most novel region
- if (b_visualizeALimages)
- showImage(maskedImg, "Most novel region");
-
- timer.start();
-
- std::stringstream out;
- std::vector< std::string > list2;
- StringTools::split ( Globals::getCurrentImgFN (), '/', list2 );
- out << resultdir << "/" << list2.back();
-
- maskedImg.writePPM ( out.str() + "_run_" + NICE::intToString(this->iterationCountSuffix) + "_" + noveltyMethodString+ "_query.ppm" );
-
- timer.stop();
- std::cerr << "AL time for writing queried image: " << timer.getLast() << std::endl;
- timer.start();
-
- //check which classes will be added using the features from the novel region
- std::set<int> newClassNumbers;
- newClassNumbers.clear(); //just to be sure
- for ( uint i = 0 ; i < newTrainExamples.size() ; i++ )
- {
- if (newClassNumbers.find(newTrainExamples[i].first /* classNumber*/) == newClassNumbers.end() )
- {
- newClassNumbers.insert(newTrainExamples[i].first );
- }
- }
- //accept the new classes as valid information
- for (std::set<int>::const_iterator clNoIt = newClassNumbers.begin(); clNoIt != newClassNumbers.end(); clNoIt++)
- {
- if ( forbidden_classesTrain.find ( *clNoIt ) != forbidden_classesTrain.end() )
- {
- forbidden_classesTrain.erase(*clNoIt);
- numberOfClasses++;
- }
- if ( classesInUse.find ( *clNoIt ) == classesInUse.end() )
- {
- classesInUse.insert( *clNoIt );
- }
- }
-
- timer.stop();
- std::cerr << "AL time for accepting possible new classes: " << timer.getLast() << std::endl;
-
- timer.start();
- //then add the new features to the classifier used
- if ( classifier != NULL )
- {
- if (this->classifierString.compare("GPHIKClassifier") == 0)
- {
- classifier->addMultipleExamples ( this->newTrainExamples );
- }
- }
- else //vclassifier
- {
- //TODO
- }
-
- timer.stop();
- std::cerr << "AL time for actually updating the classifier: " << timer.getLast() << std::endl;
-
- std::cerr << "the current region to query is: " << currentRegionToQuery.first << " -- " << currentRegionToQuery.second << std::endl;
-
- //did we already query a region of this image?
- if ( queriedRegions.find( currentRegionToQuery.first ) != queriedRegions.end() )
- {
- queriedRegions[ currentRegionToQuery.first ].insert(currentRegionToQuery.second);
- }
- else
- {
- std::set<int> tmpSet; tmpSet.insert(currentRegionToQuery.second);
- queriedRegions.insert(std::pair<std::string,std::set<int> > (currentRegionToQuery.first, tmpSet ) );
- }
-
- std::cerr << "Write already queried regions: " << std::endl;
- for (std::map<std::string,std::set<int> >::const_iterator it = queriedRegions.begin(); it != queriedRegions.end(); it++)
- {
- std::cerr << "image: " << it->first << " -- ";
- for (std::set<int>::const_iterator itReg = it->second.begin(); itReg != it->second.end(); itReg++)
- {
- std::cerr << *itReg << " ";
- }
- std::cerr << std::endl;
- }
-
- //clear the latest results, since one iteration is over
- globalMaxUncert = -numeric_limits<double>::max();
- if (!mostNoveltyWithMaxScores)
- globalMaxUncert = numeric_limits<double>::max();
- }
- const Examples * SemSegNovelty::getNovelExamples() const
- {
- return &(this->newTrainExamples);
- }
- ///////////////////// INTERFACE PERSISTENT /////////////////////
- // interface specific methods for store and restore
- ///////////////////// INTERFACE PERSISTENT /////////////////////
- void SemSegNovelty::restore ( std::istream & is, int format )
- {
- //delete everything we knew so far...
- this->clear();
-
- bool b_restoreVerbose ( false );
- #ifdef B_RESTOREVERBOSE
- b_restoreVerbose = true;
- #endif
-
- if ( is.good() )
- {
- if ( b_restoreVerbose )
- std::cerr << " restore SemSegNovelty" << std::endl;
-
- std::string tmp;
- is >> tmp; //class name
-
- if ( ! this->isStartTag( tmp, "SemSegNovelty" ) )
- {
- std::cerr << " WARNING - attempt to restore SemSegNovelty, but start flag " << tmp << " does not match! Aborting... " << std::endl;
- throw;
- }
-
- if (classifier != NULL)
- {
- delete classifier;
- classifier = NULL;
- }
-
- is.precision (numeric_limits<double>::digits10 + 1);
-
- bool b_endOfBlock ( false ) ;
-
- while ( !b_endOfBlock )
- {
- is >> tmp; // start of block
-
- if ( this->isEndTag( tmp, "SemSegNovelty" ) )
- {
- b_endOfBlock = true;
- continue;
- }
-
- tmp = this->removeStartTag ( tmp );
-
- if ( b_restoreVerbose )
- std::cerr << " currently restore section " << tmp << " in SemSegNovelty" << std::endl;
-
-
- ///////////////////////////////
- // FEATURE EXTRACTION //
- ///////////////////////////////
- if ( tmp.compare("featExtract") == 0 )
- {
- featExtract->restore(is, format);
- is >> tmp; // end of block
- tmp = this->removeEndTag ( tmp );
- }
- else if ( tmp.compare("trainWSize") == 0 )
- {
- is >> trainWSize;
- is >> tmp; // end of block
- tmp = this->removeEndTag ( tmp );
- }
- else if ( tmp.compare("whs") == 0 )
- {
- is >> whs;
- is >> tmp; // end of block
- tmp = this->removeEndTag ( tmp );
- }
- else if ( tmp.compare("testWSize") == 0 )
- {
- is >> testWSize;
- is >> tmp; // end of block
- tmp = this->removeEndTag ( tmp );
- }
- ///////////////////////////////
- // NOVELTY COMPUTATION //
- ///////////////////////////////
- else if ( tmp.compare("noveltyMethod") == 0 )
- {
- unsigned int ui_noveltyMethod;
- is >> ui_noveltyMethod;
- this->noveltyMethod = static_cast<NoveltyMethod> ( ui_noveltyMethod );
-
- is >> tmp; // end of block
- tmp = this->removeEndTag ( tmp );
- }
- else if ( tmp.compare("noveltyMethodString") == 0 )
- {
- is >> noveltyMethodString;
- is >> tmp; // end of block
- tmp = this->removeEndTag ( tmp );
- }
- else if ( tmp.compare("globalMaxUncert") == 0 )
- {
- is >> globalMaxUncert;
- is >> tmp; // end of block
- tmp = this->removeEndTag ( tmp );
- }
- else if ( tmp.compare("mostNoveltyWithMaxScores") == 0 )
- {
- is >> mostNoveltyWithMaxScores;
- is >> tmp; // end of block
- tmp = this->removeEndTag ( tmp );
- }
- else if ( tmp.compare("findMaximumUncert") == 0 )
- {
- is >> findMaximumUncert;
- is >> tmp; // end of block
- tmp = this->removeEndTag ( tmp );
- }
- //TODO maskedImg
- else if ( tmp.compare("b_visualizeALimages") == 0 )
- {
- is >> b_visualizeALimages;
- is >> tmp; // end of block
- tmp = this->removeEndTag ( tmp );
- }
- ///////////////////////////////
- // CLASSIFICATION STUFF //
- ///////////////////////////////
- else if ( tmp.compare("classifier") == 0 )
- {
- std::string isNull;
- is >> isNull;
-
- // check whether we originally used a classifier
- if ( isNull.compare( "NULL" ) == 0 )
- {
- if ( classifier != NULL )
- delete classifier;
- classifier = NULL;
- }
- else
- {
- if ( classifier == NULL )
- classifier = new OBJREC::FPCGPHIK();
- classifier->restore(is, format);
- }
-
- is >> tmp; // end of block
- tmp = this->removeEndTag ( tmp );
- }
- else if ( tmp.compare("vclassifier") == 0 )
- {
- std::string isNull;
- is >> isNull;
-
- // check whether we originally used a vclassifier
- if ( isNull.compare( "NULL" ) == 0 )
- {
- if ( vclassifier != NULL )
- delete vclassifier;
- vclassifier = NULL;
- }
- else
- {
- fthrow ( NICE::Exception, "Restoring of VecClassifiers is not implemented yet!" );
- /* if ( vclassifier == NULL )
- vclassifier = new OBJREC::VecClassifier();
- vclassifier->restore(is, format); */
- }
-
- is >> tmp; // end of block
- tmp = this->removeEndTag ( tmp );
- }
- else if ( tmp.compare("forbidden_classesTrain") == 0 )
- {
- is >> tmp; // size
- int forbClTrainSize ( 0 );
- is >> forbClTrainSize;
- forbidden_classesTrain.clear();
-
- if ( b_restoreVerbose )
- std::cerr << "restore forbidden_classesTrain with size: " << forbClTrainSize << std::endl;
- if ( forbClTrainSize > 0 )
- {
- if ( b_restoreVerbose )
- std::cerr << " restore forbidden_classesTrain" << std::endl;
-
- for (int i = 0; i < forbClTrainSize; i++)
- {
- int classNo;
- is >> classNo;
- forbidden_classesTrain.insert ( classNo );
- }
- }
- else
- {
- if ( b_restoreVerbose )
- std::cerr << " skip restoring forbidden_classesTrain" << std::endl;
- }
-
- is >> tmp; // end of block
- tmp = this->removeEndTag ( tmp );
- }
- else if ( tmp.compare("forbidden_classesActiveLearning") == 0 )
- {
- is >> tmp; // size
- int forbClALSize ( 0 );
- is >> forbClALSize;
- forbidden_classesActiveLearning.clear();
-
- if ( b_restoreVerbose )
- std::cerr << "restore forbidden_classesActiveLearning with size: " << forbClALSize << std::endl;
- if ( forbClALSize > 0 )
- {
- if ( b_restoreVerbose )
- std::cerr << " restore forbidden_classesActiveLearning" << std::endl;
-
- for (int i = 0; i < forbClALSize; i++)
- {
- int classNo;
- is >> classNo;
- forbidden_classesActiveLearning.insert ( classNo );
- }
- }
- else
- {
- if ( b_restoreVerbose )
- std::cerr << " skip restoring forbidden_classesActiveLearning" << std::endl;
- }
-
- is >> tmp; // end of block
- tmp = this->removeEndTag ( tmp );
- }
- else if ( tmp.compare("classesInUse") == 0 )
- {
- is >> tmp; // size
- int clInUseSize ( 0 );
- is >> clInUseSize;
- classesInUse.clear();
-
- if ( b_restoreVerbose )
- std::cerr << "restore classesInUse with size: " << clInUseSize << std::endl;
- if ( clInUseSize > 0 )
- {
- if ( b_restoreVerbose )
- std::cerr << " restore classesInUse" << std::endl;
-
- for (int i = 0; i < clInUseSize; i++)
- {
- int classNo;
- is >> classNo;
- classesInUse.insert ( classNo );
- }
- }
- else
- {
- if ( b_restoreVerbose )
- std::cerr << " skip restoring classesInUse" << std::endl;
- }
-
- is >> tmp; // end of block
- tmp = this->removeEndTag ( tmp );
- }
- else if ( tmp.compare("numberOfClasses") == 0 )
- {
- is >> numberOfClasses;
- is >> tmp; // end of block
- tmp = this->removeEndTag ( tmp );
- }
- else if ( tmp.compare("read_classifier") == 0 )
- {
- is >> read_classifier;
- is >> tmp; // end of block
- tmp = this->removeEndTag ( tmp );
- }
- else if ( tmp.compare("save_classifier") == 0 )
- {
- is >> save_classifier;
- is >> tmp; // end of block
- tmp = this->removeEndTag ( tmp );
- }
- else if ( tmp.compare("cache") == 0 )
- {
- is >> cache;
- is >> tmp; // end of block
- tmp = this->removeEndTag ( tmp );
- }
- else if ( tmp.compare("resultdir") == 0 )
- {
- is >> resultdir;
- is >> tmp; // end of block
- tmp = this->removeEndTag ( tmp );
- }
- //TODO newTrainExamples
- ///////////////////////////////
- // SEGMENTATION STUFF //
- ///////////////////////////////
- //TODO regionSeg
- else if ( tmp.compare("s_rsMethode") == 0 )
- {
- is >> this->s_rsMethode;
- // theoretically, we should properly store and restore the regionSeg object. However, its parent class does not provide
- // a Persistent interface yet. Hence, we perform this tiny workaround which works, since regionSeg is not changed over time...
- // only be aware of parameters originally set via config...
- is >> tmp; // end of block
- tmp = this->removeEndTag ( tmp );
- }
- //NOTE regionSeg seems really important to keep track off
- else if ( tmp.compare("reuseSegmentation") == 0 )
- {
- is >> reuseSegmentation;
- is >> tmp; // end of block
- tmp = this->removeEndTag ( tmp );
- }
- else if ( tmp.compare("queriedRegions") == 0 )
- {
- is >> tmp; // size
- int queriedRegionsSize ( 0 );
- is >> queriedRegionsSize;
- queriedRegions.clear();
- if ( b_restoreVerbose )
- std::cerr << "restore queriedRegions with size: " << queriedRegionsSize << std::endl;
- for ( int i = 0; i < queriedRegionsSize; i++ )
- {
- // restore key
- std::string key;
- is >> key;
-
- // restore values -- inner loop over sets
- is >> tmp; // size
- int regionsOfImgSize ( 0 );
- is >> regionsOfImgSize;
- std::set< int > regionsOfImg;
- regionsOfImg.clear();
-
- for (int i = 0; i < regionsOfImgSize; i++)
- {
- int idxRegion;
- is >> idxRegion;
- regionsOfImg.insert ( idxRegion );
- }
- queriedRegions.insert ( std::pair<std::string, std::set< int > > ( key, regionsOfImg ) );
- }
-
- is >> tmp; // end of block
- tmp = this->removeEndTag ( tmp );
- }
- //
- //TODO currentRegionToQuery
- //
- ///////////////////////////////
- // PARENT OBJECT //
- ///////////////////////////////
- else if ( tmp.compare("SemSegNovelty--Parent") == 0 )
- {
- // restore parent object
- SemanticSegmentation::restore(is);
- }
- else
- {
- std::cerr << "WARNING -- unexpected SemSegNovelty object -- " << tmp << " -- for restoration... aborting" << std::endl;
- throw;
- }
-
- // INSTANTIATE (YET) NON-RESTORABLE OBJECTS
- //TODO destructor of regionSeg is non-virtual so far - change this accordingly!
- if ( this->regionSeg != NULL )
- delete this->regionSeg;
-
- if( this->s_rsMethode == "none" )
- {
- this->regionSeg = NULL;
- }
- else
- {
- //NOTE using an empty config file might not be save...
- NICE::Config tmpConfEmpty;
- RegionSegmentationMethod *tmpRegionSeg = GenericRegionSegmentationMethodSelection::selectRegionSegmentationMethod( &tmpConfEmpty, this->s_rsMethode );
- if ( reuseSegmentation )
- this->regionSeg = new RSCache ( &tmpConfEmpty, tmpRegionSeg );
- else
- this->regionSeg = tmpRegionSeg;
- }
-
- // done restoration
- }
- }
- else
- {
- std::cerr << "SemSegNovelty::restore -- InStream not initialized - restoring not possible!" << std::endl;
- throw;
- }
-
-
-
- }
- void SemSegNovelty::store ( std::ostream & os, int format ) const
- {
- if (os.good())
- {
- // show starting point
- os << this->createStartTag( "SemSegNovelty" ) << std::endl;
-
- ///////////////////////////////
- // FEATURE EXTRACTION //
- ///////////////////////////////
- os << this->createStartTag( "featExtract" ) << std::endl;
- featExtract->store ( os );
- os << this->createStartTag( "featExtract" ) << std::endl;
-
- os << this->createStartTag( "trainWsize" ) << std::endl;
- os << this->trainWSize << std::endl;
- os << this->createStartTag( "trainWsize" ) << std::endl;
-
- os << this->createStartTag( "whs" ) << std::endl;
- os << this->whs << std::endl;
- os << this->createStartTag( "whs" ) << std::endl;
-
- os << this->createStartTag( "testWSize" ) << std::endl;
- os << this->testWSize << std::endl;
- os << this->createStartTag( "testWSize" ) << std::endl;
-
- ///////////////////////////////
- // NOVELTY COMPUTATION //
- ///////////////////////////////
-
- os << this->createStartTag( "noveltyMethod" ) << std::endl;
- os << this->noveltyMethod << std::endl;
- os << this->createStartTag( "noveltyMethod" ) << std::endl;
- os << this->createStartTag( "noveltyMethodString" ) << std::endl;
- os << this->noveltyMethodString << std::endl;
- os << this->createStartTag( "noveltyMethodString" ) << std::endl;
-
- os << this->createStartTag( "globalMaxUncert" ) << std::endl;
- os << this->globalMaxUncert << std::endl;
- os << this->createStartTag( "globalMaxUncert" ) << std::endl;
- os << this->createStartTag( "mostNoveltyWithMaxScores" ) << std::endl;
- os << this->mostNoveltyWithMaxScores << std::endl;
- os << this->createStartTag( "mostNoveltyWithMaxScores" ) << std::endl;
- os << this->createStartTag( "findMaximumUncert" ) << std::endl;
- os << this->findMaximumUncert << std::endl;
- os << this->createStartTag( "findMaximumUncert" ) << std::endl;
- //TODO maskedImg
-
- os << this->createStartTag( "b_visualizeALimages" ) << std::endl;
- os << this->b_visualizeALimages << std::endl;
- os << this->createStartTag( "b_visualizeALimages" ) << std::endl;
-
- ///////////////////////////////
- // CLASSIFICATION STUFF //
- ///////////////////////////////
-
- os << this->createStartTag( "classifierString" ) << std::endl;
- os << this->classifierString << std::endl;
- os << this->createStartTag( "classifierString" ) << std::endl;
- os << this->createStartTag( "classifier" ) << std::endl;
- if ( this->classifier != NULL )
- {
- os << "NOTNULL" << std::endl;
- classifier->store ( os, format );
- }
- else
- {
- os << "NULL" << std::endl;
- }
- os << this->createEndTag( "classifier" ) << std::endl;
-
- //
-
- os << this->createStartTag( "vclassifier" ) << std::endl;
- if ( this->classifier != NULL )
- {
- os << "NOTNULL" << std::endl;
- vclassifier->store ( os, format );
- }
- else
- {
- os << "NULL" << std::endl;
- }
- os << this->createEndTag( "vclassifier" ) << std::endl;
-
-
- os << this->createStartTag( "forbidden_classesTrain" ) << std::endl;
- os << "size: " << forbidden_classesTrain.size() << std::endl;
- for ( std::set< int >::const_iterator itForbClassTrain = forbidden_classesTrain.begin();
- itForbClassTrain != forbidden_classesTrain.end();
- itForbClassTrain++
- )
- {
- os << *itForbClassTrain << " " << std::endl;
- }
- os << this->createEndTag( "forbidden_classesTrain" ) << std::endl;
-
- //
-
- os << this->createStartTag( "forbidden_classesActiveLearning" ) << std::endl;
- os << "size: " << forbidden_classesActiveLearning.size() << std::endl;
- for ( std::set< int >::const_iterator itForbClassAL = forbidden_classesActiveLearning.begin();
- itForbClassAL != forbidden_classesActiveLearning.end();
- itForbClassAL++
- )
- {
- os << *itForbClassAL << " " << std::endl;
- }
- os << this->createEndTag( "forbidden_classesActiveLearning" ) << std::endl;
-
- //
-
- os << this->createStartTag( "classesInUse" ) << std::endl;
- os << "size: " << classesInUse.size() << std::endl;
- for ( std::set< int >::const_iterator itClassesInUse = classesInUse.begin();
- itClassesInUse != classesInUse.end();
- itClassesInUse++
- )
- {
- os << *itClassesInUse << " " << std::endl;
- }
- os << this->createEndTag( "classesInUse" ) << std::endl;
-
-
- os << this->createStartTag( "numberOfClasses" ) << std::endl;
- os << this->numberOfClasses << std::endl;
- os << this->createStartTag( "numberOfClasses" ) << std::endl;
-
-
- os << this->createStartTag( "read_classifier" ) << std::endl;
- os << this->read_classifier << std::endl;
- os << this->createStartTag( "read_classifier" ) << std::endl;
-
-
- os << this->createStartTag( "save_classifier" ) << std::endl;
- os << this->save_classifier << std::endl;
- os << this->createStartTag( "save_classifier" ) << std::endl;
-
-
- os << this->createStartTag( "cache" ) << std::endl;
- os << this->cache << std::endl;
- os << this->createStartTag( "cache" ) << std::endl;
-
-
- os << this->createStartTag( "resultdir" ) << std::endl;
- os << this->resultdir << std::endl;
- os << this->createStartTag( "resultdir" ) << std::endl;
- //TODO newTrainExamples
-
- ///////////////////////////////
- // SEGMENTATION STUFF //
- ///////////////////////////////
-
- // theoretically, we should properly store and restore the regionSeg object. However, its parent class does not provide
- // a Persistent interface yet. Hence, we perform this tiny workaround which works, since regionSeg is not changed over time...
- // only be aware of parameters originally set via config...
- os << this->createStartTag( "s_rsMethode" ) << std::endl;
- os << this->s_rsMethode << std::endl;
- os << this->createStartTag( "s_rsMethode" ) << std::endl;
-
- os << this->createStartTag( "reuseSegmentation" ) << std::endl;
- os << this->reuseSegmentation << std::endl;
- os << this->createStartTag( "reuseSegmentation" ) << std::endl;
-
- os << this->createStartTag( "queriedRegions" ) << std::endl;
- os << "size: " << queriedRegions.size() << std::endl;
- std::map< std::string, std::set< int > >::const_iterator itQueriedRegions = queriedRegions.begin();
- for ( uint i = 0; i < queriedRegions.size(); i++ )
- {
- // store key
- os << itQueriedRegions->first << std::endl;
-
- // store values -- inner loop over sets
- os << "size: " << ( itQueriedRegions->second ).size() << std::endl;
- for ( std::set< int >::const_iterator itRegionsOfImg = ( itQueriedRegions->second ).begin();
- itRegionsOfImg != ( itQueriedRegions->second ).end();
- itRegionsOfImg++
- )
- {
- os << *itRegionsOfImg << " " << std::endl;
- }
-
- itQueriedRegions++;
- }
- os << this->createStartTag( "queriedRegions" ) << std::endl;
- //
- //TODO currentRegionToQuery
-
-
- ///////////////////////////////
- // PARENT OBJECT //
- ///////////////////////////////
- os << this->createStartTag( "SemSegNovelty--Parent" ) << std::endl;
- SemanticSegmentation::store(os);
- os << this->createStartTag( "SemSegNovelty--Parent" ) << std::endl;
-
-
- // done
- os << this->createEndTag( "SemSegNovelty" ) << std::endl;
- }
- else
- {
- std::cerr << "OutStream not initialized - storing not possible!" << std::endl;
- }
- }
- void SemSegNovelty::clear ()
- {
- //TODO
- }
|