CudaHmaxFLSal.C
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #include "CUDA/CudaSaliency.H"
00037 #include "CUDA/CudaHmaxFLSal.H"
00038 #include "CUDA/CudaHmaxFL.H"
00039 #include "CUDA/CudaHmax.H"
00040 #include "CUDA/CudaFilterOps.H"
00041 #include "CUDA/CudaImage.H"
00042
00043 #include "Image/Kernels.H"
00044 #include "CUDA/CudaMathOps.H"
00045 #include "CUDA/CudaConvolutions.H"
00046 #include "Image/Normalize.H"
00047 #include "CUDA/CudaCutPaste.H"
00048 #include "Raster/Raster.H"
00049 #include "Raster/RasterFileFormat.H"
00050 #include "Util/MathFunctions.H"
00051 #include "Util/Types.H"
00052 #include "Util/log.H"
00053 #include "Util/safecopy.H"
00054
00055 #include <cmath>
00056 #include <cstdio>
00057 #include <cstdlib>
00058 #include <cfloat>
00059 #include <limits>
00060 #include <sstream>
00061 #include <stdexcept>
00062
00063
00064
00065 CudaHmaxFLSal::CudaHmaxFLSal(MemoryPolicy mp, int dev, nub::ref<CudaSaliency> sal_in) :
00066 sal(sal_in)
00067 {
00068 CudaHmaxFL(mp,dev,0,std::vector<int>(),std::vector<int>());
00069 }
00070
00071 CudaHmaxFLSal::~CudaHmaxFLSal()
00072 {
00073 }
00074
00075
00076 void CudaHmaxFLSal::extractRandC1Patches(Image<float> *& posTrainingImages, int numPosTrainImages, std::vector<int> patchSizes, int numPatchesPerSize, int no)
00077 {
00078
00079 std::vector<int> c1ScaleSS(2);
00080 c1ScaleSS[0] = 1; c1ScaleSS[1] = 3;
00081 std::vector<int> c1SpaceSS(2);
00082 c1SpaceSS[0] = 10; c1SpaceSS[1] = 11;
00083
00084 CudaHmaxFL hmax(itsMp,itsDev,no,c1SpaceSS,c1ScaleSS,2,true,1.0F,1.0F,0.3F,4.05F,-0.05F,11,2);
00085
00086
00087 CudaImage<float> ***patches = new CudaImage<float>**[patchSizes.size()];
00088 for(unsigned int i=0;i<patchSizes.size();i++){
00089 patches[i] = new CudaImage<float>*[numPatchesPerSize];
00090 for(int j=0;j<numPatchesPerSize;j++) {
00091 patches[i][j] = new CudaImage<float>[no];
00092 for(int k=0;k<no;k++) {
00093
00094 patches[i][j][k].resize(patchSizes[i],patchSizes[i],ZEROS);
00095 }
00096 }
00097 }
00098
00099 CudaImage<float> **c1Res;
00100 CudaImage<float> stim;
00101 std::srand(time(0));
00102 int sb = 0;
00103
00104 for(int i=0;i<numPatchesPerSize;i++){
00105
00106 unsigned int imInd = static_cast<unsigned int>(floor((rand()-1.0F)/RAND_MAX*numPosTrainImages));
00107 stim = CudaImage<float>(posTrainingImages[imInd],itsMp,itsDev);
00108
00109
00110
00111 hmax.getC1(stim,c1Res);
00112
00113 int bsize1 = c1Res[sb][0].getWidth();
00114 int bsize2 = c1Res[sb][0].getHeight();
00115 hmax.printCorners("input",stim,i<5);
00116 for(unsigned int j=0;j<patchSizes.size();j++) {
00117 int xy1 = int(floor((rand()-1.0F)/RAND_MAX*(bsize1-patchSizes[j])));
00118 int xy2 = int(floor((rand()-1.0F)/RAND_MAX*(bsize2-patchSizes[j])));
00119 Rectangle r = Rectangle::tlbrI(xy2,xy1,xy2+patchSizes[j]-1,xy1+patchSizes[j]-1);
00120 for(int k=0;k<no;k++) {
00121 patches[j][i][k] = cudaCrop(c1Res[sb][k],r);
00122 patches[j][i][k] *= 255*10;
00123 }
00124 }
00125 hmax.printCorners("patch[3][i][0]",patches[3][i][0],i<5);
00126 hmax.clearC1(c1Res);
00127
00128 }
00129 setC1Patches(patches,patchSizes,numPatchesPerSize);
00130 }
00131
00132
00133 void CudaHmaxFLSal::getC1(CudaImage<float>**& c1Res)
00134 {
00135
00136 c1Res[0][0] = sal->getIMap();
00137 c1Res[0][1] = sal->getCMap();
00138 c1Res[0][2] = sal->getOMap();
00139 c1Res[0][3] = sal->getFMap();
00140 c1Res[0][4] = sal->getMMap();
00141
00142
00143
00144 }
00145
00146
00147 void CudaHmaxFLSal::getC1(const CudaImage<float>& input, CudaImage<float>**& c1Res)
00148 {
00149 sal->doInput(input.exportToImage());
00150
00151 c1Res[0][0] = sal->getIMap();
00152 c1Res[0][1] = sal->getCMap();
00153 c1Res[0][2] = sal->getOMap();
00154 c1Res[0][3] = sal->getFMap();
00155 c1Res[0][4] = sal->getMMap();
00156
00157 }
00158
00159
00160
00161
00162