void litiv::IDatasetEvaluator_<litiv::eDatasetEval_None>::writeEvalReport() const { if(getBatches(false).empty()) { std::cout << "No report to write for dataset '" << getName() << "', skipping." << std::endl; return; } for(const auto& pGroupIter : getBatches(true)) pGroupIter->shared_from_this_cast<const IDataReporter_<eDatasetEval_None>>(true)->IDataReporter_<eDatasetEval_None>::writeEvalReport(); std::ofstream oMetricsOutput(getOutputPath()+"/overall.txt"); if(oMetricsOutput.is_open()) { oMetricsOutput << std::fixed; oMetricsOutput << "Default evaluation report for dataset '" << getName() << "' :\n\n"; oMetricsOutput << " | Packets | Seconds | Hz \n"; oMetricsOutput << "------------|------------|------------|------------\n"; size_t nOverallPacketCount = 0; double dOverallTimeElapsed = 0.0; for(const auto& pGroupIter : getBatches(true)) { oMetricsOutput << pGroupIter->shared_from_this_cast<const IDataReporter_<eDatasetEval_None>>(true)->IDataReporter_<eDatasetEval_None>::writeInlineEvalReport(0); nOverallPacketCount += pGroupIter->getTotPackets(); dOverallTimeElapsed += pGroupIter->getProcessTime(); } oMetricsOutput << "------------|------------|------------|------------\n"; oMetricsOutput << " overall|" << std::setw(12) << nOverallPacketCount << "|" << std::setw(12) << dOverallTimeElapsed << "|" << std::setw(12) << nOverallPacketCount/dOverallTimeElapsed << "\n"; oMetricsOutput << CxxUtils::getLogStamp(); } }
litiv::IMetricsAccumulatorConstPtr litiv::IDataReporter_<litiv::eDatasetEval_BinaryClassifier>::getMetricsBase() const { lvAssert(isGroup()); // non-group specialization should override this method BinClassifMetricsAccumulatorPtr pMetricsBase = BinClassifMetricsAccumulator::create(); for(const auto& pBatch : getBatches(true)) pMetricsBase->accumulate(dynamic_cast<const IDataReporter_<eDatasetEval_BinaryClassifier>&>(*pBatch).getMetricsBase()); return pMetricsBase; }
void litiv::IDatasetEvaluator_<litiv::eDatasetEval_BinaryClassifier>::writeEvalReport() const { if(getBatches(false).empty() || !isUsingEvaluator()) { IDatasetEvaluator_<litiv::eDatasetEval_None>::writeEvalReport(); return; } for(const auto& pGroupIter : getBatches(true)) pGroupIter->shared_from_this_cast<const IDataReporter_<eDatasetEval_BinaryClassifier>>(true)->IDataReporter_<eDatasetEval_BinaryClassifier>::writeEvalReport(); IMetricsCalculatorConstPtr pMetrics = getMetrics(true); lvAssert(pMetrics.get()); const BinClassifMetricsCalculator& oMetrics = dynamic_cast<const BinClassifMetricsCalculator&>(*pMetrics.get()); std::cout << CxxUtils::clampString(getName(),12) << " => Rcl=" << std::fixed << std::setprecision(4) << oMetrics.dRecall << " Prc=" << oMetrics.dPrecision << " FM=" << oMetrics.dFMeasure << " MCC=" << oMetrics.dMCC << std::endl; std::ofstream oMetricsOutput(getOutputPath()+"/overall.txt"); if(oMetricsOutput.is_open()) { oMetricsOutput << std::fixed; oMetricsOutput << "Video segmentation evaluation report for dataset '" << getName() << "' :\n\n"; oMetricsOutput << " | Rcl | Spc | FPR | FNR | PBC | Prc | FM | MCC \n"; oMetricsOutput << "------------|------------|------------|------------|------------|------------|------------|------------|------------\n"; size_t nOverallPacketCount = 0; double dOverallTimeElapsed = 0.0; for(const auto& pGroupIter : getBatches(true)) { oMetricsOutput << pGroupIter->shared_from_this_cast<const IDataReporter_<eDatasetEval_BinaryClassifier>>(true)->IDataReporter_<eDatasetEval_BinaryClassifier>::writeInlineEvalReport(0); nOverallPacketCount += pGroupIter->getTotPackets(); dOverallTimeElapsed += pGroupIter->getProcessTime(); } oMetricsOutput << "------------|------------|------------|------------|------------|------------|------------|------------|------------\n"; oMetricsOutput << " overall|" << std::setw(12) << oMetrics.dRecall << "|" << std::setw(12) << oMetrics.dSpecificity << "|" << std::setw(12) << oMetrics.dFPR << "|" << std::setw(12) << oMetrics.dFNR << "|" << std::setw(12) << oMetrics.dPBC << "|" << std::setw(12) << oMetrics.dPrecision << "|" << std::setw(12) << oMetrics.dFMeasure << "|" << std::setw(12) << oMetrics.dMCC << "\n"; oMetricsOutput << "\nHz: " << nOverallPacketCount/dOverallTimeElapsed << "\n"; oMetricsOutput << CxxUtils::getLogStamp(); } }
litiv::IMetricsCalculatorPtr litiv::IDatasetEvaluator_<litiv::eDatasetEval_BinaryClassifier>::getMetrics(bool bAverage) const { if(bAverage) { IDataHandlerPtrArray vpBatches = getBatches(true); auto ppBatchIter = vpBatches.begin(); for(; ppBatchIter!=vpBatches.end() && !(*ppBatchIter)->getTotPackets(); ++ppBatchIter); CV_Assert(ppBatchIter!=vpBatches.end()); IMetricsCalculatorPtr pMetrics = dynamic_cast<const IDataReporter_<eDatasetEval_BinaryClassifier>&>(**ppBatchIter).getMetrics(bAverage); for(; ppBatchIter!=vpBatches.end(); ++ppBatchIter) if((*ppBatchIter)->getTotPackets()) pMetrics->accumulate(dynamic_cast<const IDataReporter_<eDatasetEval_BinaryClassifier>&>(**ppBatchIter).getMetrics(bAverage)); return pMetrics; } return BinClassifMetricsCalculator::create(getMetricsBase()); }
std::string litiv::IDataReporter_<litiv::eDatasetEval_None>::writeInlineEvalReport(size_t nIndentSize) const { if(!getTotPackets()) return std::string(); const size_t nCellSize = 12; std::stringstream ssStr; ssStr << std::fixed; if(isGroup() && !isBare()) for(const auto& pBatch : getBatches(true)) ssStr << pBatch->shared_from_this_cast<const IDataReporter_<litiv::eDatasetEval_None>>(true)->IDataReporter_<eDatasetEval_None>::writeInlineEvalReport(nIndentSize+1); ssStr << CxxUtils::clampString((std::string(nIndentSize,'>')+' '+getName()),nCellSize) << "|" << std::setw(nCellSize) << getTotPackets() << "|" << std::setw(nCellSize) << getProcessTime() << "|" << std::setw(nCellSize) << getTotPackets()/getProcessTime() << "\n"; return ssStr.str(); }
void litiv::IDataReporter_<litiv::eDatasetEval_None>::writeEvalReport() const { if(!getTotPackets()) { std::cout << "No report to write for '" << getName() << "', skipping..." << std::endl; return; } else if(isGroup() && !isBare()) for(const auto& pBatch : getBatches(true)) pBatch->writeEvalReport(); std::ofstream oMetricsOutput(PlatformUtils::AddDirSlashIfMissing(getOutputPath())+"../"+getName()+".txt"); if(oMetricsOutput.is_open()) { oMetricsOutput << std::fixed; oMetricsOutput << "Default evaluation report for '" << getName() << "' :\n\n"; oMetricsOutput << " | Packets | Seconds | Hz \n"; oMetricsOutput << "------------|------------|------------|------------\n"; oMetricsOutput << IDataReporter_<eDatasetEval_None>::writeInlineEvalReport(0); oMetricsOutput << CxxUtils::getLogStamp(); } }
std::string litiv::IDataReporter_<litiv::eDatasetEval_BinaryClassifier>::writeInlineEvalReport(size_t nIndentSize) const { if(!getTotPackets()) return std::string(); const size_t nCellSize = 12; std::stringstream ssStr; ssStr << std::fixed; if(isGroup() && !isBare()) for(const auto& pBatch : getBatches(true)) ssStr << pBatch->shared_from_this_cast<const IDataReporter_<eDatasetEval_BinaryClassifier>>(true)->IDataReporter_<eDatasetEval_BinaryClassifier>::writeInlineEvalReport(nIndentSize+1); IMetricsCalculatorConstPtr pMetrics = getMetrics(true); lvAssert(pMetrics.get()); const BinClassifMetricsCalculator& oMetrics = dynamic_cast<const BinClassifMetricsCalculator&>(*pMetrics.get()); ssStr << CxxUtils::clampString((std::string(nIndentSize,'>')+' '+getName()),nCellSize) << "|" << std::setw(nCellSize) << oMetrics.dRecall << "|" << std::setw(nCellSize) << oMetrics.dSpecificity << "|" << std::setw(nCellSize) << oMetrics.dFPR << "|" << std::setw(nCellSize) << oMetrics.dFNR << "|" << std::setw(nCellSize) << oMetrics.dPBC << "|" << std::setw(nCellSize) << oMetrics.dPrecision << "|" << std::setw(nCellSize) << oMetrics.dFMeasure << "|" << std::setw(nCellSize) << oMetrics.dMCC << "\n"; return ssStr.str(); }
void litiv::IDataReporter_<litiv::eDatasetEval_BinaryClassifier>::writeEvalReport() const { if(!getTotPackets() || !getDatasetInfo()->isUsingEvaluator()) { IDataReporter_<litiv::eDatasetEval_None>::writeEvalReport(); return; } else if(isGroup() && !isBare()) for(const auto& pBatch : getBatches(true)) pBatch->writeEvalReport(); IMetricsCalculatorConstPtr pMetrics = getMetrics(true); lvAssert(pMetrics.get()); const BinClassifMetricsCalculator& oMetrics = dynamic_cast<const BinClassifMetricsCalculator&>(*pMetrics.get());; std::cout << "\t" << CxxUtils::clampString(std::string(size_t(!isGroup()),'>')+getName(),12) << " => Rcl=" << std::fixed << std::setprecision(4) << oMetrics.dRecall << " Prc=" << oMetrics.dPrecision << " FM=" << oMetrics.dFMeasure << " MCC=" << oMetrics.dMCC << std::endl; std::ofstream oMetricsOutput(PlatformUtils::AddDirSlashIfMissing(getOutputPath())+"../"+getName()+".txt"); if(oMetricsOutput.is_open()) { oMetricsOutput << std::fixed; oMetricsOutput << "Video segmentation evaluation report for '" << getName() << "' :\n\n"; oMetricsOutput << " | Rcl | Spc | FPR | FNR | PBC | Prc | FM | MCC \n"; oMetricsOutput << "------------|------------|------------|------------|------------|------------|------------|------------|------------\n"; oMetricsOutput << IDataReporter_<eDatasetEval_BinaryClassifier>::writeInlineEvalReport(0); oMetricsOutput << "\nHz: " << getTotPackets()/getProcessTime() << "\n"; oMetricsOutput << CxxUtils::getLogStamp(); } }
litiv::IMetricsAccumulatorConstPtr litiv::IDatasetEvaluator_<litiv::eDatasetEval_BinaryClassifier>::getMetricsBase() const { BinClassifMetricsAccumulatorPtr pMetricsBase = BinClassifMetricsAccumulator::create(); for(const auto& pBatch : getBatches(true)) pMetricsBase->accumulate(dynamic_cast<const IDataReporter_<eDatasetEval_BinaryClassifier>&>(*pBatch).getMetricsBase()); return pMetricsBase; }
unsigned GfxBody::getBatchesWithChildren (void) const { return getBatches() + GfxFertileNode::getBatchesWithChildren(); }