/** Save result of prediction to file
*/
void SavePredictions(const TFileList& file_list,
                     const TLabels& labels,
                     const string& prediction_file) {
        // Check that list of files and list of labels has equal size
    assert(file_list.size() == labels.size());
        // Open 'prediction_file' for writing
    ofstream stream(prediction_file.c_str());

        // Write file names and labels to stream
    for (size_t image_idx = 0; image_idx < file_list.size(); ++image_idx)
        stream << file_list[image_idx].first << " " << labels[image_idx] << endl;
    stream.close();
}
//*************************************************************************
void BeatDetectorApp::NextFile()
{
	roto = 0;
	if(mTrack && mTrack->isPlaying())
	{
		mTrack->enablePcmBuffering(false);
		mTrack->stop();
	}

#ifdef WIN32
	time_t now;
	time(&now);
	int time_int = (int)now;
#else
	timeval now;
	gettimeofday(&now, NULL);
	int time_int = now.tv_sec;
#endif

	Rand r;
	r.seed(time_int);
	int rand_file = r.nextInt(m_FileList.size());
	path my_path = m_FileList[rand_file].path();
	m_CurrentFile = my_path.string();
	
	if(!write_frames)
	{
		mAudioSource = audio::load(m_CurrentFile);
		mTrack = audio::Output::addTrack(mAudioSource, false);
		mTrack->enablePcmBuffering(true);
		mTrack->play();		
	}
	//rot_inc = r.nextFloat(1.5f, 30.0f);
}
/**Load images by list of files 'file_list' and store them in 'data_set'

*/
void LoadImages(const TFileList& file_list, TDataSet* data_set) {
    for (size_t img_idx = 0; img_idx < file_list.size(); ++img_idx) {
            // Create image
        BMP* image = new BMP();
            // Read image from file
        image->ReadFromFile(file_list[img_idx].first.c_str());
            // Add image and it's label to dataset
        data_set->push_back(make_pair(image, file_list[img_idx].second));
    }
}
示例#4
0
void CCRUDProcessor::ProcessFiles(TFileList &fileList, const char *pSourceDir, const char *pDestDir, bool bRecursive, CCRUDResults &results)
{
	OutputResult("Processing File List..");

	TFileList::iterator curFile = fileList.begin();

	TDateTime timeBegin;
	timeBegin = timeBegin.CurrentDateTime();

	results.m_iFilesFound = 0;
	results.m_iFilesCopied = 0;

    int nTopLevel = fileList.size();

	ResetEvent(m_hStopEvent);
	while ((WaitForSingleObject(m_hStopEvent, 0) == WAIT_TIMEOUT) &&
			(curFile != fileList.end()))
	{
		// Count this file
		++results.m_iFilesFound;

		// Get the source file name
		string curFileName(pSourceDir);
		curFileName += '\\';
		curFileName += *curFile;
		CleanPath(curFileName.begin());

		// Look for new files in this file
        bool bSearchInFile = bRecursive || nTopLevel;
		if (!bSearchInFile || SearchForNewFiles(fileList, curFileName.begin()))
		{
			// Get the destination file name
			string destFileName(pDestDir);
			destFileName += '\\';
			destFileName += *curFile;
			CleanPath(destFileName.begin());

			// Copy it if it needs to be updated
			if (MaybeCopyFile(curFileName.begin(), destFileName.begin()))
				++results.m_iFilesCopied;
		}

        if (nTopLevel)
            --nTopLevel;

		// Go to the next file in the list
		++curFile;

		// Breathe
		Application->ProcessMessages();
	}

	results.m_ProcessingTime = timeBegin.CurrentDateTime() - timeBegin;
}
FileSystemUtils::Path RuntimeObjectSystem::FindFile( const FileSystemUtils::Path& input )
{
    FileSystemUtils::Path requestedDirectory = input;
    FileSystemUtils::Path filename;
    FileSystemUtils::Path foundFile = input;
    bool bIsFile = input.HasExtension();
    if( bIsFile )
    {
        requestedDirectory = requestedDirectory.ParentPath();
        filename = input.Filename();
    }
    requestedDirectory.ToOSCanonicalCase();
    filename.ToOSCanonicalCase();
    foundFile.ToOSCanonicalCase();

    // Step 1: Try input directory
    if( requestedDirectory.Exists() )
    {
        m_FoundSourceDirectoryMappings[ requestedDirectory ] = requestedDirectory;
    }
    else
    {
        // Step 2: Attempt to find a pre-existing mapping
        bool bFoundMapping = false;
        if( m_FoundSourceDirectoryMappings.size() )
        {
            FileSystemUtils::Path testDir = requestedDirectory;
            FileSystemUtils::Path foundDir;
            unsigned int depth = 0;
            bool bFound = false;
            while( testDir.HasParentPath() )
            {
                TFileMapIterator itrFind = m_FoundSourceDirectoryMappings.find( testDir );
                if( itrFind != m_FoundSourceDirectoryMappings.end() )
                {
                    foundDir = itrFind->second;
                    bFound = true;
                    break;
                }

                testDir = testDir.ParentPath();
                ++depth;
            }

            if( bFound )
            {
                if( depth )
                {
                    // not an exact match
                    FileSystemUtils::Path directory = requestedDirectory;
                    directory.m_string.replace( 0, testDir.m_string.length(), foundDir.m_string );
                    if( directory.Exists() )
                    {
                        foundFile = directory / filename;
                        if( foundFile.Exists() )
                        {
                            m_FoundSourceDirectoryMappings[ requestedDirectory ] = directory;
                            if( m_pCompilerLogger ) {  m_pCompilerLogger->LogInfo( "Found Directory Mapping: %s to %s\n", requestedDirectory.c_str(), directory.c_str() ); }
                            bFoundMapping = true;
                        }
                    }

                }
                else
                {
                    // exact match
                    foundFile = foundDir / filename;
                    bFoundMapping = true;
                }
            }
            
            if( !bFoundMapping )
            {
                // Step 3: Attempt to find a mapping from a known path
                TFileList requestedSubPaths;
                FileSystemUtils::Path requestedSubPath = requestedDirectory;
                while( requestedSubPath.HasParentPath() )
                {
                    requestedSubPaths.push_back( requestedSubPath );
                    requestedSubPath = requestedSubPath.ParentPath();
                }

                TFileMapIterator itr = m_FoundSourceDirectoryMappings.begin();
                while( ( itr != m_FoundSourceDirectoryMappings.end() ) && !bFoundMapping )
                {
                    FileSystemUtils::Path existingPath = itr->second;
                    while( ( existingPath.HasParentPath() ) && !bFoundMapping )
                    {
                        // check all potentials
                        for( size_t i=0; i<requestedSubPaths.size(); ++i )
                        {
                            FileSystemUtils::Path toCheck = existingPath / requestedSubPaths[i].Filename();
                            if( toCheck.Exists() )
                            {
                                // potential mapping
                                FileSystemUtils::Path directory = requestedDirectory;
                                directory.m_string.replace( 0, requestedSubPaths[i].m_string.length(), toCheck.m_string );
                                if( directory.Exists() )
                                {
                                    foundFile = directory / filename;
                                    if( foundFile.Exists() )
                                    {
                                        m_FoundSourceDirectoryMappings[ requestedDirectory ] = directory;
                                        if( m_pCompilerLogger ) {  m_pCompilerLogger->LogInfo( "Found Directory Mapping: %s to %s\n", requestedDirectory.c_str(), directory.c_str() ); }
                                        bFoundMapping = true;
                                        break;
                                    }
                                }
                            }
                        }
                        existingPath = existingPath.ParentPath();
                    }
                    ++itr;
                }
            }
        }
    }

    if( !foundFile.Exists() )
    {
        if( m_pCompilerLogger ) {  m_pCompilerLogger->LogWarning( "Could not find Directory Mapping for: %s\n", input.c_str() ); }
        ++m_NumNotFoundSourceFiles;
    }
    return foundFile;
}