00001 /*!@file CUDA/CudaHmaxFL.H Modified from T. Serre's HMAX model with feature learning */ 00002 00003 // //////////////////////////////////////////////////////////////////// // 00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2001 by the // 00005 // 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: Laurent Itti <itti@usc.edu> 00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/CUDA/CudaHmaxFL.H $ 00035 // $Id: CudaHmaxFL.H 12962 2010-03-06 02:13:53Z irock $ 00036 // 00037 00038 #ifndef CUDAHMAXFL_H_DEFINED 00039 #define CUDAHMAXFL_H_DEFINED 00040 00041 #include "CUDA/CudaImage.H" 00042 #include "CUDA/CudaHmax.H" 00043 #include <vector> 00044 00045 #include <cmath> 00046 #include <string> 00047 #include <vector> 00048 #include <dirent.h> 00049 00050 #define C1_PATCH_FILE_NAME "C1Patches" 00051 00052 //! Object recognition model inspired from Riesenhuber & Poggio's HMAX model 00053 /*! See Riesenhuber & Poggio, Nature Neuroscience, 1999. 00054 */ 00055 00056 class CudaHmaxFL : public CudaHmax { 00057 public: 00058 //! Default constructor. Need to call init() later. 00059 CudaHmaxFL(); 00060 00061 //! Constructor 00062 CudaHmaxFL(MemoryPolicy mp, int dev, const int nori, const std::vector<int>& spacess, 00063 const std::vector<int>& scaless, const int c1spaceol = 2, 00064 const bool angleflag = true, const float s2t = 1.0F, 00065 const float s2s = 1.0F, const float gamma = 0.3F, const float divstart = 4.05F, 00066 const float divstep = -0.05F, const int fsmin = 5, const int fsstep = 2); 00067 00068 //! Initialization 00069 void init(MemoryPolicy mp, int dev, const int nori, const std::vector<int>& spacess, 00070 const std::vector<int>& scaless, const int c1spaceol = 2, 00071 const bool angleflag = true, const float s2t = 1.0F, 00072 const float s2s = 1.0F, const float gamma = 0.3F, const float divstart = 4.05F, 00073 const float divstep = -0.05F, const int fsmin = 5, const int fsstep = 2); 00074 00075 void initFilters(const float gamma, const float divstart, const float divstep, const int fsmin , const int fsstep); 00076 00077 //! Free internal memory 00078 void freeMem(); 00079 void freeC1Patches(); 00080 00081 //! Destructor 00082 ~CudaHmaxFL(); 00083 00084 //! Compute C2 responses from an input image 00085 void getC2(const CudaImage<float>& input, float**& c2Res); 00086 00087 //! Randomly extract a set of C1Patches from positive training images 00088 void extractRandC1Patches(Image<float> *& posTrainingImages, int numPosTrainImages, std::vector<int> patchSizes, int nPatchesPerSize, int no); 00089 00090 //! Set the c1patches that should be used 00091 void setC1Patches(CudaImage<float>***&patches,std::vector<int> patchSizes,int numPatchesPerSize); 00092 void readInC1Patches(std::string fileName); 00093 void writeOutC1Patches(std::string fileName); 00094 std::vector<int> getC1PatchSizes(); 00095 int getC1PatchesPerSize(); 00096 00097 //! Get the c1patches that are being used 00098 CudaImage<float>***& getC1Patches(); 00099 00100 //! Calculate the distance from a patch to an image 00101 void windowedPatchDistance(CudaImage <float>*& images, int nimages, CudaImage <float> * &patches, int npatches, CudaImage<float>& D, float sumSquaredPatch); 00102 00103 00104 protected: 00105 int nswb; //!< number of scales within a scale band 00106 CudaImage<float> ***c1Patches; //!< patches that should be compared in S2 activation c1Patches[patchSizes][patchesPerSize] 00107 float **sumPSq; 00108 std::vector<int> c1PatchSizes; //!< Number of square patch sizes of c1Patches 00109 int nC1PatchesPerSize; //!< Number of patches per patch size of c1Patches 00110 }; 00111 00112 #endif 00113 00114 // ###################################################################### 00115 /* So things look consistent in everyone's emacs... */ 00116 /* Local Variables: */ 00117 /* indent-tabs-mode: nil */ 00118 /* End: */