Home || Visual Search || Applications || Architecture || Important Messages || OGL || Src

mainIDo.cpp

Go to the documentation of this file.
00001 #include "Persistency/ImageSetRepository.h"
00002 #include "Persistency/VideoSetRepository.h"
00003 #include "Core/Feature/WeightedFeatureList.h"
00004 #include "Persistency/FeatureTableRepository.h"
00005 
00006 namespace Impala
00007 {
00008 namespace Application
00009 {
00010 
00011 
00012 using namespace Persistency;
00013 
00014 using Core::Database::RawDataSet;
00015 using Core::ImageSet::ImageSet;
00016 using Core::VideoSet::VideoSet;
00017 
00018 class IDo
00019 {
00020 public:
00021 
00022     IDo(CString cmd, bool useMpi, CString server) 
00023     {
00024         CmdOptions& options = CmdOptions::GetInstance();
00025 
00026         mTopCmd = cmd;
00027         mUseMpi = useMpi;
00028         mDataServer = (server == "noserver") ? "" : server;
00029         mLocation = (server == "noserver") ? "file:" : "dataServer:" + server;
00030         mVideoSet = 0;
00031         mImageSet = 0;
00032         String extraArgs("");
00033         for (int a=3 ; a<options.GetNrArg() ; a++)
00034             extraArgs += options.GetArg(a) + " ";
00035         mExports.Add("*", extraArgs);
00036         mExports.Add("LOCATION", mLocation);
00037 
00038         InitSet(options.GetString("set"));
00039 
00040         mNCPU = options.GetInt("ncpu");
00041         mNodes = options.GetInt("nodes");
00042         mPPN = options.GetInt("ppn");
00043         mSrcOpt = options.GetString("srcopt");
00044         mSrcOpt1 = options.GetString("srcopt1");
00045         mSrcOpt2 = options.GetString("srcopt2");
00046         mShotOpt = options.GetString("shotopt");
00047         mDoShotIndex = true;
00048         mExtra2 = options.GetString("extra2");
00049         mFramesJpg = options.GetString("frames_jpg");
00050         mSkipStills = options.GetString("skip_stills");
00051         mFrames = options.GetBool("frames");
00052         mRkf = options.GetBool("rkf");
00053         mQuidFile = options.GetString("quidfile");
00054         mTaskNrFrames = options.GetInt("tasknrframes");
00055         mTaskBlockSize = options.GetInt("taskblocksize");
00056         mTaskNrBlocks = options.GetInt("tasknrblocks");
00057         mNoImArchive = options.GetBool("noimarchive");
00058         mLimit = options.GetString("limit");
00059         mClusters = options.GetString("clusters");
00060         mRandomize = options.GetString("randomize");
00061         mProtoSet = options.GetString("protoset");
00062         mCodebook = options.GetString("codebook");
00063         mDoFeature = options.GetBool("dofeature");
00064         mDoFeatureIndex = options.GetBool("dofeatureindex");
00065         mPrecomputeIncrement = options.GetInt("precomputeincrement");
00066         mPrecomputeRuns = options.GetInt("precomputeruns");
00067         mFeatureIndexCat = options.GetString("featureindexcat");
00068         mClassifyIndexCat = options.GetString("classifyindexcat");
00069         mEpisodeConstrained = options.GetString("episode_constrained");
00070         mSkipFusion = options.GetString("skip_fusion");
00071         mAnnoSet = options.GetString("annoset");
00072         mAnnoSetTest = options.GetString("annosettest");
00073         mConcepts = options.GetString("concepts");
00074         mModel = options.GetString("model");
00075         mFik = options.GetBool("fik");
00076         mModelBins = options.GetInt("modelbins");
00077         mComputeKernelData = options.GetBool("computekerneldata");
00078         mStoreKernelData = options.GetString("storekerneldata");
00079         mKernelDataOnly = options.GetString("kerneldataonly");
00080         mDoClassifyIndex = options.GetBool("doclassifyindex");
00081         mAnnotations = options.GetString("annotations");
00082         mImpalaTmp = options.GetString("impalatmp");
00083         mCuda = options.GetBool("cuda");
00084         mCudaDevice = options.GetInt("cudaDevice");
00085         mInteractive = options.GetBool("interactive");
00086         mDryRun = options.GetBool("dryrun");
00087         mInputServer = options.GetString("inputserver");
00088         mExports.Add("INPUTSERVER", mInputServer);
00089         mRefServer = options.GetString("refserver");
00090 
00091         mWG.push_back("vissem_proto_annotation_nrScales_2_nrRects_130");
00092         mWG.push_back("vissemgabor_proto_annotation_nrScales_2_nrRects_130");
00093         mWG.push_back("fusionvissemgabor_proto_annotation_nrScales_2_nrRects_130");
00094         mWGclus960sp.push_back("vissem_proto_clusters_keyframes_all_maxlen_960_sp_1");
00095         mWGclus960sp.push_back("vissemgabor_proto_clusters_keyframes_all_maxlen_960_sp_1");
00096         mWGclus960sp.push_back("fusionvissemgabor_proto_clusters_keyframes_all_maxlen_960_sp_1");
00097         mAllSift.push_back("densesampling-sift-p11");
00098         mAllSift.push_back("densesampling-sift-p112213");
00099         mAllSift.push_back("harrislaplace-sift-p11");
00100         mAllSift.push_back("harrislaplace-sift-p112213");
00101         mAllSift.push_back("densesampling2-sift-p11");
00102         mAllSift.push_back("densesampling2-sift-p112213");
00103         mAllSift.push_back("both2-sift-p11");
00104         mAllSift.push_back("both2-sift-p112213");
00105         mAllSift.push_back("densesampling-opponentsift-p11");
00106         mAllSift.push_back("densesampling-opponentsift-p112213");
00107         mAllSift.push_back("harrislaplace-opponentsift-p11");
00108         mAllSift.push_back("harrislaplace-opponentsift-p112213");
00109         mAllSift.push_back("densesampling2-opponentsift-p11");
00110         mAllSift.push_back("densesampling2-opponentsift-p112213");
00111         mAllSift.push_back("both2-opponentsift-p11");
00112         mAllSift.push_back("both2-opponentsift-p112213");
00113         mAllSift.push_back("both2-3sift-p112213");
00114         mAllSift.push_back("both2-5sift-p112213");
00115         mAllSurf.push_back("none-surf-p11");
00116         mAllSurf.push_back("none-surf-p112213");
00117         mAllSurf.push_back("none-opponentsurf-p11");
00118         mAllSurf.push_back("none-opponentsurf-p112213");
00119         mAllSurf.push_back("none-rgbsurf-p11");
00120         mAllSurf.push_back("none-rgbsurf-p112213");
00121     }
00122 
00123     int
00124     Go()
00125     {
00126         ILOG_INFO("Doing " << mTopCmd);
00127         Timer timer(1);
00128         if (FileNameExt(mTopCmd) == "ido")
00129             HandleCmdFile(mTopCmd);
00130         else
00131             HandleCmd(mTopCmd);
00132 
00133         int nrOfErrors = ILOG_ERROR_COUNT;
00134         ILOG_INFO("Done processing in " << timer.SplitTimeStr() <<
00135                   ", total nr error = " << nrOfErrors);
00136         return nrOfErrors;
00137     }
00138 
00139     void
00140     HandleCmdFile(CString fileName)
00141     {
00142         String path;
00143         if (FileExists(fileName))
00144         {
00145             path = fileName;
00146         }
00147         else
00148         {
00149             String s =
00150                 StringResolveEnv("${IMPALAROOT}/src/script/ido/" + fileName);
00151             if (FileExists(s))
00152                 path = s;
00153         }
00154         if (path.empty())
00155         {
00156             ILOG_ERROR("Unable to find file " << fileName);
00157             return;
00158         }
00159         std::vector<String> lines;
00160         FileReadString(std::back_inserter(lines), path);
00161         for (int i=0 ; i<lines.size() ; i++)
00162         {
00163             if (StringStartsWith(lines[i], "exit"))
00164             {
00165                 ILOG_INFO("HandleCmd: doing exit");
00166                 break;
00167             }
00168             HandleCmd(lines[i]);
00169         }
00170     }
00171 
00172     void
00173     HandleCmd(CString cmdLine)
00174     {
00175         ILOG_INFO("HandleCmd " << cmdLine);
00176         if (!AskUserPermission(cmdLine))
00177             return;
00178 
00179         InitCurCmd(cmdLine);
00180         String cmd = GetCurCmd();
00181         if ((cmd == "set") || (cmd == "export"))
00182         {
00183             HandleOption(cmdLine);
00184             return;
00185         }
00186         if (cmd == "system")
00187             return DoSystem(cmdLine);
00188 
00189         // stage commands
00190         if (cmd == "stage")
00191             return Stage();
00192         if (cmd == "stageImages")
00193             return StageImages();
00194         if (cmd == "stageVideos")
00195             return StageVideos();
00196         if (cmd == "stagePrepTry")
00197             return StagePrepTry();
00198         if (cmd == "stagePrepTryOutput")
00199             return StagePrepTryOutput();
00200         if (cmd == "stageFeatureWGOutput")
00201             return StageFeatureWGOutput();
00202         if (cmd == "stageFeatureSiftOutput")
00203             return StageFeatureSiftOutput();
00204         if (cmd == "stageVocMini")
00205             return StageVocMini();
00206 
00207         // clean commands
00208         if (cmd == "cleanPrepIm")
00209             return CleanPrepIm();
00210         if (cmd == "cleanPrepTest")
00211             return CleanPrepTest();
00212         if (cmd == "cleanPrepTry")
00213             return CleanPrepTry();
00214         if (cmd == "cleanMpeg7")
00215             return CleanMpeg7();
00216         if (cmd == "cleanMergedAnnotations")
00217             return CleanMergedAnnotations();
00218         if (cmd == "cleanSm2")
00219             return CleanSm2();
00220         if (cmd == "cleanClus")
00221             return CleanClus();
00222         if (cmd == "cleanCluster")
00223             return CleanCluster();
00224         if (cmd == "cleanFeature")
00225             return CleanFeature();
00226         if (cmd == "cleanAveragesBoth2SiftP112213")
00227             return CleanAverages("both2-sift-p112213");
00228         if (cmd == "cleanModel")
00229             return CleanModel(false);
00230         if (cmd == "cleanModelIndex")
00231             return CleanModel(true);
00232         if (cmd == "cleanClassify")
00233             return CleanClassify();
00234         if (cmd == "cleanExportConcepts")
00235             return CleanExportConcepts();
00236 
00237         if ((mVideoSet == 0) && (mImageSet == 0))
00238         {
00239             ILOG_ERROR("Need dataset");
00240             return;
00241         }
00242 
00243         // processing commands
00244         if (cmd == "shotsegmenter")
00245             return ShotSegmenter();
00246         if (cmd == "keyframes")
00247             return Keyframes();
00248         if (cmd == "frames")
00249             return Frames();
00250         if (cmd == "framehashes")
00251             return FrameHashes();
00252         if (cmd == "clusterSift")
00253             return ClusterSift();
00254         if (cmd == "clusterSurf")
00255             return ClusterSiftExec("none-surf", "none-surf_sc_3-2-4");
00256         if (cmd == "clusterOpponentSurf")
00257             return ClusterSiftExec("none-opponentsurf",
00258                                    "none-opponentsurf_sc_3-2-4");
00259         if (cmd == "clusterRgbSurf")
00260             return ClusterSiftExec("none-rgbsurf", "none-rgbsurf_sc_3-2-4");
00261         if (cmd == "makeforestSurf")
00262             return MakeforestExec("none-surf");
00263         if (cmd == "makeforestOpponentSurf")
00264             return MakeforestExec("none-opponentsurf");
00265         if (cmd == "makeforestRgbSurf")
00266             return MakeforestExec("none-rgbsurf");
00267         if (cmd == "featureWG")
00268             return FeatureWG();
00269         if (cmd == "featureWGclus960sp")
00270             return FeatureWGclus960sp();
00271         if (cmd == "featureindexWG")
00272             return FeatureIndexExec(mWG[0], mWG[1], mWG[2]);
00273         if (cmd == "featureindexWGclus960sp")
00274             return FeatureIndexExec(mWGclus960sp[0], mWGclus960sp[1],
00275                                     mWGclus960sp[2]);
00276         if (cmd == "featureHarrisSift")
00277             return FeatureHarrisGenericSift("sift", "", "");
00278         if (cmd == "indexannotatedfeatureHarrisSift")
00279             return IndexAnnotatedFeatureHarrisGenericSift("sift", "");
00280         if (cmd == "featureDense2Sift")
00281             return FeatureDense2GenericSift("sift", "", "");
00282         if (cmd == "indexannotatedfeatureDense2Sift")
00283             return IndexAnnotatedFeatureDense2GenericSift("sift", "");
00284         if (cmd == "featureHarrisOpponentSift")
00285             return FeatureHarrisGenericSift("opponentsift", "", "");
00286         if (cmd == "featureDense2OpponentSift")
00287             return FeatureDense2GenericSift("opponentsift", "", "");
00288         if (cmd == "featureDense23Sift")
00289             return FeatureDense23Sift();
00290         if (cmd == "feature3Sift")
00291             return Feature3Sift();
00292         if (cmd == "featureAllSift")
00293             return FeatureAllSift();
00294         if (cmd == "featureUnc2Sift")
00295             return FeatureUnc2Sift();
00296         if (cmd == "featureUnc4Sift")
00297             return FeatureUnc4Sift();
00298         if (cmd == "featureSurf")
00299             return FeatureNoneGenericSurf("surf", "", "");
00300         if (cmd == "featureOpponentSurf")
00301             return FeatureNoneGenericSurf("opponentsurf", "", "");
00302         if (cmd == "featureRgbSurf")
00303             return FeatureNoneGenericSurf("rgbsurf", "", "");
00304         if (cmd == "featureForestSurf")
00305             return FeatureNoneGenericSurf("surf", "", "cm_forest");
00306         if (cmd == "featureForestOpponentSurf")
00307             return FeatureNoneGenericSurf("opponentsurf", "", "cm_forest");
00308         if (cmd == "featureForestRgbSurf")
00309             return FeatureNoneGenericSurf("rgbsurf", "", "cm_forest");
00310         if (cmd == "precomputeWG")
00311             return PrecomputeWG();
00312         if (cmd == "precomputeWGclus960sp")
00313             return PrecomputeWGclus960sp();
00314         if (cmd == "precomputeDense2SiftP11")
00315             return PrecomputeExec("densesampling2-sift-p11");
00316         if (cmd == "precomputeDense2SiftP1113")
00317             return PrecomputeExec("densesampling2-sift-p1113");
00318         if (cmd == "precomputeBoth2SiftP112213")
00319             return PrecomputeExec("both2-sift-p112213");
00320         if (cmd == "precomputeBoth2OpponentSiftP112213")
00321             return PrecomputeExec("both2-opponentsift-p112213");
00322         if (cmd == "precomputeDense23Sift")
00323             return PrecomputeExec("dense2-3sift-p112213");
00324         if (cmd == "precompute3Sift")
00325             return PrecomputeExec("both2-3sift-p112213");
00326         if (cmd == "precomputeUnc4Sift")
00327             return PrecomputeExec("unc-both2-4sift-p112213");
00328         if (cmd == "precomputeAllSift")
00329             return PrecomputeAllSift();
00330         if (cmd == "precomputeSurfP112213")
00331             return PrecomputeExec("none-surf-p112213");
00332         if (cmd == "precomputeOpponentSurfP112213")
00333             return PrecomputeExec("none-opponentsurf-p112213");
00334         if (cmd == "precomputeRgbSurfP112213")
00335             return PrecomputeExec("none-rgbsurf-p112213");
00336         if (cmd == "precomputeAllSurf")
00337             return PrecomputeAllSurf();
00338         if (cmd == "modelTestW")
00339             return ModelTestW();
00340         if (cmd == "modelPreWG")
00341             return ModelPreWG();
00342         if (cmd == "modelPreWGclus960sp")
00343             return ModelPreWGclus960sp();
00344         if (cmd == "modelPreDense2SiftP11")
00345             return ModelExec("densesampling2-sift-p11", "");
00346         if (cmd == "modelPreDense2SiftP1113")
00347             return ModelExec("densesampling2-sift-p1113", "");
00348         if (cmd == "modelPreBoth2SiftP112213")
00349             return ModelExec("both2-sift-p112213", "");
00350         if (cmd == "modelPreBoth2OpponentSiftP112213")
00351             return ModelExec("both2-opponentsift-p112213", "");
00352         if (cmd == "modelPreDense23SiftP112213")
00353             return ModelExec("dense2-3sift-p112213", "");
00354         if (cmd == "modelPreAllSift")
00355             return ModelPreAllSift();
00356         if (cmd == "modelPreSurfP112213")
00357             return ModelExec("none-surf-p112213", "");
00358         if (cmd == "modelPreAllSurf")
00359             return ModelPreAllSurf();
00360         if (cmd == "modelOldWG")
00361             return ModelOldWG();
00362         if (cmd == "modelOldWGclus960sp")
00363             return ModelOldWGclus960sp();
00364         if (cmd == "classifyPreWG")
00365             return ClassifyPreWG();
00366         if (cmd == "classifyPreWGclus960sp")
00367             return ClassifyPreWGclus960sp();
00368         if (cmd == "classifyPreDense2SiftP11")
00369             return ClassifyExec("densesampling2-sift-p11", true);
00370         if (cmd == "classifyPreDense2SiftP1113")
00371             return ClassifyExec("densesampling2-sift-p1113", true);
00372         if (cmd == "classifyPreBoth2SiftP112213")
00373             return ClassifyExec("both2-sift-p112213", true);
00374         if (cmd == "classifyPreBoth2OpponentSiftP112213")
00375             return ClassifyExec("both2-opponentsift-p112213", true);
00376         if (cmd == "classifyPreDense23SiftP112213")
00377             return ClassifyExec("dense2-3sift-p112213", true);
00378         if (cmd == "classifyPre3Sift")
00379             return ClassifyExec("both2-3sift-p112213", true);
00380         if (cmd == "classifyPreAllSift")
00381             return ClassifyPreAllSift();
00382         if (cmd == "classifyPreSurfP112213")
00383             return ClassifyExec("none-surf-p112213", true);
00384         if (cmd == "classifyPreOpponentSurfP112213")
00385             return ClassifyExec("none-opponentsurf-p112213", true);
00386         if (cmd == "classifyPreRgbSurfP112213")
00387             return ClassifyExec("none-rgbsurf-p112213", true);
00388         if (cmd == "classifyPreAllSurf")
00389             return ClassifyPreAllSurf();
00390         if (cmd == "classifyOldWG")
00391             return ClassifyOldWG();
00392         if (cmd == "classifyOldWGclus960sp")
00393             return ClassifyOldWGclus960sp();
00394         if (cmd == "exportConceptsWG")
00395             return ExportConceptsExec("combined");
00396         if (cmd == "importConceptsWG")
00397             return ImportConceptsExec("imported-combined");
00398         if (cmd == "mapWG")
00399             return MapWG();
00400         if (cmd == "mapWGclus960sp")
00401             return MapWGclus960sp();
00402         if (cmd == "mapPreWGclus960sp")
00403             return MapPreWGclus960sp();
00404         if (cmd == "mapPreDense2SiftP1113")
00405             return MapExec("densesampling2-sift-p1113", false);
00406         if (cmd == "mapPreBoth2SiftP112213")
00407             return MapExec("both2-sift-p112213", false);
00408         if (cmd == "mapPreAllSift")
00409             return MapPreAllSift();
00410         if (cmd == "mapPreSurfP112213")
00411             return MapExec("none-surf-p112213", false);
00412         if (cmd == "mapPreAllSurf")
00413             return MapPreAllSurf();
00414         if (cmd == "iexec")
00415             return IExec(cmdLine);
00416         if (cmd == "repositoryexec")
00417             return DoRepositoryExec(cmdLine);
00418 
00419         // check commands
00420         if (cmd == "checkPrepIm")
00421             return CheckPrepIm();
00422         if (cmd == "checkVideoAccess")
00423             return CheckVideoAccess();
00424         if (cmd == "checkPrepTest")
00425             return CheckPrepTest();
00426         if (cmd == "checkPrepTry")
00427             return CheckPrepTry();
00428         if (cmd == "checkMpeg7")
00429             return CheckMpeg7();
00430         if (cmd == "checkMergedAnnotations")
00431             return CheckMergedAnnotations();
00432         if (cmd == "checkSm2VissemKeyfr")
00433             return CheckSm2VissemKeyfr();
00434         if (cmd == "checkSm2VissemGaborKeyfr")
00435             return CheckSm2VissemGaborKeyfr();
00436         if (cmd == "checkClusVissem")
00437             return CheckClusVissem();
00438         if (cmd == "checkClusVissemGabor")
00439             return CheckClusVissemGabor();
00440         if (cmd == "checkClusterSift")
00441             return CheckClusterSift();
00442         if (cmd == "checkClusterSurf")
00443             return CheckClusterSurf();
00444         if (cmd == "checkMakeforestAllSurf")
00445             return CheckMakeforestAllSurf();
00446         if (cmd == "checkFeatureWG")
00447             return CheckFeature(mWG[2]);
00448         if (cmd == "checkFeatureWGclus960sp")
00449             return CheckFeature(mWGclus960sp[2]);
00450         if (cmd == "checkFeatureSift")
00451             return CheckFeaturePyramid3("sift", false);
00452         if (cmd == "checkFeatureOpponentSift")
00453             return CheckFeaturePyramid3("opponentsift", false);
00454         if (cmd == "checkFeature3Sift")
00455             return CheckFeature3Sift();
00456         if (cmd == "checkFeatureAllSift")
00457             return CheckFeatureAllSift();
00458         if (cmd == "checkFeatureUnc4Sift")
00459             return CheckFeatureUnc4Sift();
00460         if (cmd == "checkFeatureSurf")
00461             return CheckFeaturePyramidNone("surf", "");
00462         if (cmd == "checkFeatureAllSurf")
00463             return CheckFeatureAllSurf();
00464         if (cmd == "checkFeatureForestAllSurf")
00465             return CheckFeatureForestAllSurf();
00466         if (cmd == "checkPrecomputeWG")
00467             return CheckPrecomputeWG();
00468         if (cmd == "checkPrecomputeBoth2SiftP112213")
00469             return CheckPrecompute("both2-sift-p112213");
00470         if (cmd == "checkPrecomputeUnc4Sift")
00471             return CheckPrecompute("unc-both2-4sift-p112213");
00472         if (cmd == "checkPrecomputeSurfP112213")
00473             return CheckPrecompute("none-surf-p112213");
00474         if (cmd == "checkModelWG")
00475             return CheckModelWG();
00476         if (cmd == "checkModelWGclus960sp")
00477             return CheckModelWGclus960sp();
00478         if (cmd == "checkModelBoth2SiftP112213")
00479             return CheckModel("both2-sift-p112213");
00480         if (cmd == "checkModelAllSift")
00481             return CheckModelAllSift();
00482         if (cmd == "checkModelSurfP112213")
00483             return CheckModel("none-surf-p112213");
00484         if (cmd == "checkClassifyOldWG")
00485             return CheckSimilarities("combined");
00486         if (cmd == "checkClassifyOldWGclus960sp")
00487             return CheckSimilarities("combined960sp");
00488         if (cmd == "checkClassifyPreWG")
00489             return CheckClassifyPreWG();
00490         if (cmd == "checkClassifyPreWGclus960sp")
00491             return CheckSimilarities("combinedClus960sp");
00492         if (cmd == "checkClassifyPreBoth2SiftP112213")
00493             return CheckClassifyPreBoth2SiftP112213();
00494         if (cmd == "checkClassifyPreAllSift")
00495             return CheckClassifyPreAllSift();
00496         if (cmd == "checkClassifyPreSurfP112213")
00497             return CheckClassifyPreSurfP112213();
00498         if (cmd == "checkExportConceptsWG")
00499             return CheckSimilarities("imported-combined");
00500 
00501         ILOG_ERROR("Unknown cmd " << cmd);
00502     }
00503 
00504     void
00505     HandleOption(CString cmdLine)
00506     {
00507         ILOG_INFO("HandleOption " << cmdLine);
00508         if (StringStartsWith(cmdLine, "set -o errexit"))
00509         {
00510             gExitOnErrorLogged = true;
00511             return;
00512         }
00513         Util::StringParser p(cmdLine);
00514         String cmd = p.GetString(' ', false);
00515         if (cmd == "set")
00516             return; // ignore other set options
00517 
00518         if (cmd == "export")
00519         {
00520             String var = p.GetString('=');
00521             String val = p.GetString2(false);
00522             mExports.Add(var, val);
00523             StringToLower(var);
00524             if (var == "set")
00525                 InitSet(val);
00526             else if (var == "ncpu")
00527                 mNCPU = atol(val);
00528             else if (var == "nodes")
00529                 mNodes = atol(val);
00530             else if (var == "ppn")
00531                 mPPN = atol(val);
00532             else if (var == "srcopt")
00533                 mSrcOpt = val;
00534             else if (var == "srcopt1")
00535                 mSrcOpt1 = val;
00536             else if (var == "srcopt2")
00537                 mSrcOpt2 = val;
00538             else if (var == "shotopt")
00539                 mShotOpt = val;
00540             else if (var == "extra2")
00541                 mExtra2 = val;
00542             else if (var == "frames_jpg")
00543                 mFramesJpg = val;
00544             else if (var == "skip_stills")
00545                 mSkipStills = val;
00546             else if (var == "frames")
00547                 mFrames = atol(val);
00548             else if (var == "rkf")
00549                 mRkf = atol(val);
00550             else if (var == "quidfile")
00551                 mQuidFile = val;
00552             else if (var == "tasknrframes")
00553                 mTaskNrFrames = atol(val);
00554             else if (var == "taskblocksize")
00555                 mTaskBlockSize = atol(val);
00556             else if (var == "tasknrblocks")
00557                 mTaskNrBlocks = atol(val);
00558             else if (var == "noimarchive")
00559                 mNoImArchive = atol(val);
00560             else if (var == "limit")
00561                 mLimit = val;
00562             else if (var == "clusters")
00563                 mClusters = val;
00564             else if (var == "randomize")
00565                 mRandomize = val;
00566             else if (var == "protoset")
00567                 mProtoSet = val;
00568             else if (var == "codebook")
00569                 mCodebook = val;
00570             else if (var == "dofeature")
00571                 mDoFeature = atol(val);
00572             else if (var == "dofeatureindex")
00573                 mDoFeatureIndex = atol(val);
00574             else if (var == "precomputeincrement")
00575                 mPrecomputeIncrement = atol(val);
00576             else if (var == "precomputeruns")
00577                 mPrecomputeRuns = atol(val);
00578             else if (var == "featureindexcat")
00579                 mFeatureIndexCat = val;
00580             else if (var == "classifyindexcat")
00581                 mClassifyIndexCat = val;
00582             else if (var == "episode_constrained")
00583                 mEpisodeConstrained = val;
00584             else if (var == "skip_fusion")
00585                 mSkipFusion = val;
00586             else if (var == "annoset")
00587                 mAnnoSet = val;
00588             else if (var == "annosettest")
00589                 mAnnoSetTest = val;
00590             else if (var == "concepts")
00591                 mConcepts = val;
00592             else if (var == "model")
00593                 mModel = val;
00594             else if (var == "fik")
00595                 mFik = atol(val);
00596             else if (var == "modelbins")
00597                 mModelBins = atol(val);
00598             else if (var == "computekerneldata")
00599                 mComputeKernelData = atol(val);
00600             else if (var == "storekerneldata")
00601                 mStoreKernelData = val;
00602             else if (var == "kerneldataonly")
00603                 mKernelDataOnly = val;
00604             else if (var == "doclassifyindex")
00605                 mDoClassifyIndex = atol(val);
00606             else if (var == "annotations")
00607                 mAnnotations = val;
00608             else if (var == "impalatmp")
00609                 mImpalaTmp = val;
00610             else if (var == "cuda")
00611                 mCuda = atol(val);
00612             else if (var == "cudadevice")
00613                 mCudaDevice = atol(val);
00614             else if (var == "interactive")
00615                 mInteractive = atol(val);
00616             else if (var == "dryrun")
00617                 mDryRun = atol(val);
00618             else if (var == "inputserver")
00619                 mInputServer = val;
00620             else if (var == "refserver")
00621                 mRefServer = val;
00622             else ILOG_ERROR("Unknown option " << cmdLine);
00623             return;
00624         }
00625 
00626         ILOG_ERROR("Unknown option " << cmdLine);
00627     }
00628 
00629     void
00630     ShotSegmenter()
00631     {
00632         String srcOpt1("lavcwriteidx");
00633         String srcOpt2("lavc");
00634         if (! mSrcOpt.empty())
00635         {
00636             srcOpt1 = mSrcOpt;
00637             srcOpt2 = mSrcOpt;
00638         }
00639         if (! mSrcOpt1.empty())
00640             srcOpt1 = mSrcOpt1;
00641         if (! mSrcOpt2.empty())
00642             srcOpt2 = mSrcOpt2;
00643         for (int i=0 ; i<GetCurCmdNrArgs() ; i++)
00644         {
00645             String arg = GetCurCmdArg(i);
00646             if (arg == "--noIndex")
00647                 mDoShotIndex = false;
00648             else
00649                 mShotOpt += arg + " ";
00650         }
00651         Exec("vidset", "shotsegmenter " + mSetName + " --report 500 --src " +
00652              srcOpt1 + " " + mShotOpt);
00653         if (mShotOpt.find("SSNoMpeg7") != String::npos)
00654             mDoShotIndex = false;
00655         if (mDoShotIndex)
00656         {
00657             Exec("vidset", "indexsegmentation " + mSetName +
00658                  " --stepSize 10000000 --src " + srcOpt2, 1);
00659         }
00660         if (mExtra2 == "yes")
00661         {
00662             Exec("vidset", "selectframes " + mSetName +
00663                  " keysExtra2.tab 2 --src " + srcOpt2 +
00664                  " --segmentation --iFrames --report 100", 1);
00665         }
00666     }
00667 
00668     void
00669     Keyframes()
00670     {
00671         String srcOpt = mSrcOpt;
00672         if (srcOpt.empty())
00673             srcOpt = "lavc";
00674 
00675         //String fixSize("png 352");
00676         String fixSize("");
00677         Exec("vidset", "exportframes " + mSetName + " split " + fixSize +
00678              " --keyframes --src " + srcOpt + "  --report 100");
00679         if (mFramesJpg == "yes")
00680         {
00681             //String scale("176");
00682             String scale("0.5");
00683             Exec("vidset", "exportframes " + mSetName + " split jpg " + scale +
00684                  " --src " + srcOpt + "  --report 100");
00685         }
00686 
00687         Exec("vidset", "exportkeyframes " + mSetName + " keyframes.txt 1.0 " +
00688              "split jpg 90 --keyframes --keyframeSrc --report 100");
00689         Exec("vidset", "exportkeyframes " + mSetName + " thumbnails.txt 0.5 " +
00690              "archive jpg 90 --keyframes --keyframeSrc --report 100", 1);
00691 
00692         Exec("vidset", "exportstills " + mSetName +
00693              " def --stepSize 10000000 --src " + srcOpt + " --report 1", 1);
00694         if (mSkipStills.empty())
00695         {
00696             Exec("vidset", "exportstills " + mSetName +
00697                  " data 90 --stepSize 10000000 --src " + srcOpt + " --report 1");
00698         }
00699     }
00700 
00701     void
00702     Frames()
00703     {
00704         String srcOpt = mSrcOpt;
00705         if (srcOpt.empty())
00706             srcOpt = "lavc";
00707 
00708         if (mFramesJpg == "yes")
00709         {
00710             String scale("0.5");
00711             Exec("vidset", "exportframes " + mSetName + " split jpg " + 
00712                  scale + " --src " + srcOpt + " --report 1000");
00713         }
00714         else
00715         {
00716             String fixSize("");
00717             Exec("vidset", "exportframes " + mSetName + " split " + 
00718                  fixSize + " --src " + srcOpt + " --report 1000");
00719         }
00720     }
00721 
00722     void
00723     FrameHashes()
00724     {
00725         String srcOpt = mSrcOpt;
00726         if (srcOpt.empty())
00727             srcOpt = "lavc";
00728 
00729         Exec("vidset", "exportframehashes " + mSetName + " --src " + srcOpt + 
00730              " --report 1000");
00731     }
00732 
00733     void
00734     ClusterSift()
00735     {
00736         ClusterSiftExec("harrislaplace-sift", "harrislaplace-sift");
00737         ClusterSiftExec("densesampling2-sift", "densesampling-sift_ds_6-1.2-2");
00738     }
00739 
00740     void
00741     ClusterSiftExec(CString feature, CString featureDesc)
00742     {
00743         String prog = GetWalkerProg();
00744         String frameWalk = GetFrameWalk();
00745 
00746         // Koen says : 200000-300000 vectors is good, more is also possible...
00747         Exec(prog, "interestpointproc " + mSetName + " " + frameWalk +
00748              " --borderWidth 0 --tmpPath " + mImpalaTmp +
00749              " --noZIP --clusterInput --keepLimited " + mLimit +
00750              " " + mRandomize + " --ini ${IMPALAROOT}/src/script/" + feature +
00751              ".ini --report 25");
00752 
00753         Exec2("constructcodebook " + mSetName + " " + featureDesc +
00754               "_clusterinput_2 Codebooks/" + feature + ".tab " + mClusters, "");
00755     }
00756 
00757     void
00758     MakeforestExec(CString feature)
00759     {
00760         if (mConcepts.empty())
00761         {
00762             ILOG_ERROR("MakeforestExec: need concepts");
00763             return;
00764         }
00765 
00766         Exec2("randomforest " + mSetName + " " + mConcepts + " 0 " + feature +
00767               " --forest-depth 6 --forest-tries 4", "");
00768     }
00769 
00770     void
00771     FeatureWG()
00772     {
00773         FeatureExec(mWG[0], mWG[1], mWG[2], "0", "vissem.ini");
00774     }
00775 
00776     void
00777     FeatureWGclus960sp()
00778     {
00779         FeatureExec(mWGclus960sp[0], mWGclus960sp[1], mWGclus960sp[2], "20",
00780                     "vissemClusterSP.ini");
00781     }
00782 
00783     void
00784     FeatureExec(CString feature1, CString feature2, CString feature3,
00785                 CString featureLimit, CString featureIni)
00786     {
00787         if (mProtoSet.empty())
00788         {
00789             ILOG_ERROR("FeatureExec: need protoset");
00790             return;
00791         }
00792 
00793         String prog = GetWalkerProg();
00794         String frameWalk = GetFrameWalk();
00795         String cmd1 = "viseval " + mSetName + " " + mProtoSet + " " +
00796             feature1 + ".txt " + featureLimit + " " + frameWalk +
00797             " --ini ${IMPALAROOT}/src/script/" + featureIni + " --report 10";
00798         int ncpu = (mTaskBlockSize > 0) ? mTaskBlockSize : mNCPU;
00799         for (int i=0 ; i<mTaskNrBlocks ; i++)
00800         {
00801             String startT("");
00802             if (mTaskBlockSize > 0)
00803                 startT = " --startTask " + MakeString(i * mTaskBlockSize);
00804             Exec(prog, cmd1 + startT, ncpu);
00805         }
00806         Exec(prog, "concatfeatures " + mSetName + " " + feature1 + ".txt " +
00807              frameWalk + " --virtualWalk");
00808         //Exec(prog, "exportfeatures " + mSetName + " 25 " + feature1 + " " +
00809         //     frameWalk + " --virtualWalk " + segm);
00810 
00811         String cmd2 = "visgaboreval " + mSetName + " " + mProtoSet + " " +
00812             feature2 + ".txt " + featureLimit + " " + frameWalk +
00813             " --ini ${IMPALAROOT}/src/script/" + featureIni + " --report 10";
00814         for (int i=0 ; i<mTaskNrBlocks ; i++)
00815         {
00816             String startT("");
00817             if (mTaskBlockSize > 0)
00818                 startT = " --startTask " + MakeString(i * mTaskBlockSize);
00819             Exec(prog, cmd2 + startT, ncpu);
00820         }
00821         Exec(prog, "concatfeatures " + mSetName + " " + feature2 + ".txt " +
00822              frameWalk + " --virtualWalk");
00823         //Exec(prog, "exportfeatures " + mSetName + " 25 " + feature2 + " " +
00824         //     frameWalk + " --virtualWalk " + segm);
00825 
00826         String segm = (mVideoSet) ? "--segmentation" : "";
00827         if (mTaskBlockSize > 0)
00828             frameWalk = "";
00829         Exec(prog, "concatfeatures " + mSetName + " " + feature3 + " " +
00830              feature1 + " " + feature2 + " " + frameWalk + " --virtualWalk " +
00831              segm);
00832     }
00833 
00834     void
00835     FeatureIndexExec(CString feature1, CString feature2, CString feature3)
00836     {
00837         String prog = GetWalkerProg();
00838         String frameWalk = GetFrameWalk();
00839         Exec(prog, "indexfeatures " + mSetName + " " + feature1 + " " + 
00840              frameWalk + " --virtualWalk", 1);
00841         Exec(prog, "indexfeatures " + mSetName + " " + feature2 + " " + 
00842              frameWalk + " --virtualWalk", 1);
00843         Exec(prog, "indexfeatures " + mSetName + " " + feature3 + " " + 
00844              frameWalk + " --virtualWalk", 1);
00845     }
00846 
00847     void
00848     FeatureDense23Sift()
00849     {
00850         FeatureDense2GenericSift("sift", "", "");
00851         FeatureDense2GenericSift("opponentsift", "", "");
00852         FeatureDense2GenericSift("rgbsift", "", "");
00853     }
00854 
00855     void
00856     Feature3Sift()
00857     {
00858         FeatureHarrisGenericSift("sift", "", "");
00859         FeatureDense2GenericSift("sift", "", "");
00860 
00861         FeatureHarrisGenericSift("opponentsift", "", "");
00862         FeatureDense2GenericSift("opponentsift", "", "");
00863 
00864         FeatureHarrisGenericSift("rgbsift", "", "");
00865         FeatureDense2GenericSift("rgbsift", "", "");
00866     }
00867 
00868     void
00869     FeatureAllSift()
00870     {
00871         FeatureDenseGenericSift("sift", "", "");
00872         FeatureHarrisGenericSift("sift", "", "");
00873         FeatureDense2GenericSift("sift", "", "");
00874 
00875         FeatureDenseGenericSift("opponentsift", "", "");
00876         FeatureHarrisGenericSift("opponentsift", "", "");
00877         FeatureDense2GenericSift("opponentsift", "", "");
00878 
00879         FeatureHarrisGenericSift("rgbsift", "", "");
00880         FeatureDense2GenericSift("rgbsift", "", "");
00881 
00882         FeatureHarrisGenericSift("rgsift", "", "");
00883         FeatureDense2GenericSift("rgsift", "", "");
00884 
00885         FeatureHarrisGenericSift("csift", "", "");
00886         FeatureDense2GenericSift("csift", "", "");
00887     }
00888 
00889     void
00890     FeatureUnc2Sift()
00891     {
00892         FeatureHarrisGenericSift("sift", "unc", "cm_unc_cs_75");
00893         FeatureDense2GenericSift("sift", "unc", "cm_unc_cs_50");
00894 
00895         FeatureHarrisGenericSift("rgbsift", "unc", "cm_unc_cs_120");
00896         FeatureDense2GenericSift("rgbsift", "unc", "cm_unc_cs_80");
00897     }
00898 
00899     void
00900     FeatureUnc4Sift()
00901     {
00902         FeatureHarrisGenericSift("sift", "unc", "cm_unc_cs_75");
00903         FeatureDense2GenericSift("sift", "unc", "cm_unc_cs_50");
00904 
00905         FeatureHarrisGenericSift("opponentsift", "unc", "cm_unc_cs_120");
00906         FeatureDense2GenericSift("opponentsift", "unc", "cm_unc_cs_80");
00907 
00908         FeatureHarrisGenericSift("rgbsift", "unc", "cm_unc_cs_120");
00909         FeatureDense2GenericSift("rgbsift", "unc", "cm_unc_cs_80");
00910 
00911         FeatureHarrisGenericSift("csift", "unc", "cm_unc_cs_120");
00912         FeatureDense2GenericSift("csift", "unc", "cm_unc_cs_80");
00913     }
00914 
00915     void
00916     FeatureHarrisGenericSift(CString siftVersion, CString assign, CString cMode)
00917     {
00918         if (mDoFeature)
00919             FeatureSiftExec("harrislaplace-" + siftVersion, assign, "");
00920         if (mDoFeatureIndex)
00921             FeatureIndexSiftExec("harrislaplace-" + siftVersion, cMode);
00922     }
00923 
00924     void
00925     IndexAnnotatedFeatureHarrisGenericSift(CString siftVersion, CString cMode)
00926     {
00927         IndexAnnotatedFeatureSiftExec("harrislaplace-" + siftVersion, cMode);
00928     }
00929 
00930     void
00931     FeatureDenseGenericSift(CString siftVersion, CString assign, CString cMode)
00932     {
00933         if (mDoFeature)
00934             FeatureSiftExec("densesampling-" + siftVersion, assign, "");
00935         if (mDoFeatureIndex)
00936             FeatureIndexSiftExec("densesampling-" + siftVersion + "_ds_6-1.2",
00937                                  cMode);
00938     }
00939 
00940     void
00941     FeatureDense2GenericSift(CString siftVersion, CString assign, CString cMode)
00942     {
00943         if (mDoFeature)
00944             FeatureSiftExec("densesampling2-" + siftVersion, assign, "");
00945         if (mDoFeatureIndex)
00946             FeatureIndexSiftExec("densesampling-" + siftVersion + "_ds_6-1.2-2",
00947                                  cMode);
00948     }
00949 
00950     void
00951     IndexAnnotatedFeatureDense2GenericSift(CString siftVersion, CString cMode)
00952     {
00953         IndexAnnotatedFeatureSiftExec("densesampling-" + siftVersion +
00954                                       "_ds_6-1.2-2", cMode);
00955     }
00956 
00957     void
00958     FeatureNoneGenericSurf(CString surfVersion, CString assign, CString cMode)
00959     {
00960         if (mDoFeature)
00961             FeatureSiftExec("none-" + surfVersion, assign, cMode);
00962         if (mDoFeatureIndex)
00963             FeatureIndexSiftExec("none-" + surfVersion + "_sc_3-2-4", cMode);
00964     }
00965 
00966     // assign is used to indicate "unc" or not for sift (codebookmode is in ini)
00967     // forest is used with surf and sets codebookmode via command option
00968     void
00969     FeatureSiftExec(CString feature, CString assign, CString forest)
00970     {
00971         if (mProtoSet.empty())
00972         {
00973             ILOG_ERROR("FeatureExec: need protoset");
00974             return;
00975         }
00976         String codebook = mCodebook;
00977         if (codebook.empty())
00978             codebook = "Codebooks/" + feature + ".tab";
00979         String ini = (assign.empty()) ? "" : assign + "-";
00980         ini = " --ini ${IMPALAROOT}/src/script/" + ini + feature + ".ini";
00981         String codebookMode = (forest.empty()) ? "" : "--codebookMode forest";
00982 
00983         String prog = GetWalkerProg();
00984         String frameWalk = GetFrameWalk();
00985         Exec(prog, "interestpointproc " + mSetName + " " + mProtoSet + " " +
00986              frameWalk + " --borderWidth 0 --tmpPath " + mImpalaTmp +
00987              " --noZIP --codebook " + codebook + " " + codebookMode +
00988              " --pointSelector pyramid-1x1-2x2-1x3" + ini + " --report 50");
00989 
00990         String segm = (mVideoSet) ? "--segmentation" : "";
00991         //Exec(prog, "exportfeatures " + mSetName + " 25 " + feature + " " +
00992         //     frameWalk + " --virtualWalk " + segm);
00993     }
00994 
00995     void
00996     FeatureIndexSiftExec(CString featureDesc, CString cMode)
00997     {
00998         String cbMode = (cMode.empty()) ? "" : "_" + cMode;
00999         String prog = GetWalkerProg();
01000         String frameWalk = GetFrameWalk();
01001         for (int i=0 ; i<8 ; i++)
01002         {
01003             String sub = (i == 0) ? "" : "_sub_" + MakeString(i);
01004             Exec(prog, "indexfeatures " + mSetName + " " + featureDesc +
01005                  "_ps_pyramid-1x1-2x2-1x3" + cbMode + sub + " " + frameWalk +
01006                  " --virtualWalk", 1);
01007         }
01008     }
01009 
01010     void
01011     IndexAnnotatedFeatureSiftExec(CString featureDesc, CString cMode)
01012     {
01013         if (mConcepts.empty())
01014         {
01015             ILOG_ERROR("IndexAnnotatedFeatureSiftExec: need concepts");
01016             return;
01017         }
01018         String args;
01019         for (int i=0 ; i<GetCurCmdNrArgs() ; i++)
01020             args += " " + GetCurCmdArg(i);
01021 
01022         String cbMode = (cMode.empty()) ? "" : "_" + cMode;
01023         String qClass = GetQuidClass();
01024         for (int i=0 ; i<8 ; i++)
01025         {
01026             String sub = (i == 0) ? "" : "_sub_" + MakeString(i);
01027             RepositoryExec("indexannotatedfeatures", qClass + " " + mConcepts +
01028                            " " + featureDesc + "_ps_pyramid-1x1-2x2-1x3" +
01029                            cbMode + sub + args);
01030         }
01031     }
01032 
01033     void
01034     PrecomputeWG()
01035     {
01036         PrecomputeExec(mWG[0]);
01037         PrecomputeExec(mWG[1]);
01038         PrecomputeExec(mWG[2]);
01039     }
01040 
01041     void
01042     PrecomputeWGclus960sp()
01043     {
01044         PrecomputeExec(mWGclus960sp[0]);
01045         PrecomputeExec(mWGclus960sp[1]);
01046         PrecomputeExec(mWGclus960sp[2]);
01047     }
01048 
01049     void
01050     PrecomputeAllSift()
01051     {
01052         for (int i=0 ; i<mAllSift.size() ; i++)
01053             PrecomputeExec(mAllSift[i]);
01054     }
01055 
01056     void
01057     PrecomputeAllSurf()
01058     {
01059         for (int i=0 ; i<mAllSurf.size() ; i++)
01060             PrecomputeExec(mAllSurf[i]);
01061     }
01062 
01063     void
01064     PrecomputeExec(CString kernel)
01065     {
01066         if (mModel.empty())
01067         {
01068             ILOG_ERROR("PrecomputeExec: need model");
01069             return;
01070         }
01071         bool isHik = StringStartsWith(mModel, "hik");
01072         String iniFile = "${IMPALAROOT}/src/script/" + kernel + ".ini";
01073         String cat("");
01074         if (! mFeatureIndexCat.empty())
01075             cat = " --featureIndexCat " + mFeatureIndexCat + " ";
01076 
01077         if (mCuda)
01078         {
01079             if (!isHik)
01080                 ComputeAverages(iniFile, cat);
01081             Exec("precomputecuda", mSetName + " " + mModel + " " + kernel + cat
01082                  + " --ini " + iniFile + " --cudaDevice "
01083                  + MakeString(mCudaDevice), 1);
01084             return;
01085         }
01086 
01087         String func = (isHik) ? " --distanceFunction histogramintersection "
01088                               : "";
01089         // At this moment, annoTestSet is used for testing purposes only.
01090         String annoSet = (mAnnoSetTest.empty()) ? "nil" : mAnnoSetTest;
01091         String cmd = mSetName + " " + annoSet + " " + mModel + " " + kernel
01092             + cat + func + " --ini " + iniFile;
01093         if (mPrecomputeIncrement == 0)
01094         {
01095             Exec("precompute", cmd);
01096         }
01097         else
01098         {
01099             int start = 0;
01100             for (int i=0 ; i<mPrecomputeRuns ; i++)
01101             {
01102                 Exec("precompute", cmd + " --startFeature " + MakeString(start)
01103                      + " --numberFeatures " + MakeString(mPrecomputeIncrement));
01104                 start += mPrecomputeIncrement;
01105             }
01106         }
01107     }
01108 
01109     void
01110     ComputeAverages(CString iniFile, CString cat)
01111     {
01112         String fileName = ResolveExports(iniFile);
01113         Persistency::File file = Persistency::RepositoryGetFile(fileName, false,
01114                                                                 false);
01115         Core::Feature::WeightedFeatureList fList;
01116         Read(&fList, file);
01117         for (int i=0 ; i<fList.Size() ; i++)
01118         {
01119             Exec("computeaveragecuda", mSetName + " " + fList.GetFeature(i)
01120                  + cat + " --cudaDevice " + MakeString(mCudaDevice), 1);
01121         }
01122     }
01123 
01124     void
01125     ModelTestW()
01126     {
01127         if (mConcepts.empty())
01128         {
01129             ILOG_ERROR("ModelTestW: need concepts");
01130             return;
01131         }
01132         if (mModel.empty())
01133         {
01134             ILOG_ERROR("ModelTestW: need model");
01135             return;
01136         }
01137         CleanCall("deletefold", "Frame concepts.txt anchor episode_folds 0");
01138         CleanCall("deletefold", "Frame concepts.txt anchor episode_folds 1");
01139         CleanCall("deletefold", "Frame concepts.txt anchor episode_folds 2");
01140 
01141         CleanCall("deletesvmproblem",
01142                   "concepts.txt testmodel " + mWG[0] + " anchor");
01143 
01144         String ini("${IMPALAROOT}/src/script/train.ini");
01145         Exec("crossvalidate", mSetName + " " + mConcepts + " " + mModel + " " +
01146              mWG[0] + " --ini " + ini + " " + mEpisodeConstrained +
01147              " --testMode");
01148 
01149         CheckCall("difffold", "Frame concepts.txt anchor episode_folds 0");
01150         CheckCall("difffold", "Frame concepts.txt anchor episode_folds 1");
01151         CheckCall("difffold", "Frame concepts.txt anchor episode_folds 2");
01152 
01153         CheckCall("diffsvmproblem",
01154                   "concepts.txt testmodel " + mWG[0] + " anchor");
01155     }
01156 
01157     void
01158     ModelPreWG()
01159     {
01160         ModelExec(mWG[0], "");
01161         ModelExec(mWG[1], "");
01162         ModelExec(mWG[2], "");
01163     }
01164 
01165     void
01166     ModelPreWGclus960sp()
01167     {
01168         ModelExec(mWGclus960sp[0], "");
01169         ModelExec(mWGclus960sp[1], "");
01170         ModelExec(mWGclus960sp[2], "");
01171     }
01172 
01173     void
01174     ModelOldWG()
01175     {
01176         ModelExec(mWG[0], "${IMPALAROOT}/src/script/train.ini");
01177         ModelExec(mWG[1], "${IMPALAROOT}/src/script/train.ini");
01178         if (mSkipFusion.empty())
01179             ModelExec(mWG[2], "${IMPALAROOT}/src/script/train.ini");
01180     }
01181 
01182     void
01183     ModelOldWGclus960sp()
01184     {
01185         ModelExec(mWGclus960sp[0], "${IMPALAROOT}/src/script/train.ini");
01186         ModelExec(mWGclus960sp[1], "${IMPALAROOT}/src/script/train.ini");
01187         if (mSkipFusion.empty())
01188             ModelExec(mWGclus960sp[2], "${IMPALAROOT}/src/script/train.ini");
01189     }
01190 
01191     void
01192     ModelPreAllSift()
01193     {
01194         for (int i=0 ; i<mAllSift.size() ; i++)
01195             ModelExec(mAllSift[i], "");
01196     }
01197 
01198     void
01199     ModelPreAllSurf()
01200     {
01201         for (int i=0 ; i<mAllSurf.size() ; i++)
01202             ModelExec(mAllSurf[i], "");
01203     }
01204 
01205     void
01206     ModelExec(CString kernel, String ini)
01207     {
01208         if (mConcepts.empty())
01209         {
01210             ILOG_ERROR("ModelExec: need concepts");
01211             return;
01212         }
01213         if (mModel.empty())
01214         {
01215             ILOG_ERROR("ModelExec: need model");
01216             return;
01217         }
01218 
01219         // the old non-precomputed version is just another ini file:
01220         // new=precompute.ini and old=train.ini
01221         if (ini.empty())
01222         {
01223             ini = "${IMPALAROOT}/src/script/precompute.ini";
01224         }
01225         String cat("");
01226         if (! mFeatureIndexCat.empty())
01227             cat = "--featureIndexCat " + mFeatureIndexCat;
01228 
01229         Exec("crossvalidate", mSetName + " " + mConcepts + " " + mModel + " " +
01230              kernel + " --ini " + ini + " " + mEpisodeConstrained + " " + cat);
01231         Exec("trainmodel", mSetName + " " + mConcepts + " " + mModel + " " +
01232              kernel + " --ini " + ini + " " + cat);
01233         if (mFik)
01234         {
01235             Exec("conceptset", "approxfikmodel " + mSetName + " " + mConcepts +
01236                  " " + mModel + " " + kernel + " " + MakeString(mModelBins) +
01237                  " " + cat);
01238         }
01239     }
01240 
01241     void
01242     ClassifyPreWG()
01243     {
01244         ClassifyExec(mWG[0], true);
01245         ClassifyExec(mWG[1], true);
01246         ClassifyExec(mWG[2], true);
01247         ClassifyCombineExec(mWG[0] + " " + mWG[1] + " " + mWG[2], "combined");
01248     }
01249 
01250     void
01251     ClassifyPreWGclus960sp()
01252     {
01253         ClassifyExec(mWGclus960sp[0], true);
01254         ClassifyExec(mWGclus960sp[1], true);
01255         ClassifyExec(mWGclus960sp[2], true);
01256         ClassifyCombineExec(mWGclus960sp[0] + " " + mWGclus960sp[1] + " " +
01257                             mWGclus960sp[2], "combinedClus960sp");
01258     }
01259 
01260     void
01261     ClassifyPreAllSift()
01262     {
01263         for (int i=0 ; i<mAllSift.size() ; i++)
01264             ClassifyExec(mAllSift[i], true);
01265     }
01266 
01267     void
01268     ClassifyPreAllSurf()
01269     {
01270         for (int i=0 ; i<mAllSurf.size() ; i++)
01271             ClassifyExec(mAllSurf[i], true);
01272     }
01273 
01274     void
01275     ClassifyOldWG()
01276     {
01277         ClassifyExec(mWG[0], false);
01278         ClassifyExec(mWG[1], false);
01279         if (mSkipFusion.empty())
01280         {
01281             ClassifyExec(mWG[2], false);
01282             ClassifyCombineExec(mWG[0] + " " + mWG[1] + " " + mWG[2],
01283                                 "combined");
01284         }
01285         else
01286         {
01287             ClassifyCombineExec(mWG[0] + " " + mWG[1], "combined");
01288         }
01289     }
01290 
01291     void
01292     ClassifyOldWGclus960sp()
01293     {
01294         ClassifyExec(mWGclus960sp[0], false);
01295         ClassifyExec(mWGclus960sp[1], false);
01296         ClassifyExec(mWGclus960sp[2], false);
01297         ClassifyCombineExec(mWGclus960sp[0] + " " + mWGclus960sp[1] + " " +
01298                             mWGclus960sp[2], "combined960sp");
01299     }
01300 
01301     void
01302     ClassifyExec(CString feature, bool precomputed)
01303     {
01304         if (mAnnoSet.empty())
01305         {
01306             ILOG_ERROR("ClassifyExec: need annoset");
01307             return;
01308         }
01309         if (mConcepts.empty())
01310         {
01311             ILOG_ERROR("ClassifyExec: need concepts");
01312             return;
01313         }
01314         if (mModel.empty())
01315         {
01316             ILOG_ERROR("ClassifyExec: need model");
01317             return;
01318         }
01319 
01320         String prog = GetWalkerProg();
01321         String frameWalk = GetFrameWalk();
01322         String precompute = (precomputed) ? "--precomputed 1" : "";
01323         String fik = (mFik) ? "--fik 1"  : "";
01324         String fiCat("");
01325         if (! mFeatureIndexCat.empty())
01326             fiCat = "--featureIndexCat " + mFeatureIndexCat;
01327         String ciCat("");
01328         if (! mClassifyIndexCat.empty())
01329             ciCat = "--classifyIndexCat " + mClassifyIndexCat;
01330 
01331         if (mComputeKernelData)
01332         {
01333             Exec(prog, "computekerneldata " + mSetName + " " + mAnnoSet + " " + 
01334                  mModel + " " + feature + " " + frameWalk +
01335                  " --virtualWalk --tmpPath " + mImpalaTmp + " " + fiCat);
01336             if (mKernelDataOnly.empty())
01337             {
01338                 Exec(prog, "applyconcepts " + mSetName + " " + mAnnoSet + " " + 
01339                      mConcepts + " " + mModel + " " + feature + " " +
01340                      precompute + " " + frameWalk + " --virtualWalk --tmpPath "
01341                      + mImpalaTmp);
01342             }
01343         }
01344         else
01345         {
01346             if (ciCat.empty())
01347             {
01348                 Exec(prog, "applyconcepts " + mSetName + " " + mAnnoSet +
01349                      " " + mConcepts + " " + mModel + " " + feature + " " +
01350                      precompute + " " + frameWalk + " --virtualWalk --tmpPath "
01351                      + mImpalaTmp + " " + mStoreKernelData + " "
01352                      + mKernelDataOnly + " " + fiCat + " " + fik);
01353             }
01354             else
01355             {
01356                 Exec(prog, "applyconceptsindex " + mSetName + " " + mAnnoSet +
01357                      " " + mConcepts + " " + mModel + " " + feature + " " +
01358                      precompute + " " + frameWalk + " --virtualWalk --tmpPath "
01359                      + mImpalaTmp + " " + mStoreKernelData + " "
01360                      + mKernelDataOnly + " " + ciCat + " " + fik);
01361             }
01362         }
01363         if (mDoClassifyIndex && mKernelDataOnly.empty() && ciCat.empty())
01364         {
01365             Exec(prog, "indexconcepts " + mSetName + " " + mConcepts + " " +
01366                  mModel + " " + feature + " " + frameWalk + " --virtualWalk", 1);
01367         }
01368     }
01369 
01370     void
01371     ClassifyCombineExec(CString features, CString featureC)
01372     {
01373         // Assume ClassifyCombine has been called and args are checked.
01374         String prog = GetWalkerProg();
01375         String frameWalk = GetFrameWalk();
01376 
01377         Exec(prog, "combineconcepts " + mSetName + " " + mConcepts + " " +
01378              mModel + " " + featureC + " avg " + features + " " + frameWalk +
01379              " --virtualWalk");
01380         if (mDoClassifyIndex)
01381         {
01382             Exec(prog, "indexconcepts " + mSetName + " " + mConcepts + " " +
01383                  mModel + " " + featureC + " " + frameWalk + " --virtualWalk",
01384                  1);
01385         }
01386     }
01387 
01388     void
01389     ExportConceptsExec(CString feature)
01390     {
01391         if (mConcepts.empty())
01392         {
01393             ILOG_ERROR("ExportConceptsExec: need concepts");
01394             return;
01395         }
01396         if (mModel.empty())
01397         {
01398             ILOG_ERROR("ExportConceptsExec: need model");
01399             return;
01400         }
01401 
01402         String prog = GetWalkerProg();
01403         String frameWalk =
01404             "--src lavc --keyframes --numberKeyframes 1 --segmentation";
01405         Exec(prog, "exportconcepts " + mSetName + " 0 " + mConcepts + " " +
01406              mModel + " " + feature + " " + frameWalk);
01407     }
01408 
01409     void
01410     ImportConceptsExec(CString feature)
01411     {
01412         if (mConcepts.empty())
01413         {
01414             ILOG_ERROR("ImportConceptsExec: need concepts");
01415             return;
01416         }
01417         if (mModel.empty())
01418         {
01419             ILOG_ERROR("ImportConceptsExec: need model");
01420             return;
01421         }
01422 
01423         String prog = GetWalkerProg();
01424         String frameWalk("--virtualWalk");
01425         Exec(prog, "importconcepts " + mSetName + " " + mConcepts + " " +
01426              mModel + " " + feature + " " + frameWalk);
01427     }
01428 
01429     void
01430     MapWG()
01431     {
01432         MapExec(mWG[0], false);
01433         MapExec(mWG[1], false);
01434         if (mSkipFusion.empty())
01435             MapExec(mWG[2], false);
01436         MapExec("combined", false);
01437     }
01438 
01439     void
01440     MapWGclus960sp()
01441     {
01442         MapExec(mWGclus960sp[0], false);
01443         MapExec(mWGclus960sp[1], false);
01444         MapExec(mWGclus960sp[2], false);
01445         MapExec("combined960sp", false);
01446     }
01447 
01448     void
01449     MapPreWGclus960sp()
01450     {
01451         MapExec(mWGclus960sp[0], false);
01452         MapExec(mWGclus960sp[1], false);
01453         MapExec(mWGclus960sp[2], false);
01454         MapExec("combinedClus960sp", false);
01455     }
01456 
01457     void
01458     MapPreAllSift()
01459     {
01460         for (int i=0 ; i<mAllSift.size() ; i++)
01461             MapExec(mAllSift[i], false);
01462     }
01463 
01464     void
01465     MapPreAllSurf()
01466     {
01467         for (int i=0 ; i<mAllSurf.size() ; i++)
01468             MapExec(mAllSurf[i], false);
01469     }
01470 
01471     void
01472     MapExec(CString feature, bool doParam)
01473     {
01474         if (mConcepts.empty())
01475         {
01476             ILOG_ERROR("MapExec: need concepts");
01477             return;
01478         }
01479         if (mModel.empty())
01480         {
01481             ILOG_ERROR("MapExec: need model");
01482             return;
01483         }
01484 
01485         static bool first = true;
01486         if (first)
01487         {
01488             CallSystem("echo \"\" > map.txt");
01489             first = false;
01490         }
01491         if (doParam)
01492         {
01493             Exec2("util dumpparameter " + mSetName + " " + mConcepts + " " +
01494                   mModel + " " + feature, " >> map.txt");
01495         }
01496         Exec2("util scoreconcepts " + mSetName + " " + mConcepts + " " +
01497               mModel + " " + feature + " " + mAnnotations, " >> map.txt");
01498     }
01499 
01500     void
01501     IExec(CString cmdLine)
01502     {
01503         ILOG_INFO("IExec " << cmdLine);
01504         String line = StringTail(cmdLine, ' ', false);
01505         String ncpuStr = StringHead(line, ' ', false);
01506         int ncpu = (ncpuStr == "${NCPU}") ? mNCPU : atol(ncpuStr);
01507         line = StringTail(line, ' ', false);
01508         String prog = StringHead(line, ' ', false);
01509         line = StringTail(line, ' ', false);
01510 
01511         line = ResolveExports(line);
01512         if (!line.empty())
01513             Exec(prog, line, ncpu);
01514     }
01515 
01516     void
01517     DoRepositoryExec(CString cmdLine)
01518     {
01519         ILOG_INFO("DoRepositoryExec " << cmdLine);
01520         String line = StringTail(cmdLine, ' ', false);
01521         String cmd = StringHead(line, ' ', false);
01522         String args = StringTail(line, ' ', false);
01523 
01524         args = ResolveExports(args);
01525         if (!args.empty())
01526             RepositoryExec(cmd, args);
01527     }
01528 
01529     String
01530     GetMpiCallString(CString prog, int ncpu)
01531     {
01532         if (ncpu == 0)
01533             ncpu = mNCPU;
01534 
01535         String progMpi = prog + "mpi";
01536         if (FileExists("/home/koelma/sge/prun-sge-script"))
01537         {   // we're on DAS3 or DAS4
01538             String prun = "prun -v";
01539             prun += " -sge-script /home/koelma/sge/prun-sge-script";
01540             prun += " -asocial -t 168:00:00";
01541             if (!FileExists("/home/koelma/sge/prun-sge-script.das4"))
01542             {   // DAS3
01543                 return prun + " " + progMpi + " " + MakeString(ncpu);
01544             }
01545             if ((mNodes != -1) && (mPPN != -1))
01546             {
01547                 return prun + " -" + MakeString(mPPN) + " -np "
01548                     + MakeString(mNodes) + " " + progMpi;
01549             }
01550             if ((mPPN == -1) && StringStartsWith(prog, "precompute"))
01551             {
01552                 int root = sqrt((double) ncpu);
01553                 return prun + " -" + MakeString(root) + " -np "
01554                     + MakeString(root) + " " + progMpi;
01555             }
01556             int ppn = (mPPN == -1) ? 8 : mPPN;
01557             if (ppn > ncpu)
01558                 ppn = ncpu;
01559             int nodes = (ncpu % ppn == 0) ? ncpu / ppn : (ncpu / ppn) + 1;
01560             return prun + " -" + MakeString(ppn) + " -np "
01561                 + MakeString(nodes) + " " + progMpi;
01562         }
01563 
01564 #ifdef WIN32
01565         return "mpiexec -localonly " + MakeString(ncpu) + " " + progMpi;
01566 #endif
01567 
01568         // fails when called twice?
01569         // "mpiexec -machinefile machines.txt -n " + MakeString(ncpu);
01570         // requires lamboot to be called first
01571         return "mpiexec -n " + MakeString(ncpu) + " " + progMpi;
01572     }
01573 
01574     void
01575     Exec(CString prog, CString arguments, int ncpu = 0)
01576     {
01577         String args = StringResolveEnv(arguments);
01578         String extraArgs = GetExtraArguments();
01579 
01580         String prefix = prog;
01581         if (mUseMpi)
01582         {
01583             prefix = GetMpiCallString(prog, ncpu);
01584         }
01585         String cmdLine = prefix + " " + args + " " + extraArgs;
01586         if (mDryRun)
01587         {
01588             std::cout << cmdLine << std::endl;
01589         }
01590         else
01591         {
01592             ILOG_INFO("Exec: " << cmdLine);
01593             CallSystem(cmdLine);
01594         }
01595     }
01596 
01597     void
01598     Exec2(CString cmdLine, CString reDirect)
01599     {
01600         String line = StringResolveEnv(cmdLine);
01601 
01602                 line += GetExtraArguments();
01603         line += reDirect;
01604 
01605         if (mUseMpi)
01606         {
01607             line =
01608                 "qrsh -now n -l h_rt=168:00:00 -cwd -noshell /bin/bash -l -c \""
01609                 + line + "\"";
01610         }
01611         if (mDryRun)
01612         {
01613             std::cout << line << std::endl;
01614         }
01615         else
01616         {
01617             ILOG_INFO("Exec2: " << line);
01618             CallSystem(line);
01619         }
01620     }
01621 
01622     void
01623     RepositoryExec(CString cmd, CString arguments)
01624     {
01625         String args = ResolveExports(arguments);
01626         String line = "repository " + cmd + " " + mLocation + " " + mSetName
01627             + " " + args;
01628         if (mUseMpi)
01629         {
01630             line =
01631                 "qrsh -now n -l h_rt=168:00:00 -cwd -noshell /bin/bash -l -c \""
01632                 + line + "\"";
01633         }
01634         if (mDryRun)
01635         {
01636             std::cout << line << std::endl;
01637         }
01638         else
01639         {
01640             ILOG_INFO("RepositoryExec: " << line);
01641             CallSystem(line);
01642         }
01643     }
01644 
01645     void
01646     DoSystem(CString cmdLine)
01647     {
01648         ILOG_INFO("DoSystem " << cmdLine);
01649         String line = StringTail(cmdLine, ' ', false);
01650         line = ResolveExports(line);
01651         if (line.empty())
01652             return;
01653         if (mDryRun)
01654             std::cout << line << std::endl;
01655         else
01656             CallSystem(line);
01657     }
01658 
01659     // Check part
01660 
01661     void
01662     CheckPrepIm()
01663     {
01664         CheckCall("diffimagearchive", "false ALL images.raw");
01665     }
01666 
01667     void
01668     CheckVideoAccess()
01669     {
01670         CheckCall("diffframehashes", "");
01671         if (mDoShotIndex)
01672             CheckCall("diffsegmentation", "");
01673         else
01674             CheckCall("diffmpeg7shot", "ALL");
01675     }
01676 
01677     void
01678     CheckPrepTest()
01679     {
01680         if (mDoShotIndex)
01681             CheckCall("diffsegmentation", "");
01682         else
01683             CheckCall("diffmpeg7shot", "ALL");
01684         CheckCall("diffkeyframes", "");
01685         CheckCall("diffstills", "");
01686         CheckCall("diffquidtable", "VideoIndex keysExtra2.tab");
01687         CheckCall("diffimagesetspecial", "keyframes.txt");
01688         CheckCall("diffimagesetspecial", "thumbnails.txt");
01689         CheckCall("diffimagesetspecial", "stills.txt");
01690         CheckCall("diffimagearchive", "true ALL images.raw");
01691         CheckCall("diffimagearchive", "true ALL images_jpg.raw");
01692         CheckCall("diffimagearchivespecial", "thumbnails.txt . thumbnails.raw");
01693         CheckCall("diffimagearchivespecial", "keyframes.txt ALL images.raw");
01694         CheckCall("diffimagearchivespecial", "stills.txt ALL images.raw");
01695     }
01696 
01697     void
01698     CheckPrepTry()
01699     {
01700         CheckCall("diffvideoset", "");
01701         CheckCall("diffsegmentation", "");
01702         CheckCall("diffkeyframes", "");
01703         CheckCall("diffimagesetspecial", "keyframes.txt");
01704         CheckCall("diffimagesetspecial", "thumbnails.txt");
01705         CheckCall("diffimagesetspecial", "stills.txt");
01706         CheckCall("diffimagearchive", "true ALL images.raw");
01707     }
01708 
01709     void
01710     CheckMpeg7()
01711     {
01712         CheckCall("diffmpeg7shot", "ALL");
01713         CheckCall("diffannotationtable", "Frame concepts.txt anchor");
01714         CheckCall("diffannotationtable", "Frame concepts.txt desert");
01715         CheckCall("diffannotationtable", "Shot concepts.txt anchor");
01716         CheckCall("diffannotationtable", "Shot concepts.txt desert");
01717     }
01718 
01719     void
01720     CheckMergedAnnotations()
01721     {
01722         if (mConcepts.empty())
01723         {
01724             ILOG_ERROR("CheckMergedAnnotations: need concepts");
01725             return;
01726         }
01727         CheckCall("diffannotationtableset", GetQuidClass() + " " + mConcepts);
01728     }
01729 
01730     void
01731     CheckSm2VissemKeyfr()
01732     {
01733         String f("vissem_proto_sm2_nrScales_2_nrRects_130");
01734         CheckCall("difffeaturetable", "false true . " + f + " .");
01735     }
01736 
01737     void
01738     CheckSm2VissemGaborKeyfr()
01739     {
01740         String f("vissemgabor_proto_sm2_nrScales_2_nrRects_130");
01741         CheckCall("difffeaturetable", "false true . " + f + " .");
01742     }
01743 
01744     void
01745     CheckClusVissem()
01746     {
01747         String f("vissem_proto_clusters_keyframes_desert_maxlen_32");
01748         CheckCall("difffeaturetable", "false true . " + f + " .");
01749     }
01750 
01751     void
01752     CheckClusVissemGabor()
01753     {
01754         std::vector<String> f;
01755         f.push_back("vissemgabor_proto_clusters_keyframes_desert_radius_4.4");
01756         f.push_back("vissemgabor_proto_clusters_keyframes_desert_radius_5.2");
01757         f.push_back("vissemgabor_proto_clusters_keyframes_desert_radius_6");
01758         for (int i=0 ; i<f.size() ; i++)
01759             CheckCall("difffeaturetable", "false true . " + f[i] + " .");
01760     }
01761 
01762     void
01763     CheckClusterSift()
01764     {
01765         CheckFeature("densesampling-sift_ds_6-1.2-2_clusterinput_2");
01766         CheckFeature("harrislaplace-sift_clusterinput_2");
01767         CheckCall("difffeaturetable", "true false . densesampling2-sift .");
01768         CheckCall("difffeaturetable", "true false . harrislaplace-sift .");
01769     }
01770 
01771     void
01772     CheckClusterSurf()
01773     {
01774         CheckFeature("none-surf_sc_3-2-4_clusterinput_2");
01775         CheckCall("difffeaturetable", "true false . none-surf .");
01776     }
01777 
01778     void
01779     CheckMakeforestAllSurf()
01780     {
01781         CheckCall("difffeaturetable", "true false . none-surf .");
01782         CheckCall("difffeaturetable", "true false . none-opponentsurf .");
01783         CheckCall("difffeaturetable", "true false . none-rgbsurf .");
01784     }
01785 
01786     void
01787     CheckFeature3Sift()
01788     {
01789         CheckFeaturePyramid3("sift", false);
01790         CheckFeaturePyramid3("opponentsift", false);
01791         CheckFeaturePyramid3("rgbsift", false);
01792     }
01793 
01794     void
01795     CheckFeatureAllSift()
01796     {
01797         CheckFeaturePyramid3("sift", true);
01798         CheckFeaturePyramid3("opponentsift", true);
01799         CheckFeaturePyramid3("rgbsift", false);
01800         CheckFeaturePyramid3("rgsift", false);
01801         CheckFeaturePyramid3("csift", false);
01802     }
01803 
01804     void
01805     CheckFeatureUnc4Sift()
01806     {
01807         CheckFeaturePyramidHarris("sift", "cm_unc_cs_75");
01808         CheckFeaturePyramidDense2("sift", "cm_unc_cs_50");
01809         CheckFeaturePyramidHarris("opponentsift", "cm_unc_cs_120");
01810         CheckFeaturePyramidDense2("opponentsift", "cm_unc_cs_80");
01811         CheckFeaturePyramidHarris("rgbsift", "cm_unc_cs_120");
01812         CheckFeaturePyramidDense2("rgbsift", "cm_unc_cs_80");
01813         CheckFeaturePyramidHarris("csift", "cm_unc_cs_120");
01814         CheckFeaturePyramidDense2("csift", "cm_unc_cs_80");
01815     }
01816 
01817     void
01818     CheckFeaturePyramid3(CString feature, bool doDense)
01819     {
01820         if (doDense)
01821             CheckFeaturePyramidDense(feature, "");
01822         CheckFeaturePyramidHarris(feature, "");
01823         CheckFeaturePyramidDense2(feature, "");
01824     }
01825 
01826     void
01827     CheckFeaturePyramidHarris(CString feature, CString cMode)
01828     {
01829         String cbMode = (cMode.empty()) ? "" : "_" + cMode;
01830         for (int i=0 ; i<8 ; i++)
01831         {
01832             String sub = (i == 0) ? "" : "_sub_" + MakeString(i);
01833             CheckFeature("harrislaplace-" + feature +
01834                          "_ps_pyramid-1x1-2x2-1x3" + cbMode + sub);
01835         }
01836     }
01837 
01838     void
01839     CheckFeaturePyramidDense(CString feature, CString cMode)
01840     {
01841         String cbMode = (cMode.empty()) ? "" : "_" + cMode;
01842         for (int i=0 ; i<8 ; i++)
01843         {
01844             String sub = (i == 0) ? "" : "_sub_" + MakeString(i);
01845             CheckFeature("densesampling-" + feature +
01846                          "_ds_6-1.2_ps_pyramid-1x1-2x2-1x3" + cbMode + sub);
01847         }
01848     }
01849 
01850     void
01851     CheckFeaturePyramidDense2(CString feature, CString cMode)
01852     {
01853         String cbMode = (cMode.empty()) ? "" : "_" + cMode;
01854         for (int i=0 ; i<8 ; i++)
01855         {
01856             String sub = (i == 0) ? "" : "_sub_" + MakeString(i);
01857             CheckFeature("densesampling-" + feature +
01858                          "_ds_6-1.2-2_ps_pyramid-1x1-2x2-1x3" + cbMode + sub);
01859         }
01860     }
01861 
01862     void
01863     CheckFeatureAllSurf()
01864     {
01865         CheckFeaturePyramidNone("surf", "");
01866         CheckFeaturePyramidNone("opponentsurf", "");
01867         CheckFeaturePyramidNone("rgbsurf", "");
01868     }
01869 
01870     void
01871     CheckFeatureForestAllSurf()
01872     {
01873         CheckFeaturePyramidNone("surf", "cm_forest");
01874         CheckFeaturePyramidNone("opponentsurf", "cm_forest");
01875         CheckFeaturePyramidNone("rgbsurf", "cm_forest");
01876     }
01877 
01878     void
01879     CheckFeaturePyramidNone(CString feature, CString cMode)
01880     {
01881         String cbMode = (cMode.empty()) ? "" : "_" + cMode;
01882         for (int i=0 ; i<8 ; i++)
01883         {
01884             String sub = (i == 0) ? "" : "_sub_" + MakeString(i);
01885             CheckFeature("none-" + feature +
01886                          "_sc_3-2-4_ps_pyramid-1x1-2x2-1x3" + cbMode + sub);
01887         }
01888     }
01889 
01890     void
01891     CheckFeature(CString feature)
01892     {
01893         String dir = GetWalkerDir();
01894         ILOG_INFO("Checking feature " << feature << " in " << dir);
01895         String args = "false false " + dir + " " + feature + " ALL";
01896         CheckCall("difffeaturetable", args);
01897     }
01898 
01899     void
01900     CheckPrecomputeWG()
01901     {
01902         CheckPrecompute(mWG[0]);
01903         CheckPrecompute(mWG[1]);
01904         CheckPrecompute(mWG[2]);
01905     }
01906 
01907     void
01908     CheckPrecompute(CString featureDef)
01909     {
01910         ILOG_INFO("Checking precompute " << mModel << " " << featureDef);
01911         String args = "true nil nil " + mModel + " " + featureDef + " dummy";
01912         CheckCall("diffkernelmatrix", args);
01913         if (mAnnoSetTest.empty())
01914             return;
01915         args = "true nil " + mAnnoSetTest + " " + mModel + " " + featureDef
01916             + " dummy";
01917         CheckCall("diffkernelmatrix", args);
01918     }
01919 
01920     void
01921     CheckModelWG()
01922     {
01923         CheckModel(mWG[0]);
01924         CheckModel(mWG[1]);
01925         if (mSkipFusion.empty())
01926             CheckModel(mWG[2]);
01927     }
01928 
01929     void
01930     CheckModelWGclus960sp()
01931     {
01932         CheckModel(mWGclus960sp[0]);
01933         CheckModel(mWGclus960sp[1]);
01934         if (mSkipFusion.empty())
01935             CheckModel(mWGclus960sp[2]);
01936     }
01937 
01938     void
01939     CheckModelAllSift()
01940     {
01941         for (int i=0 ; i<mAllSift.size() ; i++)
01942             CheckModel(mAllSift[i]);
01943     }
01944 
01945     void
01946     CheckModel(CString feature)
01947     {
01948         ILOG_INFO("Checking model " << mConcepts << " " << mModel << " " <<
01949                   feature);
01950         String args = mConcepts + " " + mModel + " " + feature + " ALL";
01951         CheckCall("diffbestfile", args);
01952         CheckCall("diffallparameterfile", args);
01953         CheckCall("diffscorefile", args);
01954         CheckCall("diffmodel", args);
01955         if (mFik)
01956         {
01957             String fikModel = mModel + "-approx-" + MakeString(mModelBins);
01958             args = mConcepts + " " + fikModel + " " + feature + " ALL";
01959             CheckCall("difffiksvm", args);
01960         }
01961     }
01962 
01963     void
01964     CheckClassifyPreWG()
01965     {
01966         if (mComputeKernelData || (!mStoreKernelData.empty()))
01967         {
01968             CheckKernelData(mWG[0]);
01969             CheckKernelData(mWG[1]);
01970             CheckKernelData(mWG[2]);
01971         }
01972         if (mKernelDataOnly.empty())
01973             CheckSimilarities("combined");
01974     }
01975 
01976     void
01977     CheckClassifyPreBoth2SiftP112213()
01978     {
01979         if (mComputeKernelData || (!mStoreKernelData.empty()))
01980             CheckKernelData("both2-sift-p112213");
01981         if (mKernelDataOnly.empty())
01982             CheckSimilarities("both2-sift-p112213");
01983     }
01984 
01985     void
01986     CheckClassifyPreAllSift()
01987     {
01988         for (int i=0 ; i<mAllSift.size() ; i++)
01989             CheckSimilarities(mAllSift[i]);
01990     }
01991 
01992     void
01993     CheckClassifyPreSurfP112213()
01994     {
01995         if (mComputeKernelData || (!mStoreKernelData.empty()))
01996             CheckKernelData("none-surf-p112213");
01997         if (mKernelDataOnly.empty())
01998             CheckSimilarities("none-surf-p112213");
01999     }
02000 
02001     void
02002     CheckKernelData(CString featureDef)
02003     {
02004         ILOG_INFO("Checking kerneldata " << mModel << " " << featureDef);
02005         String dir = GetWalkerDir();
02006         if (dir == ".")
02007             dir = "Image";
02008         CheckCall("diffkernelmatrix", "false " + dir + " " + mAnnoSet + " "
02009                   + mModel + " " + featureDef + " ALL");
02010     }
02011 
02012     void
02013     CheckSimilarities(CString feature)
02014     {
02015         if (mModel.empty())
02016         {
02017             ILOG_ERROR("CheckSimilarities: need model");
02018             return;
02019         }
02020         ILOG_INFO("Checking similarities " << mModel << " " << feature);
02021         String args;
02022         if (mImageSet)
02023             args = "true dummy ";
02024         else if (mFrames)
02025             args = "false Frames ";
02026         else
02027             args = "true Keyframes ";
02028         args += mConcepts + " " + mModel + " ";
02029         if (! mQuidFile.empty())
02030             args += FileNameBase(mQuidFile) + "-";
02031         args += feature;
02032         if (mImageSet || mFrames)
02033             args += " ALL";
02034         else
02035             args += " .";
02036         CheckCall("diffsimilaritytableset", args);
02037     }
02038 
02039     void
02040     CheckCall(CString cmd, CString args)
02041     {
02042         String cmdLine = "repository " + cmd + " dataServer:" + mRefServer +
02043             " " + mSetName + " " + args + " " + mLocation;
02044 
02045         if (cmd == "diffmpeg7shot")
02046         {
02047             // SK, 7.1.11 Hack op ad-VIES van Dennis
02048             cmdLine += " --dataServer " + mRefServer;
02049             cmdLine += " --src lavc";
02050         }
02051 
02052         ILOG_INFO("Check: " << cmdLine);
02053         if (mDryRun)
02054             std::cout << cmdLine << std::endl;
02055         else
02056             CallSystem(cmdLine);
02057     }
02058 
02059     // Stage part
02060 
02061     void
02062     Stage()
02063     {
02064         if (GetCurCmdNrArgs() < 2)
02065         {
02066             ILOG_ERROR("[Stage] Need at least 2 arguments");
02067             return;
02068         }
02069         String cmd = GetCurCmdArg(0);
02070         String args = GetCurCmdArg(1);
02071         for (int i=2 ; i<GetCurCmdNrArgs() ; i++)
02072             args += " " + GetCurCmdArg(i);
02073         StageCall(cmd, args);
02074     }
02075 
02076     void
02077     StageImages()
02078     {
02079         ILOG_INFO("Staging images");
02080         String dataSet = GetCurCmdArg(0);
02081         StageCall("copyimageset", dataSet);
02082         StageCall("syncimagefiles", dataSet);
02083     }
02084 
02085     
02086     
02087     
02088     void
02089     StageVideos()
02090     {
02091         String dataSet = GetCurCmdArg(0);
02092         String doInfo = GetCurCmdArg(1);
02093         String logMsg("Staging video set definition and videos ");
02094         if (doInfo == "true")
02095             logMsg += "and video info ";
02096         ILOG_INFO(logMsg);
02097         bool fromOutput = false;
02098         if (GetCurCmdNrArgs() > 2)
02099             fromOutput = (GetCurCmdArg(2) == "true");
02100         StageCall("copyvideoset", dataSet);
02101         if (fromOutput)
02102         {
02103             ILOG_INFO("Staging videos from reference (output) ");
02104             StageCall("syncvideofiles", dataSet + " " + doInfo, mRefServer);
02105         }
02106         else
02107             StageCall("syncvideofiles", dataSet + " " + doInfo);
02108     }
02109 
02110     
02111     
02112     void
02113     StagePrepTry()
02114     {
02115         ILOG_INFO("Staging preptry");
02116         StageCall("copyvideoset", "trec2005fsd_try.txt");
02117         StageCall("syncvideofiles", "trec2005fsd_try.txt false");
02118         StageCall("syncfile", "trec2005fsd_try.txt input/141.mp7.xml");
02119         StageCall("syncfile", "trec2005fsd_try.txt input/142.mp7.xml");
02120         StageCall("syncfile", "trec2005fsd_try.txt input/145.mp7.xml");
02121         StageCall("syncfile", "trec2005fsd_try.txt input/collection.xml");
02122     }
02123 
02124     void
02125     StagePrepTryOutput()
02126     {
02127         ILOG_INFO("Staging preptryoutput");
02128         StageCall("syncvideofiles", "trec2005fsd_try.txt true");
02129         StageCall("copysegmentation", "trec2005fsd_try.txt", mRefServer);
02130         StageCall("copykeyframes", "trec2005fsd_try.txt", mRefServer);
02131         StageCall("copyimagearchive", "trec2005fsd_try.txt true ALL images.raw",
02132                   mRefServer);
02133     }
02134 
02135     void
02136     StageFeatureWGOutput()
02137     {
02138         ILOG_INFO("Staging featurewgoutput");
02139         for (int i=0 ; i<mWG.size() ; i++)
02140         {
02141             StageCall("copyfeaturetable",
02142                       "trec2005fsd_try.txt false false Keyframes " + mWG[i] +
02143                       " ALL", mRefServer);
02144         }
02145     }
02146 
02147     void
02148     StageFeatureSiftOutput()
02149     {
02150         ILOG_INFO("Staging featuresiftoutput");
02151         for (int i=0 ; i<8 ; i++)
02152         {
02153             String sub = (i == 0) ? "" : "_sub_" + MakeString(i);
02154             String f = "harrislaplace-sift_ps_pyramid-1x1-2x2-1x3" + sub;
02155             StageCall("copyfeaturetable",
02156                       "trec2005fsd_try.txt false false Keyframes " + f + " ALL",
02157                       mRefServer);
02158             f = "densesampling-sift_ds_6-1.2-2_ps_pyramid-1x1-2x2-1x3" + sub;
02159             StageCall("copyfeaturetable",
02160                       "trec2005fsd_try.txt false false Keyframes " + f + " ALL",
02161                       mRefServer);
02162         }
02163     }
02164 
02165     void
02166     StageVocMini()
02167     {
02168         ILOG_INFO("Staging vocmini");
02169         StageCall("copyimageset", "voc2007mini.txt");
02170         StageCall("copyimagearchive", "voc2007mini.txt false ALL images.raw");
02171         StageCall("copyannotationtableset",
02172                   "voc2007mini.txt Image conceptsVOC2007.txt");
02173         StageCall("copyannotationtableset",
02174                   "voc2007mini.txt Image conceptsTest.txt");
02175     }
02176 
02177     void
02178     StageCall(CString cmd, CString args, CString dataServer = "")
02179     {
02180         String server = mInputServer;
02181         if (!dataServer.empty())
02182             server = dataServer;
02183         String cmdLine = "repository " + cmd + " dataServer:" + server +
02184             " " + args + " " + mLocation + " --sync";
02185         ILOG_INFO("Stage: " << cmdLine);
02186         if (mDryRun)
02187             std::cout << cmdLine << std::endl;
02188         else
02189             CallSystem(cmdLine);
02190     }
02191 
02192     // Clean part
02193 
02194     void
02195     CleanPrepIm()
02196     {
02197         ILOG_INFO("Cleaning prepim");
02198         CleanCall("deleteimagearchive", "false ALL images.raw");
02199     }
02200 
02201     void
02202     CleanPrepTest()
02203     {
02204         ILOG_INFO("Cleaning preptest");
02205         CleanCall("deletevideoinfofiles", "");
02206         CleanCall("deletempeg7shot", "ALL");
02207         CleanCall("deletesimilaritytableset", "false Frames ALL ALL ALL ALL");
02208         CleanCall("deletesegmentation", "");
02209         CleanCall("deletekeyframes", "");
02210         CleanCall("deletestills", "");
02211         CleanCall("deletequidtable", "VideoIndex keysExtra2.tab");
02212         CleanCall("deleteimagearchivespecial",
02213                   "thumbnails.txt . thumbnails.raw");
02214         CleanCall("deleteimagearchivespecial", "keyframes.txt ALL images.raw");
02215         CleanCall("deleteimagearchivespecial", "stills.txt ALL images.raw");
02216         CleanCall("deleteimagearchive", "true ALL images.raw");
02217         CleanCall("deleteimagearchive", "true ALL images_jpg.raw");
02218         CleanCall("deleteimagesetspecial", "keyframes.txt");
02219         CleanCall("deleteimagesetspecial", "thumbnails.txt");
02220         CleanCall("deleteimagesetspecial", "stills.txt");
02221     }
02222 
02223     void
02224     CleanPrepTry()
02225     {
02226         ILOG_INFO("Cleaning preptry");
02227         CleanCall("deletevideoinfofiles", "");
02228         CleanCall("deletesimilaritytableset", "false Frames ALL ALL ALL ALL");
02229         CleanCall("deletesegmentation", "");
02230         CleanCall("deletekeyframes", "");
02231         CleanCall("deletestills", "");
02232         CleanCall("deleteimagearchivespecial",
02233                   "thumbnails.txt . thumbnails.raw");
02234         CleanCall("deleteimagearchivespecial", "keyframes.txt ALL images.raw");
02235         CleanCall("deleteimagearchive", "true ALL images.raw");
02236         CleanCall("deleteimagesetspecial", "keyframes.txt");
02237         CleanCall("deleteimagesetspecial", "thumbnails.txt");
02238         CleanCall("deleteimagesetspecial", "stills.txt");
02239         CleanCall("deletevideoset", "");
02240     }
02241 
02242     void
02243     CleanMpeg7()
02244     {
02245         ILOG_INFO("Cleaning mpeg7");
02246         CleanCall("deletempeg7shot", "ALL");
02247         CleanCall("deletempeg7annotation", "ALL");
02248         CleanCall("deleteannotationtable", "Frame concepts.txt anchor");
02249         CleanCall("deleteannotationtable", "Frame concepts.txt desert");
02250         CleanCall("deleteannotationtable", "Shot concepts.txt anchor");
02251         CleanCall("deleteannotationtable", "Shot concepts.txt desert");
02252     }
02253 
02254     void
02255     CleanMergedAnnotations()
02256     {
02257         ILOG_INFO("Cleaning merged annotations");
02258         if (mConcepts.empty())
02259         {
02260             ILOG_ERROR("CleanMergedAnnotations: need concepts");
02261             return;
02262         }
02263         CleanCall("deleteannotationtableset", GetQuidClass() + " " + mConcepts);
02264     }
02265 
02266     void
02267     CleanSm2()
02268     {
02269         ILOG_INFO("Cleaning sm2 and sm2extra");
02270         CleanCall("deletefeaturetable", "false false Keyframes ALL ALL");
02271         CleanCall("deletefeaturetable", "false false keys ALL ALL");
02272         CleanCall("deletefeaturetable", "true false sm2.vxs ALL ALL");
02273         CleanCall("deletefeaturetable", "false true . ALL ALL");
02274     }
02275 
02276     void
02277     CleanClus()
02278     {
02279         ILOG_INFO("Cleaning clus");
02280         CleanCall("deletefeaturetable", "false false Keyframes ALL ALL");
02281         CleanCall("deletefeaturetable", "true false clusters ALL ALL");
02282         CleanCall("deletefeaturetable", "false true . ALL ALL");
02283     }
02284 
02285     void
02286     CleanCluster()
02287     {
02288         ILOG_INFO("Cleaning cluster");
02289         CleanCall("deletefeaturetable", "true false . ALL ALL");
02290         CleanCall("deletefeaturetable", "false false " + GetWalkerDir() +
02291                   " ALL ALL");
02292     }
02293 
02294     void
02295     CleanFeature()
02296     {
02297         ILOG_INFO("Cleaning feature");
02298         CleanCall("deletefeaturetable", "false false " + GetWalkerDir() +
02299                   " ALL ALL");
02300         CleanCall("deletefeaturetable", "false true . ALL ALL");
02301     }
02302 
02303     // This is a "hack" awaiting further refactoring
02304     void
02305     CleanAverages(CString kernel)
02306     {
02307         ILOG_INFO("Cleaning averages");
02308         String iniFile = "${IMPALAROOT}/src/script/" + kernel + ".ini";
02309         String fileName = ResolveExports(iniFile);
02310         Persistency::File file = Persistency::RepositoryGetFile(fileName, false,
02311                                                                 false);
02312         Core::Feature::WeightedFeatureList fList;
02313         Read(&fList, file);
02314         for (int i=0 ; i<fList.Size() ; i++)
02315         {
02316             Persistency::FeatureLocator fLoc(mLocation, mSetName, false, true,
02317                                              "", fList.GetFeature(i), "");
02318             fLoc.SetSuffix(".average.raw");
02319             std::cout << "hack: deleting average " << fLoc << std::endl;
02320             Persistency::FeatureTableRepository().Delete(fLoc);
02321         }
02322     }
02323 
02324     void
02325     CleanModel(bool doFeatureIndex)
02326     {
02327         ILOG_INFO("Cleaning model");
02328         if (doFeatureIndex)
02329             CleanCall("deletefeaturetable", "false true . ALL ALL");
02330         CleanCall("deletekernelmatrix", "true nil nil nil ALL ALL");
02331         CleanCall("deletemodel", "ALL ALL ALL ALL");
02332     }
02333 
02334     void
02335     CleanClassify()
02336     {
02337         ILOG_INFO("Cleaning classify");
02338         CleanCall("deletekernelmatrix",
02339                   "false " + GetWalkerDir() + " nil nil ALL ALL");
02340         CleanCall("deletesimilaritytableset",
02341                   "false " + GetWalkerDir() + " ALL ALL ALL ALL");
02342         CleanCall("deletesimilaritytableset",
02343                   "true " + GetWalkerDir() + " ALL ALL ALL ALL");
02344         CleanCall("deletempeg7concept", "ALL");
02345     }
02346 
02347     void
02348     CleanExportConcepts()
02349     {
02350         ILOG_INFO("Cleaning exportconcepts");
02351         CleanCall("deletempeg7concept", "ALL");
02352         CleanCall("deletesimilaritytableset",
02353                   "true nil concepts.txt svm_nrkf_episode_1_holdout_0 imported-combined nil");
02354     }
02355 
02356     void
02357     CleanCall(CString cmd, CString args)
02358     {
02359         String cmdLine = "repository " + cmd + " " + mLocation +
02360             " " + mSetName + " " + args;
02361         ILOG_INFO("Clean: " << cmdLine);
02362         if (mDryRun)
02363             std::cout << cmdLine << std::endl;
02364         else
02365             CallSystem(cmdLine);
02366     }
02367 
02368 private:
02369 
02370     void
02371     InitSet(CString name)
02372     {
02373         mSetName = name;
02374         if (mSetName.empty())
02375             return;
02376 
02377         Locator loc(mLocation, mSetName);
02378         if (VideoSetsRepository::GetInstance().Contains(mSetName))
02379         {
02380             mVideoSet = VideoSetRepository().Get(loc);
02381         }
02382         else if (ImageSetsRepository::GetInstance().Contains(mSetName))
02383         {
02384             ImageSetLocator imSetLoc(loc, "");
02385             mImageSet = ImageSetRepository().Get(imSetLoc);
02386         }
02387         else
02388         {
02389             ILOG_ERROR("Could not find " << mSetName << " in repository");
02390         }
02391     }
02392 
02393     void
02394     InitCurCmd(CString cmdLine)
02395     {
02396         Util::StringParser p(cmdLine);
02397         mCurCmd = p.GetString(' ', false);
02398         mCurCmdArgs.clear();
02399         while (!p.TheEnd())
02400         {
02401             String arg = p.GetString(' ', false);
02402             if (!arg.empty())
02403                 mCurCmdArgs.push_back(arg);
02404         }
02405     }
02406 
02407     String
02408     GetCurCmd()
02409     {
02410         return mCurCmd;
02411     }
02412 
02413     int
02414     GetCurCmdNrArgs()
02415     {
02416         return mCurCmdArgs.size();
02417     }
02418 
02419     String
02420     GetCurCmdArg(int idx)
02421     {
02422         if ((idx < 0) || (idx >= mCurCmdArgs.size()))
02423         {
02424             ILOG_ERROR("[GetCurCmdArg] invalid argument index");
02425             return "invalidArg";
02426         }
02427         return mCurCmdArgs[idx];
02428     }
02429 
02430     String
02431     GetWalkerProg()
02432     {
02433         if (mImageSet)
02434         {
02435             if (mCuda)
02436                 return "imsetcuda";
02437             return "imset";
02438         }
02439         if (mCuda)
02440             return "vidsetcuda";
02441         return "vidset";
02442     }
02443 
02444     String
02445     GetWalkerDir()
02446     {
02447         if (mImageSet)
02448             return ".";
02449         if (! mQuidFile.empty())
02450             return FileNameBase(mQuidFile);
02451         if (mFrames)
02452             return "Frames";
02453         return "Keyframes";
02454     }
02455 
02456     String
02457     GetFrameWalk()
02458     {
02459         if (mImageSet)
02460         {
02461             if (mNoImArchive)
02462                 return "";
02463             return "--imSplitArchive";
02464         }
02465         if (! mQuidFile.empty())
02466             return "--quidWalk " + mQuidFile;
02467         if (mRkf)
02468             return "--keyframes --rkfMask --keyframeSrc";
02469         if (mTaskNrFrames > 0)
02470         {
02471             return "--partialWalk --numberFrames " + MakeString(mTaskNrFrames)
02472                 + " --segmentation";
02473         }
02474         if (mFrames)
02475             return "";
02476         return "--keyframes --keyframeSrc";
02477     }
02478 
02479     String
02480     GetQuidClass()
02481     {
02482         if (mImageSet)
02483             return "Image";
02484         return "Frame";
02485     }
02486 
02487     bool
02488     AskUserPermission(CString cmdLine)
02489     {
02490         if (!mInteractive)
02491             return true;
02492 
02493         char buf[0x100];
02494         while(1)
02495         {
02496             std::cout << "[" << cmdLine << "] Execute? [nY] " << std::endl;
02497             buf[0] = '\0';
02498             std::cin.getline(buf, 0x100, '\n');
02499             if ((buf[0] == 'n') || (buf[0] == 'N'))
02500                 return false;
02501             if ((buf[0] == 'y') || (buf[0] == 'Y') || (buf[0] == '\0'))
02502                 return true;
02503             std::cout << "Invalid input...";
02504         }
02505     }
02506 
02507     String
02508     ResolveExports(CString cmdLine)
02509     {
02510         String line = cmdLine;
02511         String::size_type start = line.find("${");
02512         while (start != String::npos)
02513         {
02514             String::size_type end = line.find("}", start+2);
02515             String var = line.substr(start+2, end - (start+2));
02516             String val;
02517             if (!mExports.Get(var, val))
02518             {
02519                 char* envVal = getenv(var.c_str());
02520                 if (envVal)
02521                 {
02522                     val = String(envVal);
02523                 }
02524                 else
02525                 {
02526                     ILOG_ERROR("ResolveExports: unknown variable " << var);
02527                     return "";
02528                 }
02529             }
02530             line = line.replace(start, var.size()+3, val);
02531             start = line.find("${");
02532         }
02533         return line;
02534     }
02535 
02536     void
02537     CallSystem(CString cmdLine)
02538     {
02539         if (!AskUserPermission(cmdLine))
02540             return;
02541 
02542         char* sysBuf = new char[cmdLine.size() + 100];
02543         sprintf(sysBuf, "%s", cmdLine.c_str());
02544         int sysRes = system(sysBuf);
02545         if (sysRes != 0)
02546         {
02547             ILOG_ERROR("system call failed: ["  << sysBuf << "]");
02548         }
02549         delete sysBuf;
02550     }
02551 
02552     String
02553     GetExtraArguments()
02554     {
02555         CmdOptions& options = CmdOptions::GetInstance();
02556         String res("");
02557         if (options.GetBool("noFeatureCache"))
02558             res += " --noFeatureCache";
02559 
02560         if (! mDataServer.empty())
02561             res += " --dataServer " + mDataServer;
02562         res += " --data " + options.GetString("data");
02563 
02564         String refModelServerOption = "dataServer::reference_model.txt";
02565         String refModelServer = options.GetString(refModelServerOption);
02566         if (! refModelServer.empty())
02567             res += " --" + refModelServerOption + " " + refModelServer;
02568 
02569         String refModelDataOption = "data::reference_model.txt";
02570         String refModelData = options.GetString(refModelDataOption);
02571         if (! refModelData.empty())
02572             res += " --" + refModelDataOption + " " + refModelData;
02573 
02574         return res;
02575     }
02576 
02577     String              mTopCmd; // top level : single command or .ido file
02578     String              mCurCmd; // the current command to be executed
02579     std::vector<String> mCurCmdArgs; // arguments to the current command
02580 
02581     bool      mUseMpi;
02582     String    mDataServer;
02583     String    mLocation;
02584     String    mSetName;
02585     VideoSet* mVideoSet;
02586     ImageSet* mImageSet;
02587 
02588     int       mNCPU;
02589     int       mNodes;
02590     int       mPPN;
02591     String    mSrcOpt;
02592     String    mSrcOpt1;
02593     String    mSrcOpt2;
02594     String    mShotOpt;
02595     bool      mDoShotIndex;
02596     String    mExtra2;
02597     String    mFramesJpg;
02598     String    mSkipStills;
02599     bool      mFrames;
02600     bool      mRkf;
02601     String    mQuidFile;
02602     int       mTaskNrFrames;
02603     int       mTaskBlockSize;
02604     int       mTaskNrBlocks;
02605     bool      mNoImArchive;
02606     String    mLimit;
02607     String    mClusters;
02608     String    mRandomize;
02609     String    mProtoSet;
02610     String    mCodebook;
02611     bool      mDoFeature;
02612     bool      mDoFeatureIndex;
02613     int       mPrecomputeIncrement;
02614     int       mPrecomputeRuns;
02615     String    mFeatureIndexCat;
02616     String    mClassifyIndexCat;
02617     String    mEpisodeConstrained;
02618     String    mSkipFusion;
02619     String    mAnnoSet;
02620     String    mAnnoSetTest;
02621     String    mConcepts;
02622     String    mModel;
02623     bool      mFik;
02624     int       mModelBins;
02625     bool      mComputeKernelData;
02626     String    mStoreKernelData;
02627     String    mKernelDataOnly;
02628     bool      mDoClassifyIndex;
02629     String    mAnnotations;
02630 
02631     String    mImpalaTmp;
02632     bool      mCuda;
02633     int       mCudaDevice;
02634     bool      mInteractive;
02635     bool      mDryRun;
02636     String    mInputServer;
02637     String    mRefServer;
02638 
02639     std::vector<String> mWG;
02640     std::vector<String> mWGclus960sp;
02641     std::vector<String> mAllSift;
02642     std::vector<String> mAllSurf;
02643 
02644     Util::SimpleMap<String, String> mExports;
02645 
02646     ILOG_VAR_DECL;
02647 };
02648 
02649 ILOG_VAR_INIT(IDo, Impala.Application);
02650 
02651 int
02652 mainIDo(int argc, char* argv[])
02653 {
02654     CmdOptions& options = CmdOptions::GetInstance();
02655     options.Initialise(true, true, true);
02656     options.AddOption(0, "set", "dataSet.txt", "", 0, true);
02657     options.AddOption(0, "ncpu", "nr", "1", 0, true);
02658     options.AddOption(0, "nodes", "nr", "-1", 0, true);
02659     options.AddOption(0, "ppn", "nr", "-1", 0, true);
02660     options.AddOption(0, "srcopt", "option", "", 0, true);
02661     options.AddOption(0, "srcopt1", "option", "", 0, true);
02662     options.AddOption(0, "srcopt2", "option", "", 0, true);
02663     options.AddOption(0, "shotopt", "options for shot segmenter", "", 0, true);
02664     options.AddOption(0, "extra2", "yes", "", 0, true);
02665     options.AddOption(0, "frames_jpg", "yes", "", 0, true);
02666     options.AddOption(0, "skip_stills", "yes", "", 0, true);
02667     options.AddOption(0, "frames", "", "0", 0, true);
02668     options.AddOption(0, "rkf", "", "0", 0, true);
02669     options.AddOption(0, "quidfile", "filename", "", 0, true);
02670     options.AddOption(0, "tasknrframes", "nr", "0", 0, true);
02671     options.AddOption(0, "taskblocksize", "nr", "0", 0, true);
02672     options.AddOption(0, "tasknrblocks", "nr", "1", 0, true);
02673     options.AddOption(0, "noimarchive", "", "0", 0, true);
02674     options.AddOption(0, "limit", "nr", "50", 0, true);
02675     options.AddOption(0, "clusters", "nr", "4096", 0, true);
02676     options.AddOption(0, "randomize", "--noRandomizeSeed", "", 0, true);
02677     options.AddOption(0, "protoset", "dataSet.txt", "", 0, true);
02678     options.AddOption(0, "codebook", "Codebooks/table.tab", "", 0, true);
02679     options.AddOption(0, "dofeature", "flag", "1", 0, true);
02680     options.AddOption(0, "dofeatureindex", "flag", "1", 0, true);
02681     options.AddOption(0, "precomputeincrement", "stepsize", "0", 0, true);
02682     options.AddOption(0, "precomputeruns", "nr", "1", 0, true);
02683     options.AddOption(0, "featureindexcat", "name", "", 0, true);
02684     options.AddOption(0, "episode_constrained", "--episode-constrained 0", "",
02685                       0, true);
02686     options.AddOption(0, "skip_fusion", "yes", "", 0, true);
02687     options.AddOption(0, "annoset", "dataSet.txt", "", 0, true);
02688     options.AddOption(0, "annosettest", "dataSet.txt", "", 0, true);
02689     options.AddOption(0, "concepts", "concepts.txt", "", 0, true);
02690     options.AddOption(0, "model", "modelName", "", 0, true);
02691     options.AddOption(0, "fik", "", "0", 0, true);
02692     options.AddOption(0, "modelbins", "nr", "100", 0, true);
02693     options.AddOption(0, "computekerneldata", "", "0", 0, true);
02694     options.AddOption(0, "storekerneldata", "--storeKernelData 1", "", 0, true);
02695     options.AddOption(0, "kerneldataonly", "--kernelDataOnly 1", "", 0, true);
02696     options.AddOption(0, "doclassifyindex", "flag", "1", 0, true);
02697     options.AddOption(0, "annotations", "concepts.txt", "", 0, true);
02698     options.AddOption(0, "impalatmp", "fileName", "/local/${USER}/tmp", 0, true);
02699     options.AddOption(0, "cuda", "", "0");
02700     options.AddOption(0, "interactive", "", "0");
02701     options.AddOption(0, "dryrun", "", "0");
02702     options.AddOption(0, "inputserver", "host:port",
02703                       "image.science.uva.nl:25000", 0, true);
02704     options.AddOption(0, "refserver", "host:port", "image.science.uva.nl:26000",
02705                       0, true);
02706     String usageStr = "cmd|file.ido mpi|nompi noserver|server:port\n\n cmd = \n";
02707     usageStr += "  featureWG\n";
02708     if (! options.ParseArgs(argc, argv, usageStr, 3))
02709         return 1;
02710 
02711     ILOG_VAR(Impala.Application.mainIDo);
02712 
02713     String cmd = options.GetArg(0);
02714     String mpi = options.GetArg(1);
02715     if (! ((mpi == "mpi") || (mpi == "nompi")))
02716     {
02717         ILOG_ERROR("Second argument should be mpi|nompi");
02718         return 1;
02719     }
02720     String server = options.GetArg(2);
02721 
02722     Application::IDo iDo(cmd, mpi == "mpi", server);
02723     return iDo.Go();
02724 }
02725 
02726 } // namespace Application
02727 } // namespace Impala
02728 
02729 int
02730 main(int argc, char* argv[])
02731 {
02732     int result = Impala::Application::mainIDo(argc, argv);
02733     return result;
02734 }

Generated on Thu Jan 13 09:03:42 2011 for ImpalaSrc by  doxygen 1.5.1