Added statistics for incremental flann index size

This commit is contained in:
matlabbe
2015-09-09 12:08:51 -04:00
parent 3be4b9a3f5
commit beab2271f0
5 changed files with 93 additions and 19 deletions

View File

@@ -230,6 +230,8 @@ void Rtabmap::setupLogFiles(bool overwrite)
fprintf(_foutInt, " 17-Is last location merged through Weight Update?\n");
fprintf(_foutInt, " 18-Local graph size\n");
fprintf(_foutInt, " 19-Sensor data id\n");
fprintf(_foutInt, " 20-Indexed words\n");
fprintf(_foutInt, " 21-Index memory usage (KB)\n");
}
ULOGGER_DEBUG("Log file (int)=%s", (_wDir+"/"+LOG_I).c_str());
@@ -2270,6 +2272,8 @@ bool Rtabmap::process(
// Surf specific parameters
statistics_.addStatistic(Statistics::kKeypointDictionary_size(), dictionarySize);
statistics_.addStatistic(Statistics::kKeypointIndexed_words(), _memory->getVWDictionary()->getIndexedWordsCount());
statistics_.addStatistic(Statistics::kKeypointIndex_memory_usage(), _memory->getVWDictionary()->getIndexMemoryUsed());
//Epipolar geometry constraint
statistics_.addStatistic(Statistics::kLoopRejectedHypothesis(), rejectedHypothesis?1.0f:0);
@@ -2514,7 +2518,7 @@ bool Rtabmap::process(
timeLocalTimeDetection,
timeLocalSpaceDetection,
timeMapOptimization);
std::string logI = uFormat("%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d\n",
std::string logI = uFormat("%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d\n",
_loopClosureHypothesis.first,
_highestHypothesis.first,
(int)signaturesRemoved.size(),
@@ -2533,7 +2537,9 @@ bool Rtabmap::process(
rehearsalMaxId,
rehearsalMaxId>0?1:0,
localGraphSize,
data.id());
data.id(),
_memory->getVWDictionary()->getIndexedWordsCount(),
_memory->getVWDictionary()->getIndexMemoryUsed());
if(_statisticLogsBufferedInRAM)
{
_bufferedLogsF.push_back(logF);

View File

@@ -83,6 +83,41 @@ public:
}
}
unsigned int indexedFeatures() const
{
if(!index_)
{
return 0;
}
if(binaryType_)
{
return ((const flann::Index<flann::Hamming<unsigned char> >*)index_)->size();
}
else
{
return ((const flann::Index<flann::L2<float> >*)index_)->size();
}
}
// return KB
unsigned int memoryUsed() const
{
if(!index_)
{
return 0;
}
if(binaryType_)
{
return ((const flann::Index<flann::Hamming<unsigned char> >*)index_)->usedMemory()/1000;
}
else
{
return ((const flann::Index<flann::L2<float> >*)index_)->usedMemory()/1000;
}
}
void build(
const cv::Mat & features,
const flann::IndexParams& params,
@@ -427,6 +462,16 @@ int VWDictionary::getLastIndexedWordId() const
}
}
unsigned int VWDictionary::getIndexedWordsCount() const
{
return _flannIndex->indexedFeatures();
}
unsigned int VWDictionary::getIndexMemoryUsed() const
{
return _flannIndex->memoryUsed();
}
void VWDictionary::update()
{
ULOGGER_DEBUG("");
@@ -447,21 +492,27 @@ void VWDictionary::update()
(_notIndexedWords.size() || _removedIndexedWords.size()) &&
oldSize)
{
for(std::set<int>::iterator iter=_notIndexedWords.begin(); iter!=_notIndexedWords.end(); ++iter)
if(_notIndexedWords.size())
{
VisualWord* w = uValue(_visualWords, *iter, (VisualWord*)0);
UASSERT(w);
UASSERT(w->getDescriptor().cols == _dataTree.cols);
UASSERT(w->getDescriptor().type() == _dataTree.type());
_dataTree.push_back(w->getDescriptor());
_mapIndexId.insert(_mapIndexId.end(), std::pair<int, int>(_dataTree.rows-1, w->id()));
std::pair<std::map<int, int>::iterator, bool> inserted = _mapIdIndex.insert(std::pair<int, int>(w->id(), _dataTree.rows-1));
if(!inserted.second)
int i = _dataTree.rows;
_dataTree.reserve(_dataTree.rows + _notIndexedWords.size());
for(std::set<int>::iterator iter=_notIndexedWords.begin(); iter!=_notIndexedWords.end(); ++iter)
{
//update to new index
inserted.first->second = _dataTree.rows-1;
VisualWord* w = uValue(_visualWords, *iter, (VisualWord*)0);
UASSERT(w);
UASSERT(w->getDescriptor().cols == _dataTree.cols);
UASSERT(w->getDescriptor().type() == _dataTree.type());
_dataTree.push_back(w->getDescriptor());
_mapIndexId.insert(_mapIndexId.end(), std::pair<int, int>(i, w->id()));
std::pair<std::map<int, int>::iterator, bool> inserted = _mapIdIndex.insert(std::pair<int, int>(w->id(), i));
if(!inserted.second)
{
//update to new index
inserted.first->second = i;
}
_flannIndex->addPoints(w->getDescriptor());
++i;
}
_flannIndex->addPoints(w->getDescriptor());
}
for(std::set<int>::iterator iter=_removedIndexedWords.begin(); iter!=_removedIndexedWords.end(); ++iter)
{
@@ -475,6 +526,8 @@ void VWDictionary::update()
oldSize)
{
//just add not indexed words
int i = _dataTree.rows;
_dataTree.reserve(_dataTree.rows + _notIndexedWords.size());
for(std::set<int>::iterator iter=_notIndexedWords.begin(); iter!=_notIndexedWords.end(); ++iter)
{
VisualWord* w = uValue(_visualWords, *iter, (VisualWord*)0);
@@ -482,9 +535,10 @@ void VWDictionary::update()
UASSERT(w->getDescriptor().cols == _dataTree.cols);
UASSERT(w->getDescriptor().type() == _dataTree.type());
_dataTree.push_back(w->getDescriptor());
_mapIndexId.insert(_mapIndexId.end(), std::pair<int, int>(_dataTree.rows-1, w->id()));
std::pair<std::map<int, int>::iterator, bool> inserted = _mapIdIndex.insert(std::pair<int, int>(w->id(), _dataTree.rows-1));
_mapIndexId.insert(_mapIndexId.end(), std::pair<int, int>(i, w->id()));
std::pair<std::map<int, int>::iterator, bool> inserted = _mapIdIndex.insert(std::pair<int, int>(w->id(), i));
UASSERT(inserted.second);
++i;
}
}
else