123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- #ifndef DATATOOLSINCLUDE
- #define DATATOOLSINCLUDE
- #include <iostream>
- #include <core/basics/Config.h>
- #include <vislearning/baselib/Globals.h>
- #include <vislearning/cbaselib/MultiDataset.h>
- #include <vislearning/cbaselib/LabeledSet.h>
- using namespace std;
- using namespace NICE;
- using namespace OBJREC;
- template <typename MatrixType, typename VectorType>
- 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 <typename MatrixType, typename VectorType>
- void readData ( const NICE::Config & conf, const OBJREC::LabeledSet & ls, MatrixType & X, Vector & y, std::vector<std::string> & 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<NICE::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
|