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

mainImSet.cpp

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

Generated on Fri Mar 19 09:30:29 2010 for ImpalaSrc by  doxygen 1.5.1