#ifndef DATATOOLSINCLUDE #define DATATOOLSINCLUDE #include #include #include #include #include using namespace std; using namespace NICE; using namespace OBJREC; template void readData ( const NICE::Config & conf, const OBJREC::LabeledSet & ls, MatrixType & X, Vector & y, std::string extension = ".txt" ) { std::string cacheroot = conf.gS("cache", "root"); y.resize ( ls.count() ); X.clear(); LOOP_ALL_S ( ls ) { EACH_S(classno, imgfn); Globals::setCurrentImgFN ( imgfn ); std::string cachefn = Globals::getCacheFilename ( cacheroot, Globals::SORT_CATEGORIES ) + extension; std::cerr << "fn: " << imgfn << " cachefn: " << cachefn << std::endl; y[ X.size() ] = classno; VectorType x; std::ifstream ifs ( cachefn.c_str(), std::ios::in ); if ( ! ifs.good() ) fthrow(Exception, "File not found: " << cachefn ); ifs >> x; X.push_back ( x ); ifs.close(); } } template void readData ( const NICE::Config & conf, const OBJREC::LabeledSet & ls, MatrixType & X, Vector & y, std::vector & filenames, std::string extension = ".txt" ) { std::string cacheroot = conf.gS("cache", "root"); y.resize ( ls.count() ); X.clear(); filenames.clear(); LOOP_ALL_S ( ls ) { EACH_S(classno, imgfn); Globals::setCurrentImgFN ( imgfn ); std::string cachefn = Globals::getCacheFilename ( cacheroot, Globals::SORT_CATEGORIES ) + extension; std::cerr << "fn: " << imgfn << " cachefn: " << cachefn << std::endl; filenames.push_back( imgfn ); y[ X.size() ] = classno; VectorType x; std::ifstream ifs ( cachefn.c_str(), std::ios::in ); if ( ! ifs.good() ) fthrow(Exception, "File not found: " << cachefn ); ifs >> x; X.push_back ( x ); ifs.close(); } } void readDataAwA ( const NICE::Config & conf, const OBJREC::LabeledSet & ls, std::vector & X, NICE::Vector & y, std::string extension = ".txt" ) { std::string cacheroot = conf.gS("cache", "root"); y.resize ( ls.count() ); X.clear(); LOOP_ALL_S ( ls ) { EACH_S(classno, imgfn); Globals::setCurrentImgFN ( imgfn ); std::string cachefn = Globals::getCacheFilename ( cacheroot, Globals::SORT_CATEGORIES ) + extension; std::cerr << "fn: " << imgfn << " cachefn: " << cachefn << std::endl; y[ X.size() ] = classno; std::ifstream ifs ( cachefn.c_str(), std::ios::in ); if ( ! ifs.good() ) fthrow(Exception, "File not found: " << cachefn ); NICE::Vector x (ifs,true); // ifs >> x; X.push_back ( x ); ifs.close(); } } #endif