|
@@ -78,10 +78,11 @@ void segmentToOverlay ( const NICE::Image *orig, const NICE::ColorImage & segmen
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-void updateMatrix ( const NICE::Image & img,
|
|
|
|
- const NICE::Image & gt,
|
|
|
|
|
|
+void updateMatrix ( const NICE::ImageT<int> & img,
|
|
|
|
+ const NICE::ImageT<int> & gt,
|
|
NICE::Matrix & M,
|
|
NICE::Matrix & M,
|
|
- const set<int> & forbidden_classes )
|
|
|
|
|
|
+ const set<int> & forbidden_classes,
|
|
|
|
+ map<int,int> & classMapping )
|
|
{
|
|
{
|
|
double subsamplex = gt.width() / ( double ) img.width();
|
|
double subsamplex = gt.width() / ( double ) img.width();
|
|
double subsampley = gt.height() / ( double ) img.height();
|
|
double subsampley = gt.height() / ( double ) img.height();
|
|
@@ -106,7 +107,7 @@ void updateMatrix ( const NICE::Image & img,
|
|
|
|
|
|
if ( forbidden_classes.find ( gimg ) == forbidden_classes.end() )
|
|
if ( forbidden_classes.find ( gimg ) == forbidden_classes.end() )
|
|
{
|
|
{
|
|
- M ( gimg, cimg ) ++;
|
|
|
|
|
|
+ M ( classMapping[gimg], classMapping[cimg] ) ++;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -117,6 +118,7 @@ void startClassification (SemanticSegmentation *semseg,
|
|
const LabeledSet* testFiles,
|
|
const LabeledSet* testFiles,
|
|
const ClassNames & classNames,
|
|
const ClassNames & classNames,
|
|
const set<int> & forbidden_classes,
|
|
const set<int> & forbidden_classes,
|
|
|
|
+ map<int,int> & classMapping,
|
|
const string & resultdir,
|
|
const string & resultdir,
|
|
const bool doCrossVal)
|
|
const bool doCrossVal)
|
|
{
|
|
{
|
|
@@ -135,8 +137,8 @@ void startClassification (SemanticSegmentation *semseg,
|
|
semseg->getDepthVector ( testFiles, zsizeVec, run_3Dseg );
|
|
semseg->getDepthVector ( testFiles, zsizeVec, run_3Dseg );
|
|
int depthCount = 0, idx = 0;
|
|
int depthCount = 0, idx = 0;
|
|
vector< string > filelist;
|
|
vector< string > filelist;
|
|
- NICE::MultiChannelImageT<double> segresult;
|
|
|
|
- NICE::MultiChannelImageT<double> gt;
|
|
|
|
|
|
+ NICE::MultiChannelImageT<int> segresult;
|
|
|
|
+ NICE::MultiChannelImageT<int> gt;
|
|
|
|
|
|
for (LabeledSet::const_iterator it = testFiles->begin(); it != testFiles->end(); it++)
|
|
for (LabeledSet::const_iterator it = testFiles->begin(); it != testFiles->end(); it++)
|
|
{
|
|
{
|
|
@@ -148,8 +150,8 @@ void startClassification (SemanticSegmentation *semseg,
|
|
filelist.push_back ( file );
|
|
filelist.push_back ( file );
|
|
depthCount++;
|
|
depthCount++;
|
|
|
|
|
|
- NICE::Image lm;
|
|
|
|
- NICE::Image lm_gt;
|
|
|
|
|
|
+ NICE::ImageT<int> lm;
|
|
|
|
+ NICE::ImageT<int> lm_gt;
|
|
if ( info.hasLocalizationInfo() )
|
|
if ( info.hasLocalizationInfo() )
|
|
{
|
|
{
|
|
const LocalizationResult *l_gt = info.localization();
|
|
const LocalizationResult *l_gt = info.localization();
|
|
@@ -205,9 +207,9 @@ void startClassification (SemanticSegmentation *semseg,
|
|
}
|
|
}
|
|
|
|
|
|
// confusion matrix
|
|
// confusion matrix
|
|
- NICE::Matrix M ( classNames.getMaxClassno() + 1, classNames.getMaxClassno() + 1 );
|
|
|
|
|
|
+ NICE::Matrix M ( classMapping.size(), classMapping.size() );
|
|
M.set ( 0 );
|
|
M.set ( 0 );
|
|
- updateMatrix ( lm, lm_gt, M, forbidden_classes );
|
|
|
|
|
|
+ updateMatrix ( lm, lm_gt, M, forbidden_classes, classMapping );
|
|
M_vec.push_back ( M );
|
|
M_vec.push_back ( M );
|
|
|
|
|
|
classNames.labelToRGB ( lm, rgb );
|
|
classNames.labelToRGB ( lm, rgb );
|
|
@@ -315,6 +317,23 @@ int main ( int argc, char **argv )
|
|
classNames.getSelection ( conf.gS ( "analysis", "forbidden_classes", "" ),
|
|
classNames.getSelection ( conf.gS ( "analysis", "forbidden_classes", "" ),
|
|
forbidden_classes );
|
|
forbidden_classes );
|
|
|
|
|
|
|
|
+ vector<bool> usedClasses ( classNames.numClasses(), true );
|
|
|
|
+ for ( set<int>::const_iterator it = forbidden_classes.begin();
|
|
|
|
+ it != forbidden_classes.end(); ++it)
|
|
|
|
+ {
|
|
|
|
+ usedClasses [ *it ] = false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ map<int,int> classMapping;
|
|
|
|
+ int j = 0;
|
|
|
|
+ for ( int i = 0; i < usedClasses.size(); i++ )
|
|
|
|
+ if (usedClasses[i])
|
|
|
|
+ {
|
|
|
|
+ classMapping[i] = j;
|
|
|
|
+ j++;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
// initialize semantic segmentation method
|
|
// initialize semantic segmentation method
|
|
SemanticSegmentation *semseg = NULL;
|
|
SemanticSegmentation *semseg = NULL;
|
|
|
|
|
|
@@ -332,7 +351,7 @@ int main ( int argc, char **argv )
|
|
cout << "##############\n" << endl;
|
|
cout << "##############\n" << endl;
|
|
const LabeledSet *testFiles = md["test"];
|
|
const LabeledSet *testFiles = md["test"];
|
|
startClassification (semseg, M_vec, conf, testFiles, classNames,
|
|
startClassification (semseg, M_vec, conf, testFiles, classNames,
|
|
- forbidden_classes, resultdir, doCrossVal );
|
|
|
|
|
|
+ forbidden_classes, classMapping, resultdir, doCrossVal );
|
|
|
|
|
|
delete semseg;
|
|
delete semseg;
|
|
}
|
|
}
|
|
@@ -357,7 +376,7 @@ int main ( int argc, char **argv )
|
|
cout << "#################\n" << endl;
|
|
cout << "#################\n" << endl;
|
|
const LabeledSet *testFiles = md[cvaltest];
|
|
const LabeledSet *testFiles = md[cvaltest];
|
|
startClassification (semseg, M_vec, conf, testFiles, classNames,
|
|
startClassification (semseg, M_vec, conf, testFiles, classNames,
|
|
- forbidden_classes, resultdir, doCrossVal );
|
|
|
|
|
|
+ forbidden_classes, classMapping, resultdir, doCrossVal );
|
|
|
|
|
|
delete semseg;
|
|
delete semseg;
|
|
}
|
|
}
|
|
@@ -379,13 +398,12 @@ int main ( int argc, char **argv )
|
|
double overall = 0.0;
|
|
double overall = 0.0;
|
|
double sumall = 0.0;
|
|
double sumall = 0.0;
|
|
|
|
|
|
- NICE::Matrix M ( classNames.getMaxClassno() + 1, classNames.getMaxClassno() + 1 );
|
|
|
|
|
|
+ NICE::Matrix M ( classMapping.size(), classMapping.size() );
|
|
M.set ( 0 );
|
|
M.set ( 0 );
|
|
for ( int s = 0; s < ( int ) M_vec.size(); s++ )
|
|
for ( int s = 0; s < ( int ) M_vec.size(); s++ )
|
|
{
|
|
{
|
|
NICE::Matrix M_tmp = M_vec[s];
|
|
NICE::Matrix M_tmp = M_vec[s];
|
|
for ( int r = 0; r < ( int ) M_tmp.rows(); r++ )
|
|
for ( int r = 0; r < ( int ) M_tmp.rows(); r++ )
|
|
- {
|
|
|
|
for ( int c = 0; c < ( int ) M_tmp.cols(); c++ )
|
|
for ( int c = 0; c < ( int ) M_tmp.cols(); c++ )
|
|
{
|
|
{
|
|
if ( r == c )
|
|
if ( r == c )
|
|
@@ -394,23 +412,22 @@ int main ( int argc, char **argv )
|
|
sumall += M_tmp ( r, c );
|
|
sumall += M_tmp ( r, c );
|
|
M ( r, c ) += M_tmp ( r, c );
|
|
M ( r, c ) += M_tmp ( r, c );
|
|
}
|
|
}
|
|
- }
|
|
|
|
}
|
|
}
|
|
overall /= sumall;
|
|
overall /= sumall;
|
|
|
|
|
|
cout << "Confusion Matrix:" << endl;
|
|
cout << "Confusion Matrix:" << endl;
|
|
|
|
+ cout.precision(4);
|
|
for (int r = 0; r < (int) M.rows(); r++)
|
|
for (int r = 0; r < (int) M.rows(); r++)
|
|
{
|
|
{
|
|
for (int c = 0; c < (int) M.cols(); c++)
|
|
for (int c = 0; c < (int) M.cols(); c++)
|
|
- {
|
|
|
|
- cout << M(r,c) << " ";
|
|
|
|
- }
|
|
|
|
|
|
+ cout << M(r,c)/sumall << " ";
|
|
|
|
+
|
|
cout << endl;
|
|
cout << endl;
|
|
}
|
|
}
|
|
|
|
|
|
// metrics for binary classification
|
|
// metrics for binary classification
|
|
double precision, recall, f1score = -1.0;
|
|
double precision, recall, f1score = -1.0;
|
|
- if (classNames.getMaxClassno()+1 == 2)
|
|
|
|
|
|
+ if (classNames.numClasses() == 2)
|
|
{
|
|
{
|
|
precision = (double)M(1,1) / (double)(M(1,1)+M(0,1));
|
|
precision = (double)M(1,1) / (double)(M(1,1)+M(0,1));
|
|
recall = (double)M(1,1) / (double)(M(1,1)+M(1,0));
|
|
recall = (double)M(1,1) / (double)(M(1,1)+M(1,0));
|