Selaa lähdekoodia

more efficient implementation

Sven Sickert 10 vuotta sitten
vanhempi
commit
d810876a71

+ 2 - 1
classifier/fpclassifier/randomforest/DTBObliqueLS.cpp

@@ -176,7 +176,8 @@ void DTBObliqueLS::getDataAndLabel(
         const pair<int, Example> & p = examples[*si];
         const Example & ex = p.second;
 
-        NICE::Vector pixelRepr = f->getFeatureVector( &ex );
+        NICE::Vector pixelRepr (amountParams, 1.0);
+        f->getFeatureVector( &ex, pixelRepr );
 
         double label = p.first;
         pixelRepr *= ex.weight;

+ 18 - 22
features/fpfeatures/ConvolutionFeature.cpp

@@ -120,12 +120,13 @@ NICE::Vector ConvolutionFeature::getParameterVector() const
 }
 
 /** return feature vector */
-NICE::Vector ConvolutionFeature::getFeatureVector( const Example *example ) const
+void ConvolutionFeature::getFeatureVector(
+        const Example *example,
+        NICE::Vector & vec ) const
 {
-    NICE::Vector vec(paramsLength, 1.0);
-
     NICE::MultiChannelImageT<double> * imgD = NULL;
     imgD = & example->ce->getDChannel( CachedExample::D_EOH );
+    double** data = imgD->getDataPointer();
 
     int xsize, ysize;
     example->ce->getImageSize( xsize, ysize );
@@ -134,27 +135,22 @@ NICE::Vector ConvolutionFeature::getFeatureVector( const Example *example ) cons
     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;
+    //const int step = window_size_x*window_size_y;
 
     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 < vec.size() )
+    for ( int c = 0; c < numChannels; c++)
+        for ( int v = -halfwsy; v <= halfwsy; v++ )
+            for ( int u = -halfwsx; u <= halfwsx; u++, k++ )
             {
-                for ( int c = 0; c < numChannels; c++)
-                    vec[k+c*step] = imgD->get(x+uu,y+vv,c);
+                int uu = u;
+                int vv = v;
+                if (x+u < 0 || x+u >= xsize) uu=-u;
+                if (y+v < 0 || y+v >= ysize) vv=-v;
+
+                //vec[k] = imgD->get(x+uu,y+vv,c);
+                vec[k] = data[c][(x+uu)+(y+vv)*xsize];
+
             }
-        }
 
     if (useSpatialPriors)
     {
@@ -162,7 +158,6 @@ NICE::Vector ConvolutionFeature::getFeatureVector( const Example *example ) cons
         vec[paramsLength-1] = (double)y/(double)ysize;
     }
 
-    return vec;
 }
 
 /** return length of parameter vector */
@@ -217,7 +212,8 @@ double ConvolutionFeature::val ( const Example *example ) const
         return val1;
     }
 
-    NICE::Vector featVec = getFeatureVector ( example );
+    NICE::Vector featVec (paramsLength, 1.0);
+    getFeatureVector ( example, featVec );
 
 //    for ( int i = 0; i < featVec.size(); i++ )
 //        val1 += featVec[i] * params->operator [](i);

+ 2 - 2
features/fpfeatures/ConvolutionFeature.h

@@ -88,9 +88,9 @@ class ConvolutionFeature : public Feature
     /**
      * @brief return feature vector
      * @param example current example
-     * @return feature vector
+     * @param returned feature vector
      */
-    NICE::Vector getFeatureVector ( const Example *example ) const;
+    void getFeatureVector ( const Example *example, NICE::Vector &vec ) const;
 
     /**
      * @brief return length of parameter vector