00001 #include "Core/ImageSet/MakeImageSet.h"
00002 #include "Core/ImageSet/ClusterFeatures.h"
00003 #include "Core/ImageSet/IndexConcepts.h"
00004 #include "Core/ImageSet/CombineConcepts.h"
00005 #include "Core/ImageSet/IndexFeatures.h"
00006 #include "Core/ImageSet/ProtoSimilarityEval.h"
00007 #include "Core/ImageSet/Archive.h"
00008 #include "Core/ImageSet/Thumbnails.h"
00009 #include "Core/ImageSet/Reporter.h"
00010 #include "Core/ImageSet/Walker.h"
00011 #include "Core/ImageSet/ApplyConcepts.h"
00012 #include "Core/ImageSet/ConcatFeatures.h"
00013 #include "Core/ImageSet/ComputeKernelData.h"
00014 #include "Core/Feature/VisSem.h"
00015 #include "Core/ImageSet/InterestPointProc.h"
00016 #include "Core/ImageSet/MakeQuidLookup.h"
00017
00018
00019 #include "Link/ImpalaLib.cpp"
00020 #include "Link/Svm/LinkSvm.cpp"
00021
00022 namespace Impala
00023 {
00024 namespace Application
00025 {
00026
00027
00028 using namespace Impala::Core::Array;
00029 using namespace Impala::Core::Feature;
00030 using namespace Impala::Core::ImageSet;
00031
00032 int
00033 mainImSet(int argc, char* argv[])
00034 {
00035 Link::Mpi::Init(&argc, &argv);
00036
00037 CmdOptions& options = CmdOptions::GetInstance();
00038 options.Initialise(false, false, true);
00039 options.AddOption(0, "report", "perNr", "0");
00040 options.AddOption(0, "startDir", "idx", "0");
00041 options.AddOption(0, "numberDirs", "nr", "-1");
00042 options.AddOption(0, "startFile", "idx", "0");
00043 options.AddOption(0, "numberFiles", "nr", "-1");
00044 options.AddOption(0, "virtualWalk", "", "0");
00045 options.AddOption(0, "virtualWalkAll", "", "0");
00046 options.AddOption(0, "imArchive", "", "0");
00047 options.AddOption(0, "imFileArchive", "", "0");
00048 options.AddOption(0, "imSplitArchive", "", "0");
00049 options.AddOption(0, "imCacheSize", "size", "1");
00050 options.AddOption(0, "featureIndexCat", "name", "");
00051 options.AddOption(0, "classifyIndexCat", "name", "");
00052 options.AddOption(0, "precomputed", "[applyconcepts only] boolean: if 1 modelfiles must be for precomputed kernel", "0");
00053 options.AddOption(0, "storeKernelData", "[applyconcepts only] boolean: if 1 kernel data will be written to disk", "0");
00054 options.AddOption(0, "kernelDataOnly", "[only works for applyconcepts] boolean: if 1 only kernel data will be computed (no model apply)", "0");
00055 options.AddOption(0, "fik", "[only works for applyconcepts] boolean: if 1 modelfiles must be for fast intersection kernel", "0");
00056 options.AddOption(0, "addToName", "[fixsizes only] string: add this to the standard filename of archive", "");
00057
00058
00059 Impala::Core::ImageSet::InterestPointProc::AddCmdOptions();
00060
00061 String usageStr = String("cmd imageSet|ixs\n") +
00062 "cmd == fixsizes --> imset fixsizes imageSet [max-width max-height [split]]\n" +
00063 "other commands are undocumented..." +
00064 "\n\n";
00065 if (! options.ParseArgs(argc, argv, usageStr, 2))
00066 {
00067 Link::Mpi::Finalize();
00068 return 1;
00069 }
00070
00071 ILOG_VAR(Impala.Application.ImSet.mainImSet);
00072
00073 String cmd = options.GetArg(0);
00074 String fileName = options.GetArg(1);
00075 ImageSet* imageSet = MakeImageSet(fileName);
00076 imageSet->SetImageSrc(options.GetBool("imArchive"),
00077 options.GetBool("imFileArchive"),
00078 options.GetBool("imSplitArchive"),
00079 true);
00080
00081 Walker walker(imageSet);
00082 Reporter* reporter = new Reporter(0);
00083 walker.AddListener(reporter);
00084
00085 ILOG_INFO("imset command : " << cmd);
00086
00087 if (cmd == "computekerneldata")
00088 walker.AddListener(new ComputeKernelData(reporter, options));
00089 if (cmd == "applyconcepts")
00090 walker.AddListener(new ApplyConcepts(reporter, options, imageSet,false));
00091 if (cmd == "applyconceptsindex")
00092 walker.AddListener(new ApplyConcepts(reporter, options, imageSet, true));
00093 if (cmd == "indexconcepts")
00094 walker.AddListener(new IndexConcepts(reporter, options, imageSet));
00095 if (cmd == "combineconcepts")
00096 walker.AddListener(new CombineConcepts(reporter, options));
00097 if (cmd == "archive")
00098 walker.AddListener(new Archive(reporter, options));
00099 if (cmd == "concatfeatures")
00100 walker.AddListener(new ConcatFeatures(reporter, options));
00101 if (cmd == "indexfeatures")
00102 walker.AddListener(new IndexFeatures(reporter, options));
00103 if (cmd == "interestpointproc")
00104 walker.AddListener(new InterestPointProc(reporter, options));
00105 if (cmd == "makequidlookup")
00106 walker.AddListener(new MakeQuidLookup(reporter, options));
00107 if (cmd == "thumbnails")
00108 walker.AddListener(new Thumbnails(reporter, options));
00109 if (cmd == "clusterfeatures")
00110 {
00111 if (options.GetNrArg() < 4)
00112 ILOG_ERROR("cluster: missing argument");
00113 String feature = options.GetArg(2);
00114 Computor* c = 0;
00115 if (feature == "weibull")
00116 c = new VisSem("vissem", options);
00117 if (feature == "gabor")
00118 c = new Core::Feature::VisSem("vissemgabor", options);
00119 String clusteror = options.GetArg(3);
00120 walker.AddListener(new ClusterFeatures(c, clusteror, reporter, options));
00121 }
00122
00123 if (cmd == "viseval")
00124 {
00125 Computor* c = new Core::Feature::VisSem("vissem", options);
00126 walker.AddListener(new ProtoSimilarityEval(c, reporter, options));
00127 }
00128 if (cmd == "visgaboreval")
00129 {
00130 Computor* c = new Core::Feature::VisSem("vissemgabor", options);
00131 walker.AddListener(new ProtoSimilarityEval(c, reporter,options));
00132 }
00133
00134 if ((walker.NrListeners() == 1) && (cmd != "nop"))
00135 {
00136 ILOG_ERROR("Unknow command : " << cmd);
00137 Link::Mpi::Finalize();
00138 return 1;
00139 }
00140
00141 walker.AddListener(new Reporter(reporter));
00142 if (FileNameExt(fileName) == "ixs")
00143 {
00144 walker.LoadBookmarks(fileName);
00145 walker.DoWalkBookmarks();
00146 }
00147 else
00148 {
00149 int startDir = options.GetInt("startDir");
00150 int numberDirs = options.GetInt("numberDirs");
00151 #ifdef MPI_USED
00152 int numProcs = Link::Mpi::NrProcs();
00153 int myId = Link::Mpi::MyId();
00154 if (numberDirs == -1)
00155 numberDirs = imageSet->NrDirs();
00156 if (startDir + numberDirs >= imageSet->NrDirs())
00157 numberDirs = imageSet->NrDirs() - startDir;
00158 if (!options.GetBool("virtualWalkAll"))
00159 {
00160 int lastDir = startDir + numberDirs;
00161 int taskSize = numberDirs / numProcs;
00162 int restSize = numberDirs % numProcs;
00163 int curDir = startDir;
00164 for (int i=0 ; i<=myId ; i++)
00165 {
00166 startDir = curDir;
00167 numberDirs = taskSize;
00168 if (--restSize >= 0)
00169 numberDirs++;
00170 if (startDir + numberDirs > lastDir)
00171 numberDirs = lastDir - startDir;
00172 curDir += numberDirs;
00173 }
00174 }
00175 ILOG_INFO("Process " << myId << " of " << numProcs
00176 << " is doing dirs " << startDir << " till "
00177 << startDir + numberDirs);
00178 #endif
00179 walker.DoWalk(startDir, numberDirs);
00180 }
00181 reporter->FinalReport();
00182 int nrOfErrors = ILOG_ERROR_COUNT;
00183
00184 nrOfErrors = Link::Mpi::ReduceSum(nrOfErrors);
00185 ILOG_INFO_HEADNODE("Root: total nr error = " << nrOfErrors);
00186 Link::Mpi::Finalize();
00187
00188 return nrOfErrors;
00189 }
00190
00191 }
00192 }
00193
00194 int
00195 main(int argc, char* argv[])
00196 {
00197
00198 #ifdef NO_DIALOGONCRASH
00199 #ifdef WIN32
00200 DWORD oldMode = ::SetErrorMode(SEM_NOGPFAULTERRORBOX);
00201 ::SetErrorMode(oldMode | SEM_NOGPFAULTERRORBOX);
00202 #endif
00203 #endif
00204
00205 return Impala::Application::mainImSet(argc, argv);
00206 }