00001 #ifndef Impala_Core_ApplicationFactory_h
00002 #define Impala_Core_ApplicationFactory_h
00003
00004 #include "Basis/CmdOptions.h"
00005 #include "Util/PropertySet.h"
00006 #include "Core/DataFactory.h"
00007 #include "Core/Training/Factory.h"
00008
00009 namespace Impala
00010 {
00011 namespace Core
00012 {
00013
00026 class ApplicationFactory
00027 {
00028 public:
00029 ApplicationFactory(CmdOptions* options)
00030 {
00031 mOptions = options;
00032 String setName = mOptions->GetArg(0);
00033 Util::Database* db = new Util::Database(setName);
00034 String path = db->GetFilePath("ImageData", setName, false, true);
00035 if (! path.empty())
00036 {
00037 mQuidClass = QUID_CLASS_IMAGE;
00038 ImageSet::ImageSet* is = ImageSet::MakeImageSet(setName);
00039 is->SetImageSrc(true, true, true);
00040 mDataSet = is;
00041 }
00042 else
00043 {
00044 mQuidClass = QUID_CLASS_FRAME;
00045 mDataSet = VideoSet::MakeVideoSet(setName);
00046 }
00047 delete db;
00048 }
00049
00050 DataFactory* MakeDataFactory()
00051 {
00052 String conceptSet = mOptions->GetArg(1);
00053 String modelType = mOptions->GetArg(2);
00054 String src = mOptions->GetArg(3);
00055 Feature::FeatureDefinition featureDef(src);
00056 return new DataFactory(mDataSet, mDataSet->GetDatabase(), mQuidClass,
00057 conceptSet, modelType, featureDef, src,
00058 mOptions->GetInt("start",0),
00059 mOptions->GetInt("number",-1));
00060 }
00061
00062 Training::Factory* MakeTrainFactory(Util::PropertySet* properties)
00063 {
00064 return new Training::Factory(properties);
00065 }
00068 Training::Factory* MakeTrainFactory()
00069 {
00070 return new Training::Factory();
00071 }
00072
00073 Util::PropertySet* MakeClassifierProperties()
00074 {
00075 ILOG_VAR(Samples.mainCrossValidate.GetProperties);
00076 Util::PropertySet* properties = new Util::PropertySet;
00077
00078 properties->Add("w1", mOptions->GetString("w1"));
00079 properties->Add("w2", mOptions->GetString("w2"));
00080 properties->Add("autoweight", mOptions->GetString("autoweight"));
00081 if(properties->GetBool("autoweight"))
00082 {
00083 properties->Add("w1", "1");
00084 properties->Add("w2", "1");
00085 }
00086 properties->Add("C", mOptions->GetString("C"));
00087 properties->Add("gamma", mOptions->GetString("gamma"));
00088 properties->Add("cache", mOptions->GetString("cache"));
00089 properties->Add("probability", mOptions->GetInt("probability"));
00090 properties->Add("kernel", mOptions->GetString("kernel"));
00091 properties->Add("precompute-kernel",
00092 mOptions->GetString("precompute-kernel"));
00093 properties->Add("folds", mOptions->GetInt("folds"));
00094 properties->Add("repetitions", mOptions->GetInt("repetitions"));
00095 properties->Add("episode-constrained",
00096 mOptions->GetInt("episode-constrained"));
00097 properties->Add("evaluator", mOptions->GetString("evaluator"));
00098 properties->Add("maxVideoId", mOptions->GetInt("maxVideoId"));
00099 properties->Add("maxPosPerVideo", mOptions->GetInt("maxPosPerVideo"));
00100 properties->Add("maxNegPerVideo", mOptions->GetInt("maxNegPerVideo"));
00101 if(properties->GetInt("episode-constrained") &&
00102 mQuidClass == QUID_CLASS_IMAGE)
00103 {
00104 ILOG_WARN("ImageSet learning doesn't support episode-constrained!");
00105 properties->Add("episode-constrained", 0);
00106 }
00107 if (Link::Mpi::MyId() == 0)
00108 {
00109 if(!properties->GetBool("episode-constrained"))
00110 ILOG_INFO("not using episode constrained.")
00111 else
00112 ILOG_INFO("using episode constrained.")
00113 ILOG_INFO("using " << properties->GetString("evaluator") <<
00114 " for evaluation.");
00115 }
00116
00117 return properties;
00118 }
00119 private:
00120 int mQuidClass;
00121 Core::Database::RawDataSet* mDataSet;
00122 CmdOptions* mOptions;
00123 };
00124
00125 }
00126 }
00127
00128 #endif