InferoTemporalCudaHmax.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
00037
00038 #include "Neuro/InferoTemporalCudaHmax.H"
00039 #include "CUDA/CudaHmaxCBCL.H"
00040 #include "Learn/SVMClassifier.H"
00041 #include "Component/OptionManager.H"
00042 #include "Component/ModelOptionDef.H"
00043 #include "Image/MathOps.H"
00044 #include "Image/ShapeOps.H"
00045 #include "Image/CutPaste.H"
00046 #include "Image/ColorOps.H"
00047 #include "Neuro/NeuroOpts.H"
00048 #include "Neuro/NeuroSimEvents.H"
00049 #include "Neuro/Brain.H"
00050 #include "Neuro/VisualCortex.H"
00051 #include "Simulation/SimEventQueue.H"
00052 #include "Media/MediaSimEvents.H"
00053
00054 #include <cstdlib>
00055 #include <iostream>
00056 #include <iomanip>
00057 #include <fstream>
00058
00059 const ModelOptionDef OPT_ITCUDAHMAXC0PatchesFileName =
00060 { MODOPT_ARG_STRING, "ITC C0 feature patches file", &MOC_ITC, OPTEXP_CORE,
00061 "File containing c0 patches in the following format:\n"
00062 "NUM_PATCHES\n"
00063 "DEPTH WIDTH HEIGHT\n"
00064 "D0W0H0 D0W0H1 D0W0H2 ...\n"
00065 "D0W1H0 ...\n",
00066 "it-cudahmax-c0patches-filename", '\0', "<filename>", "" };
00067
00068 const ModelOptionDef OPT_ITCUDAHMAXC1PatchesFileName =
00069 { MODOPT_ARG_STRING, "ITC C1 feature patches file", &MOC_ITC, OPTEXP_CORE,
00070 "File containing c0 patches in the following format:\n"
00071 "NUM_PATCHES\n"
00072 "DEPTH WIDTH HEIGHT\n"
00073 "D0W0H0 D0W0H1 D0W0H2 ...\n"
00074 "D0W1H0 ...\n",
00075 "it-cudahmax-c1patches-filename", '\0', "<filename>", "" };
00076
00077
00078
00079
00080 namespace
00081 {
00082 Image<PixRGB<byte> > getCroppedObject(const Image<PixRGB<byte> >& scene,
00083 const Image<float>& smoothMask)
00084 {
00085 if (!scene.initialized())
00086 return Image<PixRGB<byte> >();
00087
00088 if (!smoothMask.initialized())
00089 return Image<PixRGB<byte> >();
00090
00091 const float threshold = 1.0f;
00092
00093 const Rectangle r = findBoundingRect(smoothMask, threshold);
00094 return crop(scene, r);
00095 }
00096 }
00097
00098
00099
00100 InferoTemporalCudaHmax::InferoTemporalCudaHmax(OptionManager& mgr,
00101 const std::string& descrName,
00102 const std::string& tagName) :
00103 InferoTemporalHmax(mgr, descrName, tagName),
00104 itsCUDAHMAXStoredC0PatchesFile(&OPT_ITCUDAHMAXC0PatchesFileName, this),
00105 itsCUDAHMAXStoredC1PatchesFile(&OPT_ITCUDAHMAXC1PatchesFileName, this)
00106 {
00107
00108 }
00109
00110
00111 void InferoTemporalCudaHmax::start1()
00112 {
00113
00114 if(itsHMAXStoredPatchesDir.getVal().compare("") != 0) {
00115 LFATAL("This option is not valid for CUDA based Hmax use --it-cudahmax-c1patches-filename instead");
00116 }
00117
00118 if(itsCUDAHMAXStoredC0PatchesFile.getVal().compare("") == 0) {
00119 LFATAL("Must specify filename containing C0 Patches using --it-cudahmax-c0patches-filename");
00120 }
00121 if(itsCUDAHMAXStoredC1PatchesFile.getVal().compare("") == 0) {
00122 LFATAL("Must specify filename containing C1 Patches using --it-cudahmax-c1patches-filename");
00123 }
00124
00125
00126 hmax.loadC0(itsCUDAHMAXStoredC0PatchesFile.getVal());
00127 hmax.loadC1(itsCUDAHMAXStoredC1PatchesFile.getVal());
00128 InferoTemporal::start1();
00129 }
00130
00131
00132
00133 InferoTemporalCudaHmax::~InferoTemporalCudaHmax()
00134 {}
00135
00136
00137
00138 std::vector<float> InferoTemporalCudaHmax::_convertFeatureVector(float *c2Res, int numC2)
00139 {
00140 std::vector<float> ret;
00141
00142 for(int i=0;i<numC2;i++) {
00143 ret.push_back(c2Res[i]);
00144 }
00145 return ret;
00146 }
00147
00148 void InferoTemporalCudaHmax::_freeFeatureVector(float *c2Res)
00149 {
00150 }
00151
00152
00153 void InferoTemporalCudaHmax::_freeFeatureVector(float **c2Res)
00154 {
00155
00156 }
00157
00158 std::vector<float> InferoTemporalCudaHmax::_convertFeatureVector(float **c2Res)
00159 {
00160
00161 std::vector<float> ignore;
00162 LFATAL("Should never call this convertFeatureVector()");
00163 return ignore;
00164 }
00165
00166 std::vector<float> InferoTemporalCudaHmax::calculateFeatureVector(Image<float> objImg)
00167 {
00168
00169 float *c2Res;
00170 int numC2;
00171
00172 hmax.getC2(objImg.getArrayPtr(),objImg.getWidth(),objImg.getHeight());
00173 c2Res = hmax.getC2Features();
00174 numC2 = hmax.numC2Features();
00175 std::vector<float> ret = _convertFeatureVector(c2Res,numC2);
00176 hmax.clearC2();
00177
00178 return ret;
00179 }
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190