Skip to content

Commit

Permalink
[popsift] remove failed interpolating orientation code
Browse files Browse the repository at this point in the history
  • Loading branch information
Carsten Griwodz committed Oct 16, 2020
1 parent bd1c8ef commit 74f7053
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 200 deletions.
2 changes: 0 additions & 2 deletions src/application/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,6 @@ static void parseargs(int argc, char** argv, popsift::Config& config, string& in
"Computed filter width are lower than VLFeat/PopSift")
("direct-scaling", bool_switch()->notifier([&](bool b) { if(b) config.setScalingMode(popsift::Config::ScaleDirect); }),
"Direct each octave from upscaled orig instead of blurred level.")
( "ori-mode", value<std::string>()->notifier([&](const std::string& s) {config.setOrientationMode(s); }),
popsift::Config::getOrientationModeUsage() )
("norm-multi", value<int>()->notifier([&](int i) {config.setNormalizationMultiplier(i); }), "Multiply the descriptor by pow(2,<int>).")
( "norm-mode", value<std::string>()->notifier([&](const std::string& s) { config.setNormMode(s); }),
popsift::Config::getNormModeUsage() )
Expand Down
146 changes: 32 additions & 114 deletions src/popsift/s_orientation.cu
Original file line number Diff line number Diff line change
Expand Up @@ -45,101 +45,11 @@ float smoothe( const float* const src, const int bin )
return f;
}

class BestBin
{
public:
__device__ inline static
void fillHist( float* hist, const float weight, const float theta )
{
int bidx = (int)roundf( __fdividef( float(ORI_NBINS) * (theta + M_PI), M_PI2 ) );

while( bidx < 0 ) bidx += ORI_NBINS;
while( bidx >= ORI_NBINS ) bidx -= ORI_NBINS;

atomicAdd( &hist[bidx], weight );
}

__device__ inline static
void refine( int bin, float* hist, float maxval, float& angle, float& val )
{
const int prev = ( bin - 1 + ORI_NBINS ) % ORI_NBINS;
const int next = ( bin + 1 ) % ORI_NBINS;

bool predicate = ( bin < ORI_NBINS ) &&
( hist[bin] > max( hist[prev], hist[next] ) ) &&
( hist[bin] > 0.8f * maxval );

const float num = predicate ? 3.0f * hist[prev]
- 4.0f * hist[bin]
+ 1.0f * hist[next]
: 0.0f;
const float denB = predicate ? 2.0f * ( hist[prev] - 2.0f * hist[bin] + hist[next] ) : 1.0f;

const float newbin = __fdividef( num, denB ); // verified: accuracy OK

angle = predicate ? prev + newbin : -1;
val = predicate ? -(num*num) / (4.0f * denB) + hist[prev] : -INFINITY;
}

__device__ inline static
float twist( float angle )
{
angle -= M_PI;
if( angle < 0 ) angle += M_PI2;
return angle;
}
};

class InterpolatedBin
{
public:
__device__ inline static
void fillHist( float* hist, const float weight, const float theta )
{
const float fbin = float(ORI_NBINS) / M_PI2 * theta;
const int bin = (int)floorf(fbin - 0.5f);
const float rbin = fbin - bin - 0.5f;

int bin1 = ( bin + ORI_NBINS ) % ORI_NBINS;
atomicAdd( &hist[bin1], (1.0f - rbin) * weight );
int bin2 = ( bin + 1 ) % ORI_NBINS;
atomicAdd( &hist[bin2], rbin * weight );
}

__device__ inline static
void refine( int bin, float* hist, float maxval, float& angle, float& val )
{
const int prev = ( bin - 1 + ORI_NBINS ) % ORI_NBINS;
const int next = ( bin + 1 ) % ORI_NBINS;

bool predicate = ( bin < ORI_NBINS ) &&
( hist[bin] > max( hist[prev], hist[next] ) ) &&
( hist[bin] > 0.8f * maxval );

const float num = predicate ? hist[next] - hist[prev]
: 0.0f;
const float denB = predicate ? 2.0f * ( hist[prev] - 2.0f * hist[bin] + hist[next] ) : 1.0f;

const float newbin = __fdividef( num, denB ); // verified: accuracy OK

angle = predicate ? bin + newbin + 0.5f : -1;

val = predicate ? -(num*num) / (4.0f * denB) + hist[prev] : -INFINITY;
}

__device__ inline static
float twist( float angle )
{
return angle;
}
};

/*
* Compute the keypoint orientations for each extremum
* using 16 threads for each of them.
* direct curve fitting approach
*/
template<class SB>
__global__
void ori_par( const int octave,
const int ext_ct_prefix_sum,
Expand Down Expand Up @@ -170,7 +80,6 @@ void ori_par( const int octave,

/* orientation histogram radius */
const float sigw = ORI_WINFACTOR * sig;
// const int32_t rad = (int)roundf((3.0f * sigw));
const int32_t rad = max( (int)floorf((3.0f * sigw)), 1 );

const float factor = __fdividef( -0.5f, (sigw * sigw) );
Expand Down Expand Up @@ -216,7 +125,12 @@ void ori_par( const int octave,
{
float weight = grad * expf(sq_dist * factor);

SB::fillHist( hist, weight, theta );
int bidx = (int)roundf( __fdividef( float(ORI_NBINS) * (theta + M_PI), M_PI2 ) );

while( bidx < 0 ) bidx += ORI_NBINS;
while( bidx >= ORI_NBINS ) bidx -= ORI_NBINS;

atomicAdd( &hist[bidx], weight );
}
}
}
Expand Down Expand Up @@ -251,7 +165,23 @@ void ori_par( const int octave,

for( int bin = threadIdx.x; popsift::any( bin < ORI_NBINS ); bin += blockDim.x )
{
SB::refine( bin, sm_hist, maxval, refined_angle[bin], yval[bin] );
const int prev = ( bin - 1 + ORI_NBINS ) % ORI_NBINS;
const int next = ( bin + 1 ) % ORI_NBINS;

bool predicate = ( bin < ORI_NBINS ) &&
( sm_hist[bin] > max( sm_hist[prev], sm_hist[next] ) ) &&
( sm_hist[bin] > 0.8f * maxval );

const float num = predicate ? 3.0f * sm_hist[prev]
- 4.0f * sm_hist[bin]
+ 1.0f * sm_hist[next]
: 0.0f;
const float denB = predicate ? 2.0f * ( sm_hist[prev] - 2.0f * sm_hist[bin] + sm_hist[next] ) : 1.0f;

const float newbin = __fdividef( num, denB ); // verified: accuracy OK

refined_angle[bin] = predicate ? prev + newbin : -1;
yval[bin] = predicate ? -(num*num) / (4.0f * denB) + hist[prev] : -INFINITY;
}
__syncthreads();

Expand All @@ -274,7 +204,8 @@ void ori_par( const int octave,
if( chosen_bin >= ORI_NBINS ) chosen_bin -= ORI_NBINS;
if( chosen_bin < 0 ) chosen_bin += ORI_NBINS;
float th = __fdividef(M_PI2 * chosen_bin , ORI_NBINS); // - M_PI;
th = SB::twist( th );
th -= M_PI;
if( th < 0.0f ) th += M_PI2;
ext->orientation[threadIdx.x] = th;
written = true;
}
Expand Down Expand Up @@ -443,26 +374,13 @@ void Pyramid::orientation( const Config& conf )
block.y = 1;
grid.x = num;

if( conf.getOrientationMode() == Config::BestBin )
{
ori_par<BestBin>
<<<grid,block,4*64*sizeof(float),oct_str>>>
( octave,
hct.ext_ps[octave],
oct_obj.getDataTexPoint( ),
oct_obj.getWidth( ),
oct_obj.getHeight( ) );
}
else
{
ori_par<InterpolatedBin>
<<<grid,block,4*64*sizeof(float),oct_str>>>
( octave,
hct.ext_ps[octave],
oct_obj.getDataTexPoint( ),
oct_obj.getWidth( ),
oct_obj.getHeight( ) );
}
ori_par
<<<grid,block,4*64*sizeof(float),oct_str>>>
( octave,
hct.ext_ps[octave],
oct_obj.getDataTexPoint( ),
oct_obj.getWidth( ),
oct_obj.getHeight( ) );
POP_SYNC_CHK;

if( octave != 0 ) {
Expand Down
37 changes: 0 additions & 37 deletions src/popsift/sift_conf.cu
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ Config::Config( )
, _sift_mode( Config::PopSift )
, _log_mode( Config::None )
, _scaling_mode( Config::ScaleDefault )
, _ori_mode( Config::OriDefault )
, _desc_mode( Config::Loop )
, _grid_filter_mode( Config::RandomScale )
, verbose( false )
Expand Down Expand Up @@ -196,42 +195,6 @@ void Config::setScalingMode( ScalingMode mode )
_scaling_mode = mode;
}

void Config::setOrientationMode( OriMode mode )
{
_ori_mode = mode;
}

void Config::setOrientationMode( const std::string& text )
{
if( stringIsame( text, "BestBin" ) )
{
_ori_mode = BestBin;
}
else if( stringIsame( text, "PopSift" ) )
{
_ori_mode = BestBin;
}
else if( stringIsame( text, "InterpolatedBin" ) )
{
_ori_mode = InterpolatedBin;
}
else if( stringIsame( text, "VLFeat" ) )
{
_ori_mode = InterpolatedBin;
}
else
POP_FATAL( string("Bad Orientation mode.\n") + getOrientationModeUsage() );
}

const char* Config::getOrientationModeUsage( )
{
return
"Choice of orientation computation modes. "
"Options are: "
"BestBin (original PopSift bejaviour, default), "
"InterpolatedBin (VLFeat-like behaviour, experimental, do not use)";
}

/**
* Normalization mode
* Should the descriptor normalization use L2-like classic normalization
Expand Down
47 changes: 0 additions & 47 deletions src/popsift/sift_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,24 +80,6 @@ struct Config
ScaleDefault
};

/**
* @brief PopSift
*/
enum OriMode
{
/** One bin per sample in histogram filling, quadratic angle refinement.
* Original mode using by PopSift.
*/
BestBin,
/** Two bins per sample in histogram filling, simple angle refinement.
* Tries to implement the approach taken by VLFeat. Experimental.
*/
InterpolatedBin,
/// default value
OriDefault = BestBin

};

/**
* @brief Modes for descriptor extraction.
*/
Expand Down Expand Up @@ -193,20 +175,6 @@ struct Config
*/
void setScalingMode( ScalingMode mode = ScaleDefault );

/**
* @brief Set the orientation mode.
* @param mode The orientation mode
* @see OriMode
*/
void setOrientationMode( OriMode mode = BestBin );

/**
* @brief Set the orientation mode.
* @param text string parsed as a legal orientation mode
* @see OriMode
*/
void setOrientationMode( const std::string& text );

/**
* @brief Enable/desable verbose mode.
* @param[in] on Whether to display additional information .
Expand Down Expand Up @@ -388,18 +356,6 @@ struct Config
*/
inline ScalingMode getScalingMode() const { return _scaling_mode; }

/**
* @brief Get the orientation mode.
* @return the orientation mode.
* @see OriMode
*/
inline OriMode getOrientationMode() const { return _ori_mode; }

/**
* @brief Helper functions for the main program's usage string.
*/
static const char* getOrientationModeUsage( );

/**
* @brief Get the descriptor extraction mode
* @return the descriptor extraction mode
Expand Down Expand Up @@ -429,9 +385,6 @@ struct Config
/// default: ScalingMode::DownscaledOctaves
ScalingMode _scaling_mode;

/// default: OriMode::BestBin
OriMode _ori_mode;

/// default: DescMode::Loop
DescMode _desc_mode;

Expand Down

0 comments on commit 74f7053

Please sign in to comment.