vcx-benchmark.C

Go to the documentation of this file.
00001 /*!@file AppNeuro/vcx-benchmark.C */
00002 
00003 // //////////////////////////////////////////////////////////////////// //
00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2005   //
00005 // by the University of Southern California (USC) and the iLab at USC.  //
00006 // See http://iLab.usc.edu for information about this project.          //
00007 // //////////////////////////////////////////////////////////////////// //
00008 // Major portions of the iLab Neuromorphic Vision Toolkit are protected //
00009 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency //
00010 // in Visual Environments, and Applications'' by Christof Koch and      //
00011 // Laurent Itti, California Institute of Technology, 2001 (patent       //
00012 // pending; application number 09/912,225 filed July 23, 2001; see      //
00013 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status).     //
00014 // //////////////////////////////////////////////////////////////////// //
00015 // This file is part of the iLab Neuromorphic Vision C++ Toolkit.       //
00016 //                                                                      //
00017 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can   //
00018 // redistribute it and/or modify it under the terms of the GNU General  //
00019 // Public License as published by the Free Software Foundation; either  //
00020 // version 2 of the License, or (at your option) any later version.     //
00021 //                                                                      //
00022 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope  //
00023 // that it will be useful, but WITHOUT ANY WARRANTY; without even the   //
00024 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
00025 // PURPOSE.  See the GNU General Public License for more details.       //
00026 //                                                                      //
00027 // You should have received a copy of the GNU General Public License    //
00028 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write   //
00029 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,   //
00030 // Boston, MA 02111-1307 USA.                                           //
00031 // //////////////////////////////////////////////////////////////////// //
00032 //
00033 // Primary maintainer for this file: Rob Peters <rjpeters at usc dot edu>
00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/AppNeuro/vcx-benchmark.C $
00035 // $Id: vcx-benchmark.C 10982 2009-03-05 05:11:22Z itti $
00036 //
00037 
00038 #ifndef APPNEURO_VCX_BENCHMARK_C_DEFINED
00039 #define APPNEURO_VCX_BENCHMARK_C_DEFINED
00040 
00041 #include "Channels/ChannelOpts.H"
00042 #include "Channels/IntegerInput.H"
00043 #include "Channels/IntegerMathEngine.H"
00044 #include "Component/ModelManager.H"
00045 #include "Component/ModelOptionDef.H"
00046 #include "Component/ModelParam.H"
00047 #include "Channels/IntegerRawVisualCortex.H"
00048 #include "Channels/RawVisualCortex.H"
00049 #include "rutz/rand.h"
00050 #include "rutz/time.h"
00051 
00052 #include <stdio.h>
00053 #include <sys/resource.h>
00054 #include <sys/time.h>
00055 
00056 static const ModelOptionDef OPT_UseInteger =
00057   { MODOPT_FLAG, "UseInteger", &MOC_GENERAL, OPTEXP_CORE,
00058     "Whether to the VisualCortex based on integer arithmetic",
00059     "use-integer", '\0', "", "true" };
00060 
00061 int main(int argc, char** argv)
00062 {
00063   MYLOGVERB = LOG_CRIT;
00064 
00065   ModelManager manager("VisualCortex Benchmarker");
00066   OModelParam<bool> useinteger(&OPT_UseInteger, &manager);
00067 
00068   nub::ref<IntegerMathEngine> ieng(new IntegerMathEngine(manager));
00069   manager.addSubComponent(ieng);
00070 
00071   nub::ref<IntegerRawVisualCortex> ivcx(new IntegerRawVisualCortex(manager, ieng));
00072   manager.addSubComponent(ivcx);
00073 
00074   nub::ref<RawVisualCortex> fvcx(new RawVisualCortex(manager));
00075   manager.addSubComponent(fvcx);
00076 
00077   manager.setOptionValString(&OPT_MaxNormType, "Maxnorm");
00078   manager.setOptionValString(&OPT_DirectionChannelLowThresh, "0");
00079   manager.setOptionValString(&OPT_IntChannelScaleBits, "16");
00080   manager.setOptionValString(&OPT_IntMathLowPass5, "lp5optim");
00081   manager.setOptionValString(&OPT_IntMathLowPass9, "lp9optim");
00082 
00083   if (manager.parseCommandLine(argc, argv, "[numframes=100] [WWWxHHH=512x512]",
00084                                0, 2) == false)
00085     return 1;
00086 
00087   const int nframes =
00088     manager.numExtraArgs() >= 1
00089     ? manager.getExtraArgAs<int>(0) : 100;
00090 
00091   const Dims dims =
00092     manager.numExtraArgs() >= 2
00093     ? manager.getExtraArgAs<Dims>(1) : Dims(512,512);
00094 
00095   manager.start();
00096 
00097   if (nframes > 0)
00098     {
00099       // allocate two images with different random
00100       // (uninitialized) content (so that we excite the
00101       // dynamic channels with non-static inputs, which may
00102       // some day make a difference in execute time):
00103       Image<PixRGB<byte> > in1(dims, NO_INIT);
00104       Image<PixRGB<byte> > in2(dims, NO_INIT);
00105 
00106       rutz::urand gen(time(NULL)); gen.idraw(1);
00107 
00108       for (Image<PixRGB<byte> >::iterator
00109              itr = in1.beginw(), stop = in1.endw(); itr != stop; ++itr)
00110         *itr = PixRGB<byte>(gen.idraw(256),
00111                             gen.idraw(256),
00112                             gen.idraw(256));
00113 
00114       for (Image<PixRGB<byte> >::iterator
00115              itr = in2.beginw(), stop = in2.endw(); itr != stop; ++itr)
00116         *itr = PixRGB<byte>(gen.idraw(256),
00117                             gen.idraw(256),
00118                             gen.idraw(256));
00119 
00120       const Image<byte> clipMask;
00121 
00122       fprintf(stderr, "%s (%s): START: %d frames %dx%d... ",
00123               argv[0],
00124               useinteger.getVal() ? "integer" : "floating-point",
00125               nframes, dims.w(), dims.h());
00126       fflush(stderr);
00127 
00128       const rutz::time real1 = rutz::time::wall_clock_now();
00129       const rutz::time user1 = rutz::time::user_rusage();
00130       const rutz::time sys1 = rutz::time::sys_rusage();
00131 
00132       SimTime t = SimTime::ZERO();
00133 
00134       if (useinteger.getVal())
00135         for (int c = 0; c < nframes; ++c)
00136           {
00137             t += SimTime::HERTZ(30);
00138 
00139             PyramidCache<int> cache;
00140             ivcx->inputInt(IntegerInput::fromRgb(c & 1 ? in2 : in1,
00141                                                  ieng->getNbits()),
00142                            t, &cache, clipMask);
00143 
00144             const Image<int> output = ivcx->getOutputInt();
00145           }
00146       else
00147         for (int c = 0; c < nframes; ++c)
00148           {
00149             t += SimTime::HERTZ(30);
00150 
00151             PyramidCache<int> cache;
00152             fvcx->input(InputFrame::fromRgb(c & 1 ? &in2 : &in1, t));
00153 
00154             const Image<float> output = fvcx->getOutput();
00155           }
00156 
00157       const rutz::time real2 = rutz::time::wall_clock_now();
00158       const rutz::time user2 = rutz::time::user_rusage();
00159       const rutz::time sys2 = rutz::time::sys_rusage();
00160 
00161       const double real_secs = (real2 - real1).sec();
00162       const double user_secs = (real2 - real1).sec();
00163       const double sys_secs = (real2 - real1).sec();
00164 
00165       const double frame_rate = nframes / real_secs;
00166       const double msec_per_frame = (1000.0*real_secs) / nframes;
00167 
00168       fprintf(stderr, "DONE.\n");
00169       fprintf(stderr, "%s (%s): real %.3fs; user %.3fs; "
00170               "sys %.3fs\n", argv[0],
00171               useinteger.getVal() ? "integer" : "floating-point",
00172               real_secs, user_secs, sys_secs);
00173       fprintf(stderr, "%s (%s): %.3ffps; %.3fmsec/frame\n",
00174               argv[0],
00175               useinteger.getVal() ? "integer" : "floating-point",
00176               frame_rate, msec_per_frame);
00177     }
00178 
00179   manager.stop();
00180 }
00181 
00182 // ######################################################################
00183 /* So things look consistent in everyone's emacs... */
00184 /* Local Variables: */
00185 /* mode: c++ */
00186 /* indent-tabs-mode: nil */
00187 /* End: */
00188 
00189 #endif // APPNEURO_VCX_BENCHMARK_C_DEFINED
Generated on Sun May 8 08:40:08 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3