Exemplo n.º 1
0
void CameraTab::updateImageInfo()
{
	CleanupSettingsModel *model = CleanupSettingsModel::instance();
	CleanupParameters *params = model->getCurrentParameters();

	TDimension outRes(0, 0);
	TPointD outDpi;

	params->getOutputImageInfo(outRes, outDpi.x, outDpi.y);
	setImageInfo(outRes.lx, outRes.ly, outDpi.x, outDpi.y);

	TXshSimpleLevel *sl;
	TFrameId fid;
	model->getCleanupFrame(sl, fid);

	ToonzScene *scene = TApp::instance()->getCurrentScene()->getScene();
	TFilePath outputPath(sl ? scene->decodeFilePath(model->getOutputPath(sl, params)) : TFilePath());

	setImageInfo(outputPath);
}
Exemplo n.º 2
0
void MDDAGClassifier::run(const string& dataFileName, const string& shypFileName,
                          int numIterations, const string& outResFileName, int numRanksEnclosed)
{
    InputData* pData = loadInputData(dataFileName, shypFileName);

    if (_verbose > 0)
        cout << "Loading strong hypothesis..." << flush;

    // The class that loads the weak hypotheses
    UnSerialization us;

    // Where to put the weak hypotheses
    vector<BaseLearner*> weakHypotheses;

    // loads them
    us.loadHypotheses(shypFileName, weakHypotheses, pData);

    // where the results go
    vector< ExampleResults* > results;

    if (_verbose > 0)
        cout << "Classifying..." << flush;

    // get the results
    computeResults( pData, weakHypotheses, results, numIterations );

    const int numClasses = pData->getNumClasses();

    if (_verbose > 0)
    {
        // well.. if verbose = 0 no results are displayed! :)
        cout << "Done!" << endl;

        vector< vector<float> > rankedError(numRanksEnclosed);

        // Get the per-class error for the numRanksEnclosed-th ranks
        for (int i = 0; i < numRanksEnclosed; ++i)
            getClassError( pData, results, rankedError[i], i );

        // output it
        cout << endl;
        cout << "Error Summary" << endl;
        cout << "=============" << endl;

        for ( int l = 0; l < numClasses; ++l )
        {
            // first rank (winner): rankedError[0]
            cout << "Class '" << pData->getClassMap().getNameFromIdx(l) << "': "
                 << setprecision(4) << rankedError[0][l] * 100 << "%";

            // output the others on its side
            if (numRanksEnclosed > 1 && _verbose > 1)
            {
                cout << " (";
                for (int i = 1; i < numRanksEnclosed; ++i)
                    cout << " " << i+1 << ":[" << setprecision(4) << rankedError[i][l] * 100 << "%]";
                cout << " )";
            }

            cout << endl;
        }

        // the overall error
        cout << "\n--> Overall Error: "
             << setprecision(4) << getOverallError(pData, results, 0) * 100 << "%";

        // output the others on its side
        if (numRanksEnclosed > 1 && _verbose > 1)
        {
            cout << " (";
            for (int i = 1; i < numRanksEnclosed; ++i)
                cout << " " << i+1 << ":[" << setprecision(4) << getOverallError(pData, results, i) * 100 << "%]";
            cout << " )";
        }

        cout << endl;

    } // verbose


    // If asked output the results
    if ( !outResFileName.empty() )
    {
        const int numExamples = pData->getNumExamples();
        ofstream outRes(outResFileName.c_str());

        outRes << "Instance" << '\t' << "Forecast" << '\t' << "Labels" << '\n';

        string exampleName;

        for (int i = 0; i < numExamples; ++i)
        {
            // output the name if it exists, otherwise the number
            // of the example
            exampleName = pData->getExampleName(i);
            if ( exampleName.empty() )
                outRes << i << '\t';
            else
                outRes << exampleName << '\t';

            // output the predicted class
            outRes << pData->getClassMap().getNameFromIdx( results[i]->getWinner().first ) << '\t';

            outRes << '|';

            vector<Label>& labels = pData->getLabels(i);
            for (vector<Label>::iterator lIt=labels.begin(); lIt != labels.end(); ++lIt) {
                if (lIt->y>0)
                {
                    outRes << ' ' << pData->getClassMap().getNameFromIdx(lIt->idx);
                }
            }

            outRes << endl;
        }

        if (_verbose > 0)
            cout << "\nPredictions written on file <" << outResFileName << ">!" << endl;

    }


    // delete the input data file
    if (pData)
        delete pData;

    vector<ExampleResults*>::iterator it;
    for (it = results.begin(); it != results.end(); ++it)
        delete (*it);
}
Exemplo n.º 3
0
	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;

			outRes << "Posteriors";
			for(int i=0; i<numOfExamples; ++i )
			{	
				outRes << " " << cascadeData[i].score;
			}				
			outRes << endl;
			
		}						
		
		outRes.close();
		
		// free memory allocation
		vector<vector<BaseLearner*> >::iterator bvIt;
		for( bvIt = weakHypotheses.begin(); bvIt != weakHypotheses.end(); ++bvIt )
		{
			vector<BaseLearner* >::iterator bIt;
			for( bIt = (*bvIt).begin(); bIt != (*bvIt).end(); ++bIt )
				delete *bIt;
		}
	}