本文整理汇总了C++中UnSerialization::loadCascadeHypotheses方法的典型用法代码示例。如果您正苦于以下问题:C++ UnSerialization::loadCascadeHypotheses方法的具体用法?C++ UnSerialization::loadCascadeHypotheses怎么用?C++ UnSerialization::loadCascadeHypotheses使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnSerialization
的用法示例。
在下文中一共展示了UnSerialization::loadCascadeHypotheses方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: run
void VJCascadeClassifier::run(const string& dataFileName, const string& shypFileName,
int numIterations, const string& outResFileName )
{
// loading data
InputData* pData = loadInputData(dataFileName, shypFileName);
const int numOfExamples = pData->getNumExamples();
//get the index of positive label
const NameMap& namemap = pData->getClassMap();
_positiveLabelIndex = namemap.getIdxFromName( _positiveLabelName );
if (_verbose > 0)
cout << "Loading strong hypothesis..." << flush;
// The class that loads the weak hypotheses
UnSerialization us;
// Where to put the weak hypotheses
vector<vector<BaseLearner*> > weakHypotheses;
// For stagewise thresholds
vector<AlphaReal> thresholds(0);
// loads them
//us.loadHypotheses(shypFileName, weakHypotheses, pData);
us.loadCascadeHypotheses(shypFileName, weakHypotheses, thresholds, pData);
// store result
vector<CascadeOutputInformation> cascadeData(0);
vector<CascadeOutputInformation>::iterator it;
cascadeData.resize(numOfExamples);
for( it=cascadeData.begin(); it != cascadeData.end(); ++it )
{
it->active=true;
}
if (!_outputInfoFile.empty())
{
outputHeader();
}
for(int stagei=0; stagei < weakHypotheses.size(); ++stagei )
{
// for posteriors
vector<AlphaReal> posteriors(0);
// calculate the posteriors after stage
VJCascadeLearner::calculatePosteriors( pData, weakHypotheses[stagei], posteriors, _positiveLabelIndex );
// update the data (posteriors, active element index etc.)
updateCascadeData(pData, weakHypotheses, stagei, posteriors, thresholds, _positiveLabelIndex, cascadeData);
if (!_outputInfoFile.empty())
{
_output << stagei + 1 << "\t";
_output << weakHypotheses[stagei].size() << "\t";
outputCascadeResult( pData, cascadeData );
}
int numberOfActiveInstance = 0;
for( int i = 0; i < numOfExamples; ++i )
if (cascadeData[i].active) numberOfActiveInstance++;
if (_verbose > 0 )
cout << "Number of active instances: " << numberOfActiveInstance << "(" << numOfExamples << ")" << endl;
}
vector<vector<int> > confMatrix(2);
confMatrix[0].resize(2);
fill( confMatrix[0].begin(), confMatrix[0].end(), 0 );
confMatrix[1].resize(2);
fill( confMatrix[1].begin(), confMatrix[1].end(), 0 );
// print accuracy
for(int i=0; i<numOfExamples; ++i )
{
vector<Label>& labels = pData->getLabels(i);
if (labels[_positiveLabelIndex].y>0) // pos label
if (cascadeData[i].forecast==1)
confMatrix[1][1]++;
else
confMatrix[1][0]++;
else // negative label
if (cascadeData[i].forecast==0)
confMatrix[0][0]++;
else
confMatrix[0][1]++;
}
double acc = 100.0 * (confMatrix[0][0] + confMatrix[1][1]) / ((double) numOfExamples);
// output it
cout << endl;
cout << "Error Summary" << endl;
cout << "=============" << endl;
cout << "Accuracy: " << setprecision(4) << acc << endl;
//.........这里部分代码省略.........
示例2: savePosteriors
void VJCascadeClassifier::savePosteriors(const string& dataFileName, const string& shypFileName,
const string& outFileName, int numIterations)
{
// loading data
InputData* pData = loadInputData(dataFileName, shypFileName);
const int numOfExamples = pData->getNumExamples();
//get the index of positive label
const NameMap& namemap = pData->getClassMap();
_positiveLabelIndex = namemap.getIdxFromName( _positiveLabelName );
if (_verbose > 0)
cout << "Loading strong hypothesis..." << flush;
// open outfile
ofstream outRes(outFileName.c_str());
if (!outRes.is_open())
{
cout << "Cannot open outfile!!! " << outFileName << endl;
}
// The class that loads the weak hypotheses
UnSerialization us;
// Where to put the weak hypotheses
vector<vector<BaseLearner*> > weakHypotheses;
// For stagewise thresholds
vector<AlphaReal> thresholds(0);
// loads them
//us.loadHypotheses(shypFileName, weakHypotheses, pData);
us.loadCascadeHypotheses(shypFileName, weakHypotheses, thresholds, pData);
// output the number of stages
outRes << "StageNum " << weakHypotheses.size() << endl;
// output original labels
outRes << "Labels";
for(int i=0; i<numOfExamples; ++i )
{
vector<Label>& labels = pData->getLabels(i);
if (labels[_positiveLabelIndex].y>0) // pos label
outRes << " 1";
else
outRes << " 0";
}
outRes << endl;
// store result
vector<CascadeOutputInformation> cascadeData(0);
vector<CascadeOutputInformation>::iterator it;
cascadeData.resize(numOfExamples);
for( it=cascadeData.begin(); it != cascadeData.end(); ++it )
{
it->active=true;
}
for(int stagei=0; stagei < weakHypotheses.size(); ++stagei )
{
// for posteriors
vector<AlphaReal> posteriors(0);
// calculate the posteriors after stage
VJCascadeLearner::calculatePosteriors( pData, weakHypotheses[stagei], posteriors, _positiveLabelIndex );
// update the data (posteriors, active element index etc.)
//VJCascadeLearner::forecastOverAllCascade( pData, posteriors, activeInstances, thresholds[stagei] );
updateCascadeData(pData, weakHypotheses, stagei, posteriors, thresholds, _positiveLabelIndex, cascadeData);
int numberOfActiveInstance = 0;
for( int i = 0; i < numOfExamples; ++i )
if (cascadeData[i].active) numberOfActiveInstance++;
if (_verbose > 0 )
cout << "Number of active instances: " << numberOfActiveInstance << "(" << numOfExamples << ")" << endl;
// output stats
outRes << "Stage " << stagei << " " << weakHypotheses[stagei].size() << endl;
outRes << "Forecast";
for(int i=0; i<numOfExamples; ++i )
{
outRes << " " << cascadeData[i].forecast;
}
outRes << endl;
outRes << "Active";
for(int i=0; i<numOfExamples; ++i )
{
if( cascadeData[i].active)
outRes << " 1";
else
outRes << " 0";
}
outRes << endl;
//.........这里部分代码省略.........