|
@@ -3,6 +3,7 @@
|
|
|
|
|
|
#include "SemSegNovelty.h"
|
|
|
|
|
|
+#include "core/image/FilterT.h"
|
|
|
#include "fast-hik/GPHIKClassifier.h"
|
|
|
#include "vislearning/baselib/ICETools.h"
|
|
|
#include "vislearning/baselib/Globals.h"
|
|
@@ -20,17 +21,21 @@ SemSegNovelty::SemSegNovelty ( const Config *conf,
|
|
|
{
|
|
|
this->conf = conf;
|
|
|
|
|
|
+ string section = "SemSegNovelty";
|
|
|
+
|
|
|
featExtract = new LFColorWeijer ( conf );
|
|
|
|
|
|
save_cache = conf->gB ( "FPCPixel", "save_cache", true );
|
|
|
read_cache = conf->gB ( "FPCPixel", "read_cache", false );
|
|
|
- uncertdir = conf->gS("debug", "uncertainty","uncertainty");
|
|
|
+ uncertdir = conf->gS("debug", "uncertainty", "uncertainty");
|
|
|
cache = conf->gS ( "cache", "root", "" );
|
|
|
|
|
|
+
|
|
|
classifier = new GPHIKClassifier ( conf, "ClassiferGPHIK" );;
|
|
|
|
|
|
- whs = conf->gI ( "SemSegNovelty", "window_size", 10 );
|
|
|
- featdist = conf->gI ( "SemSegNovelty", "grid", 10 );
|
|
|
+ whs = conf->gI ( section, "window_size", 10 );
|
|
|
+ featdist = conf->gI ( section, "grid", 10 );
|
|
|
+ testWSize = conf->gI (section, "test_window_size", 10);
|
|
|
|
|
|
cn = md->getClassNames ( "train" );
|
|
|
|
|
@@ -134,6 +139,16 @@ void SemSegNovelty::train ( const MultiDataset *md )
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
for ( int c = 0; c < featdim; c++ )
|
|
@@ -150,7 +165,7 @@ void SemSegNovelty::train ( const MultiDataset *md )
|
|
|
if ( forbidden_classes.find ( classno ) != forbidden_classes.end() )
|
|
|
continue;
|
|
|
|
|
|
-
|
|
|
+
|
|
|
Example example;
|
|
|
example.vec = NULL;
|
|
|
example.svec = new SparseVector ( featdim );
|
|
@@ -160,9 +175,9 @@ void SemSegNovelty::train ( const MultiDataset *md )
|
|
|
if ( val > 1e-10 )
|
|
|
( *example.svec ) [f] = val;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
example.svec->normalize();
|
|
|
-
|
|
|
+
|
|
|
example.position = imgnb;
|
|
|
examples.push_back ( pair<int, Example> ( classno, example ) );
|
|
|
}
|
|
@@ -218,7 +233,7 @@ void SemSegNovelty::semanticseg ( CachedExample *ce, NICE::Image & segresult, NI
|
|
|
{
|
|
|
Timer timer;
|
|
|
timer.start();
|
|
|
-
|
|
|
+
|
|
|
Examples examples;
|
|
|
examples.filename = "testing";
|
|
|
|
|
@@ -232,9 +247,9 @@ void SemSegNovelty::semanticseg ( CachedExample *ce, NICE::Image & segresult, NI
|
|
|
int xsize, ysize;
|
|
|
ce->getImageSize ( xsize, ysize );
|
|
|
|
|
|
- probabilities.reInit( xsize, ysize, cn.getMaxClassno()+1);
|
|
|
+ probabilities.reInit( xsize, ysize, cn.getMaxClassno() + 1);
|
|
|
probabilities.set ( 0.0 );
|
|
|
-
|
|
|
+
|
|
|
NICE::ColorImage img;
|
|
|
try {
|
|
|
img = ColorImage ( currentFile );
|
|
@@ -248,7 +263,17 @@ void SemSegNovelty::semanticseg ( CachedExample *ce, NICE::Image & segresult, NI
|
|
|
|
|
|
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;
|
|
|
+
|
|
|
|
|
|
for ( int c = 0; c < featdim; c++ )
|
|
|
{
|
|
@@ -263,12 +288,12 @@ void SemSegNovelty::semanticseg ( CachedExample *ce, NICE::Image & segresult, NI
|
|
|
cout << "first: " << timer.getLastAbsolute() << endl;
|
|
|
timer.start();
|
|
|
#pragma omp parallel for
|
|
|
- for ( int y = 0; y < ysize; y++ )
|
|
|
+ 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++ )
|
|
|
+ for ( int x = 0; x < xsize; x += testWSize)
|
|
|
{
|
|
|
for ( int f = 0; f < featdim; f++ )
|
|
|
{
|
|
@@ -277,29 +302,40 @@ void SemSegNovelty::semanticseg ( CachedExample *ce, NICE::Image & segresult, NI
|
|
|
( *example.svec ) [f] = val;
|
|
|
}
|
|
|
example.svec->normalize();
|
|
|
-
|
|
|
+
|
|
|
ClassificationResult cr = classifier->classify ( example );
|
|
|
|
|
|
- for ( int j = 0 ; j < cr.scores.size(); j++ )
|
|
|
+ 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++)
|
|
|
{
|
|
|
- probabilities ( x, y, j ) = cr.scores[j];
|
|
|
+ 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;
|
|
|
+ uncert ( xl, yl ) = cr.uncertainty;
|
|
|
+ }
|
|
|
}
|
|
|
- segresult ( x, y ) = cr.classno;
|
|
|
- if(maxunc < cr.uncertainty)
|
|
|
+
|
|
|
+ if (maxunc < cr.uncertainty)
|
|
|
maxunc = cr.uncertainty;
|
|
|
- uncert ( x, y ) = cr.uncertainty;
|
|
|
example.svec->clear();
|
|
|
}
|
|
|
delete example.svec;
|
|
|
example.svec = NULL;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
cout << "maxunertainty: " << maxunc << endl;
|
|
|
|
|
|
timer.stop();
|
|
|
cout << "second: " << timer.getLastAbsolute() << endl;
|
|
|
timer.start();
|
|
|
-
|
|
|
+
|
|
|
ColorImage imgrgb ( xsize, ysize );
|
|
|
|
|
|
std::stringstream out;
|
|
@@ -307,13 +343,13 @@ void SemSegNovelty::semanticseg ( CachedExample *ce, NICE::Image & segresult, NI
|
|
|
StringTools::split ( Globals::getCurrentImgFN (), '/', list2 );
|
|
|
out << uncertdir << "/" << list2.back();
|
|
|
|
|
|
- uncert.writeRaw(out.str()+".rawfloat");
|
|
|
- uncert(0,0) = 0.0;
|
|
|
- uncert(0,1) = 1.0;
|
|
|
+ uncert.writeRaw(out.str() + ".rawfloat");
|
|
|
+ uncert(0, 0) = 0.0;
|
|
|
+ uncert(0, 1) = 1.0;
|
|
|
ICETools::convertToRGB ( uncert, imgrgb );
|
|
|
imgrgb.write ( out.str() + "rough.png" );
|
|
|
|
|
|
-
|
|
|
+
|
|
|
timer.stop();
|
|
|
cout << "last: " << timer.getLastAbsolute() << endl;
|
|
|
}
|