فهرست منبع

removed redundant code

Sven Sickert 10 سال پیش
والد
کامیت
e4554d2b18
2فایلهای تغییر یافته به همراه43 افزوده شده و 75 حذف شده
  1. 41 73
      features/fpfeatures/ConvolutionFeature.cpp
  2. 2 2
      features/fpfeatures/ConvolutionFeature.h

+ 41 - 73
features/fpfeatures/ConvolutionFeature.cpp

@@ -15,9 +15,9 @@ using namespace OBJREC;
 
 using namespace NICE;
 
-/* Convolutional feature consists of shift parameter beta[0] and the
+/* Convolutional feature consists of shift parameter params[0] and the
    convolutional mask, which is stored in the rest of the parameter vector
-   beta */
+   params */
 
 
 /** simple constructor */
@@ -63,17 +63,17 @@ ConvolutionFeature::ConvolutionFeature ( const ConvolutionFeature *confFeat )
 {
     window_size_x = confFeat->window_size_x;
     window_size_y = confFeat->window_size_y;
-    betaLength = confFeat->betaLength;
+    paramsLength = confFeat->paramsLength;
     isColor = confFeat->isColor;
     useSpatialPriors = confFeat->useSpatialPriors;
     numChannels = confFeat->numChannels;
-    beta = new NICE::Vector( betaLength, 0.0 );
+    params = new NICE::Vector( paramsLength, 0.0 );
 
     int i = 0;
-    for ( NICE::Vector::iterator it = confFeat->beta->begin();
-          it != confFeat->beta->end(); ++it, i++ )
+    for ( NICE::Vector::iterator it = confFeat->params->begin();
+          it != confFeat->params->end(); ++it, i++ )
     {
-        beta[i] = *it;
+        params[i] = *it;
     }
 }
 
@@ -94,12 +94,12 @@ void ConvolutionFeature::initializeParameterVector()
         else
             numChannels = 1;
 
-        betaLength = numChannels*window_size_x*window_size_y + 1;
+        paramsLength = numChannels*window_size_x*window_size_y + 1;
 
-        if (useSpatialPriors) betaLength += 2;
+        if (useSpatialPriors) paramsLength += 2;
 
-        beta = new NICE::Vector( betaLength, (1.0/(double)(betaLength-1) ) );
-        beta[0] = 1;
+        params = new NICE::Vector( paramsLength, (1.0/(double)(paramsLength-1) ) );
+        params[0] = 1;
     }
     else
         std::cerr << "ConvolutionFeature::initializeVector: Size of window is Zero! Could not initialize..."
@@ -114,14 +114,14 @@ bool ConvolutionFeature::isColorMode() const
 /** return parameter vector */
 NICE::Vector ConvolutionFeature::getParameterVector() const
 {
-    NICE::Vector res = (*this->beta);
+    NICE::Vector res = (*this->params);
     return res;
 }
 
 /** return feature vector */
 NICE::Vector ConvolutionFeature::getFeatureVector( const Example *example ) const
 {
-    NICE::Vector vec(betaLength, 1.0);
+    NICE::Vector vec(paramsLength, 1.0);
 
     NICE::MultiChannelImageT<double> * imgD = NULL;
     imgD = & example->ce->getDChannel( CachedExample::D_EOH );
@@ -157,8 +157,8 @@ NICE::Vector ConvolutionFeature::getFeatureVector( const Example *example ) cons
 
     if (useSpatialPriors)
     {
-        vec[betaLength-2] = (double)x/(double)xsize;
-        vec[betaLength-1] = (double)y/(double)ysize;
+        vec[paramsLength-2] = (double)x/(double)xsize;
+        vec[paramsLength-1] = (double)y/(double)ysize;
     }
 
     return vec;
@@ -167,37 +167,37 @@ NICE::Vector ConvolutionFeature::getFeatureVector( const Example *example ) cons
 /** return length of parameter vector */
 int ConvolutionFeature::getParameterLength() const
 {
-    return betaLength;
+    return paramsLength;
 }
 
 void ConvolutionFeature::setRandomParameterVector ( )
 {
     srand (time(NULL));
-    for ( NICE::Vector::iterator it = beta->begin();
-          it != beta->end(); ++it )
+    for ( NICE::Vector::iterator it = params->begin();
+          it != params->end(); ++it )
     {
         double b = (double) rand() / (double) RAND_MAX;
         *it = b;
     }
-    beta->normalizeL2();
+    params->normalizeL2();
 }
 
 /** set parameter vector */
 void ConvolutionFeature::setParameterVector( const Vector & vec )
 {
-    if ( beta->size() == vec.size() )
+    if ( params->size() == vec.size() )
     {
         int i = 0;
-        for ( NICE::Vector::iterator it = beta->begin();
-              it != beta->end(); ++it, i++ )
+        for ( NICE::Vector::iterator it = params->begin();
+              it != params->end(); ++it, i++ )
         {
             *it = vec[i];
         }
-        beta->normalizeL2();
+        params->normalizeL2();
     }
     else
         std::cerr << "ConvolutionFeature::setParameterVector: Vector sizes do not match!"
-                  << " expected: " << beta->size() << ", got: " << vec.size()
+                  << " expected: " << params->size() << ", got: " << vec.size()
                   << std::endl;
 
 }
@@ -208,7 +208,7 @@ double ConvolutionFeature::val ( const Example *example ) const
     double val1 = 0.0;
 
     // is parameter vector and image data available?
-    if (beta == NULL)
+    if (params == NULL)
     {
         std::cerr << "ConvolutionalFeature::val: Missing parameter vector!"
                   << std::endl;
@@ -216,43 +216,11 @@ double ConvolutionFeature::val ( const Example *example ) const
         return val1;
     }
 
-    NICE::MultiChannelImageT<double> * imgD = NULL;
-    imgD = & example->ce->getDChannel( CachedExample::D_EOH );
-
-    int xsize, ysize;
-    example->ce->getImageSize( xsize, ysize );
-
-    const int x = example->x;
-    const int y = example->y;
-    const int halfwsx = std::floor ( window_size_x / 2 );
-    const int halfwsy = std::floor ( window_size_y / 2 );
-    const int step = window_size_x*window_size_y;
+    NICE::Vector featVec = getFeatureVector ( example );
 
-    int k = 1;
-    for ( int v = -halfwsy; v <= halfwsy; v++ )
-        for ( int u = -halfwsx; u <= halfwsx; u++, k++ )
-        {
-            int uu = u;
-            int vv = v;
-            if (x+u < 0 || x+u >= xsize) uu=-u;
-            if (y+v < 0 || y+v >= ysize) vv=-v;
-
-            if ( x+uu > 0
-                 && x+uu < xsize
-                 && y+vv > 0
-                 && y+vv < ysize
-                 && k < beta->size() )
-            {
-                for ( int c = 0; c < numChannels; c++ )
-                    val1 += imgD->get(x+uu,y+vv,c) * beta->operator [](k + c*step);
-            }
-        }
-
-    if (useSpatialPriors)
-    {
-        val1 += (double)x/(double)xsize * beta->operator [](betaLength-2);
-        val1 += (double)y/(double)ysize * beta->operator [](betaLength-1);
-    }
+//    for ( int i = 0; i < featVec.size(); i++ )
+//        val1 += featVec[i] * params->operator [](i);
+    val1 = params->scalarProduct ( featVec );
 
     return val1;
 }
@@ -278,7 +246,7 @@ Feature *ConvolutionFeature::clone ( ) const
                 this->isColor,
                 this->useSpatialPriors );
 
-    f->setParameterVector( *beta );
+    f->setParameterVector( *params );
 
     return f;
 }
@@ -292,31 +260,31 @@ void ConvolutionFeature::restore ( std::istream & is, int format )
 {
     is >> window_size_x;
     is >> window_size_y;
-    is >> betaLength;
+    is >> paramsLength;
 
     isColor = false;
     useSpatialPriors = false;
     numChannels = 1;
 
-    if ( betaLength == (window_size_x*window_size_y+3) )
+    if ( paramsLength == (window_size_x*window_size_y+3) )
     {
         useSpatialPriors = true;
     }
-    else if ( betaLength == (3*window_size_x*window_size_y+1) )
+    else if ( paramsLength == (3*window_size_x*window_size_y+1) )
     {
         isColor = true;
         numChannels = 3;
     }
-    else if ( betaLength == (3*window_size_x*window_size_y+3) )
+    else if ( paramsLength == (3*window_size_x*window_size_y+3) )
     {
         isColor = true;
         numChannels = 3;
         useSpatialPriors = true;
     }
 
-    beta = new NICE::Vector( betaLength, 1.0 );
-    for ( NICE::Vector::iterator it = beta->begin();
-          it != beta->end(); ++it )
+    params = new NICE::Vector( paramsLength, 1.0 );
+    for ( NICE::Vector::iterator it = params->begin();
+          it != params->end(); ++it )
         is >> *it;
 }
 
@@ -325,15 +293,15 @@ void ConvolutionFeature::store ( std::ostream & os, int format ) const
     os << "ConvolutionFeature "
        << window_size_x << " "
        << window_size_y << " "
-       << betaLength;
+       << paramsLength;
 
-    for ( NICE::Vector::const_iterator it = beta->begin();
-          it != beta->end(); ++it )
+    for ( NICE::Vector::const_iterator it = params->begin();
+          it != params->end(); ++it )
         os << ' ' << *it;
 
 }
 
 void ConvolutionFeature::clear ()
 {
-    beta->clear();
+    params->clear();
 }

+ 2 - 2
features/fpfeatures/ConvolutionFeature.h

@@ -32,12 +32,12 @@ class ConvolutionFeature : public Feature
     /** feature parameter */
     int window_size_x;
     int window_size_y;
-    int betaLength;
+    int paramsLength;
     int numChannels;
     bool isColor;
     bool useSpatialPriors;
 
-    NICE::Vector *beta;
+    NICE::Vector *params;
 
     /**
      * @brief (re)initialize parameter vector