|
@@ -8,6 +8,7 @@
|
|
|
#include <iostream>
|
|
|
#include <iomanip>
|
|
|
|
|
|
+#include "core/basics/StringTools.h"
|
|
|
#include "SemSegTools.h"
|
|
|
|
|
|
using namespace OBJREC;
|
|
@@ -235,98 +236,174 @@ void SemSegTools::saveResultsToImageFile(
|
|
|
outStr = out.str();
|
|
|
}
|
|
|
|
|
|
-void SemSegTools::collectTrainingExamples (
|
|
|
+void SemSegTools::getDepthVector (
|
|
|
+ const LabeledSet *Files,
|
|
|
+ std::vector<int> & depthVec,
|
|
|
+ const bool run3Dseg )
|
|
|
+{
|
|
|
+ std::string oldName;
|
|
|
+ int zsize = 0;
|
|
|
+ bool isInit = false;
|
|
|
+
|
|
|
+ for (LabeledSet::const_iterator it = Files->begin(); it != Files->end(); it++)
|
|
|
+ {
|
|
|
+ for (std::vector<ImageInfo *>::const_iterator jt = it->second.begin();
|
|
|
+ jt != it->second.end(); jt++)
|
|
|
+ {
|
|
|
+ ImageInfo & info = *(*jt);
|
|
|
+ std::string file = info.img();
|
|
|
+
|
|
|
+ std::vector< std::string > list;
|
|
|
+ StringTools::split ( file, '/', list );
|
|
|
+ std::string filename = list.back();
|
|
|
+ uint found = filename.find_last_of ( "_" );
|
|
|
+ if (run3Dseg && found < filename.size() && found-3 > 0 )
|
|
|
+ {
|
|
|
+ std::string curName = filename.substr ( found-3,3 );
|
|
|
+ if ( !isInit )
|
|
|
+ {
|
|
|
+ oldName = curName;
|
|
|
+ isInit = true;
|
|
|
+ }
|
|
|
+ if ( curName.compare ( oldName ) == 0 ) // if strings match up
|
|
|
+ {
|
|
|
+ zsize++;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ depthVec.push_back ( zsize );
|
|
|
+ zsize = 1;
|
|
|
+ oldName = curName;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ zsize = 1;
|
|
|
+ depthVec.push_back ( zsize );
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ depthVec.push_back ( zsize );
|
|
|
+}
|
|
|
+
|
|
|
+void SemSegTools::collectTrainingExamples (
|
|
|
const Config * conf,
|
|
|
const std::string & section,
|
|
|
const LabeledSet & train,
|
|
|
const ClassNames & cn,
|
|
|
Examples & examples,
|
|
|
- vector<CachedExample *> & imgexamples )
|
|
|
+ vector<CachedExample *> & imgexamples,
|
|
|
+ const bool run3Dseg )
|
|
|
{
|
|
|
assert ( train.count() > 0 );
|
|
|
examples.clear();
|
|
|
imgexamples.clear();
|
|
|
|
|
|
+ vector<int> zsizeVec;
|
|
|
+ SemSegTools::getDepthVector ( &train, zsizeVec, true );
|
|
|
+
|
|
|
int grid_size_x = conf->gI(section, "grid_size_x", 5 );
|
|
|
int grid_size_y = conf->gI(section, "grid_size_y", 5 );
|
|
|
+ int grid_size_z = conf->gI(section, "grid_size_z", 5 );
|
|
|
int grid_border_x = conf->gI(section, "grid_border_x", 20 );
|
|
|
int grid_border_y = conf->gI(section, "grid_border_y", 20 );
|
|
|
+ int grid_border_z = conf->gI(section, "grid_border_z", 20 );
|
|
|
|
|
|
std::string selection = conf->gS(section, "train_selection" );
|
|
|
|
|
|
set<int> classnoSelection;
|
|
|
cn.getSelection ( selection, classnoSelection );
|
|
|
-
|
|
|
+
|
|
|
bool useExcludedAsBG = conf->gB(section, "use_excluded_as_background", false );
|
|
|
|
|
|
int backgroundClassNo = 0;
|
|
|
-
|
|
|
+
|
|
|
if ( useExcludedAsBG )
|
|
|
{
|
|
|
backgroundClassNo = cn.classno("various");
|
|
|
assert ( backgroundClassNo >= 0 );
|
|
|
}
|
|
|
|
|
|
- LOOP_ALL_S (train)
|
|
|
- {
|
|
|
- EACH_INFO(image_classno,imgInfo);
|
|
|
- std::string imgfn = imgInfo.img();
|
|
|
-
|
|
|
- if ( ! imgInfo.hasLocalizationInfo() ) {
|
|
|
- std::cerr << "WARNING: NO localization info found for "
|
|
|
- << imgfn << " !" << std::endl;
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- int xsize, ysize;
|
|
|
- CachedExample *ce = new CachedExample ( imgfn );
|
|
|
- ce->getImageSize ( xsize, ysize );
|
|
|
- imgexamples.push_back ( ce );
|
|
|
-
|
|
|
- const LocalizationResult *locResult = imgInfo.localization();
|
|
|
- if ( locResult->size() <= 0 ) {
|
|
|
- std::cerr << "WARNING: NO ground truth polygons found for "
|
|
|
- << imgfn << " !" << std::endl;
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- std::cerr << "SemSegTools: Collecting pixel examples from localization info: "
|
|
|
- << imgfn << std::endl;
|
|
|
+ int depthCount = 0;
|
|
|
+ int imgCounter = 0;
|
|
|
+ vector<std::string> filelist;
|
|
|
+ NICE::MultiChannelImageT<int> pixelLabels;
|
|
|
|
|
|
- NICE::ImageT<int> pixelLabels (xsize, ysize);
|
|
|
- pixelLabels.set(0);
|
|
|
- locResult->calcLabeledImage ( pixelLabels, cn.getBackgroundClass() );
|
|
|
+ for (LabeledSet::const_iterator it = train.begin(); it != train.end(); it++)
|
|
|
+ {
|
|
|
+ for (std::vector<ImageInfo *>::const_iterator jt = it->second.begin();
|
|
|
+ jt != it->second.end(); jt++)
|
|
|
+ {
|
|
|
+ int classno = it->first;
|
|
|
+ ImageInfo & info = *(*jt);
|
|
|
+ std::string file = info.img();
|
|
|
+ filelist.push_back ( file );
|
|
|
+ depthCount++;
|
|
|
+
|
|
|
+ const LocalizationResult *locResult = info.localization();
|
|
|
+
|
|
|
+ // getting groundtruth
|
|
|
+ NICE::ImageT<int> pL;
|
|
|
+ pL.resize ( locResult->xsize, locResult->ysize );
|
|
|
+ pL.set ( 0 );
|
|
|
+ locResult->calcLabeledImage ( pL, cn.getBackgroundClass() );
|
|
|
+ pixelLabels.addChannel ( pL );
|
|
|
+
|
|
|
+ if ( locResult->size() <= 0 ) {
|
|
|
+ std::cerr << "WARNING: NO ground truth polygons found for "
|
|
|
+ << file << " !" << std::endl;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
|
|
|
-#ifdef DEBUG_LOCALIZATION
|
|
|
- NICE::Image img (imgfn);
|
|
|
- showImage(img);
|
|
|
- showImage(pixelLabels);
|
|
|
-#endif
|
|
|
+ std::cerr << "SemSegTools: Collecting pixel examples from localization info: "
|
|
|
+ << file << std::endl;
|
|
|
|
|
|
- Example pce ( ce, 0, 0 );
|
|
|
- for ( int x = 0 ; x < xsize ; x += grid_size_x )
|
|
|
- for ( int y = 0 ; y < ysize ; y += grid_size_y )
|
|
|
+ int depthBoundary = 0;
|
|
|
+ if ( run3Dseg )
|
|
|
{
|
|
|
- if ( (x >= grid_border_x) &&
|
|
|
- ( y >= grid_border_y ) && ( x < xsize - grid_border_x ) &&
|
|
|
- ( y < ysize - grid_border_x ) )
|
|
|
- {
|
|
|
- pce.x = x; pce.y = y;
|
|
|
- int classno = pixelLabels.getPixel(x,y);
|
|
|
-
|
|
|
- if ( classnoSelection.find(classno) != classnoSelection.end() ) {
|
|
|
- examples.push_back ( pair<int, Example> (
|
|
|
- classno,
|
|
|
- pce // FIXME: offset handling
|
|
|
- ) );
|
|
|
- } else if ( useExcludedAsBG ) {
|
|
|
- examples.push_back ( pair<int, Example> (
|
|
|
- backgroundClassNo,
|
|
|
- pce // FIXME: offset handling
|
|
|
- ) );
|
|
|
- }
|
|
|
- }
|
|
|
+ depthBoundary = zsizeVec[imgCounter];
|
|
|
}
|
|
|
+
|
|
|
+ if ( depthCount < depthBoundary ) continue;
|
|
|
+
|
|
|
+ int xsize, ysize, zsize;
|
|
|
+ CachedExample *ce = new CachedExample ( filelist );
|
|
|
+ ce->getImageSize3 ( xsize, ysize, zsize );
|
|
|
+ imgexamples.push_back ( ce );
|
|
|
+
|
|
|
+ // drawing actual examples
|
|
|
+ Example pce ( ce, 0, 0, 0 );
|
|
|
+ for ( int z = 0; z < zsize; z += grid_size_z )
|
|
|
+ for ( int x = 0 ; x < xsize ; x += grid_size_x )
|
|
|
+ for ( int y = 0 ; y < ysize ; y += grid_size_y )
|
|
|
+ if ( ( x >= grid_border_x ) &&
|
|
|
+ ( y >= grid_border_y ) &&
|
|
|
+ ( z >= grid_border_z ) &&
|
|
|
+ ( x < xsize - grid_border_x ) &&
|
|
|
+ ( y < ysize - grid_border_y ) &&
|
|
|
+ ( z < zsize - grid_border_z ) )
|
|
|
+ {
|
|
|
+ pce.x = x; pce.y = y; pce.z = z;
|
|
|
+ int classno = pixelLabels.get(x,y,(unsigned int)z);
|
|
|
+
|
|
|
+ if ( classnoSelection.find(classno) != classnoSelection.end() )
|
|
|
+ {
|
|
|
+ examples.push_back (
|
|
|
+ pair<int, Example> ( classno, pce ) );
|
|
|
+ } else if ( useExcludedAsBG )
|
|
|
+ {
|
|
|
+ examples.push_back (
|
|
|
+ pair<int, Example> ( backgroundClassNo, pce ) );
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // prepare for new 3D image
|
|
|
+ filelist.clear();
|
|
|
+ pixelLabels.reInit ( 0,0,0 );
|
|
|
+ depthCount = 0;
|
|
|
+ imgCounter++;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
std::cerr << "total number of examples: " << (int)examples.size() << std::endl;
|