Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/vl feat compliance3 #133

Open
wants to merge 34 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
0b75276
[popsift] improve docs and options
Oct 16, 2020
ed60e19
[bugfix] fix bug in L2 normalization
Oct 16, 2020
b13d259
[cosmetic] improve normalize_histogram
Oct 16, 2020
2956630
[popsift] change orientation computation to get closer to VLFeat
Oct 16, 2020
7be0e89
[popsift] add VLFeat-like descriptor extraction
Oct 16, 2020
5a295bb
[popsift] vlfeat descriptor area corrected
Mar 6, 2021
f815fbb
[popsift] speedup vlfeat descriptor
Mar 7, 2021
bb901d7
[popsift] configuration to ignore edge and peak thresholds
Feb 14, 2021
b1b4b92
[popsift] use ManagedMemory for ExtremaCounters and buffers
Feb 19, 2021
9a21d43
[popsift] simplify grid filtering with managed mem
Feb 20, 2021
41a34fd
[popsift] update demo prog usage for new grid filter
Feb 26, 2021
c21d399
[popsift] move InitialExtremum to own file, clean up
Feb 27, 2021
79de1d5
[popsift] simplify extrema prefix sum in ExtremaCounters
Feb 28, 2021
7840b89
[testing] scripted comparison with vlfeat
Mar 7, 2021
45247e7
[testing] more flexible mode comparison script
Feb 27, 2021
9ed7e69
[popsift] introduce CUDA cooperative groups
Mar 9, 2021
46c63a6
[testing] minor speed improvements by manually finding min1/min2
Mar 10, 2021
9e8fc3e
Merge branch 'feature/compareScripts' into test
Mar 10, 2021
b08231c
Merge branch 'wip/managedMemDescriptors' into test
Mar 11, 2021
030da06
[debug] moved kernels out of namespace to make profiling possible
Mar 16, 2021
004685e
Merge branch 'develop' into mergeBase
Jul 2, 2021
116eb25
[feature] FeaturesDev::matchAndReturn gives you brute-forced matches …
Jul 2, 2021
c992910
[demo] popsift-match changed for CPU-size match printing
Jul 2, 2021
a893f43
[popsift] use CPU-side sorting in filtergrid
Sep 28, 2021
9f78dc5
[filtergrid] allow case 1x1 filter grid
Oct 1, 2021
eb92700
[filtergrid] generalize prefix sum of initial extrema count
Oct 1, 2021
60def0e
[filtergrid] detailed debugging added
Oct 1, 2021
bb41846
[cuda] found the filtergrid bug
Oct 11, 2021
752e88b
[cuda] remove the filtergrid debug output
Oct 11, 2021
b804c05
[thrust] use thrust by default in filtergrid
Oct 11, 2021
1e074cf
merged develop
Oct 11, 2021
ed12e2c
[thrust] add include apparently required by some
Oct 11, 2021
f9ba274
[doc] update changelog
simogasp Jul 28, 2022
604295a
[doc] fix changelog
simogasp Jul 28, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Support for Cuda CC 7 cards (RTX 2080) [PR](https://github.com/alicevision/popsift/pull/67)
- Support for Boost 1.70 [PR](https://github.com/alicevision/popsift/pull/65)
- Support for device selection and multiple GPUs [PR](https://github.com/alicevision/popsift/pull/121)
- Test: adding descriptor comparator [PR](https://github.com/alicevision/popsift/pull/133)
- Support descriptor computation compliant with VLFeat [PR](https://github.com/alicevision/popsift/pull/133)
- Support for ignoring Edge and Peak Thresholds [PR](https://github.com/alicevision/popsift/pull/133)
- Support for grid filtering on CUDA Managed Memory and sorting initial extrema on the CPU side [PR](https://github.com/alicevision/popsift/pull/133)

### Fixed
- CMake: fixes to allow building on Windows using vcpkg [PR](https://github.com/alicevision/popsift/pull/92)
- Fix race condition [PR](https://github.com/alicevision/popsift/pull/82)
- Fixed a bug in L2 normalization [PR](https://github.com/alicevision/popsift/pull/133)

### Changed
- Improved resource releasing [PR](https://github.com/alicevision/popsift/pull/71)
Expand Down
8 changes: 6 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ if(MSVC)
list(APPEND CUDA_NVCC_FLAGS -Xcompiler ${PopSift_MVSC_LINKER})
endif()

list(APPEND CUDA_NVCC_FLAGS "-lineinfo")

# default stream per-thread implies that each host thread has one non-synchronizing 0-stream
# currently, the code requires legacy mode
list(APPEND CUDA_NVCC_FLAGS "--default-stream;legacy")
Expand Down Expand Up @@ -181,9 +183,11 @@ else()
endif()

if(CUDA_VERSION VERSION_GREATER_EQUAL "9.0")
set(HAVE_SHFL_DOWN_SYNC 1)
set(PopSift_HAVE_SHFL_DOWN_SYNC 1)
set(PopSift_HAVE_COOPERATIVE_GROUPS 1)
else()
set(HAVE_SHFL_DOWN_SYNC 0)
set(PopSift_HAVE_SHFL_DOWN_SYNC 0)
set(PopSift_HAVE_COOPERATIVE_GROUPS 0)
endif()

if(NOT PopSift_USE_GRID_FILTER)
Expand Down
12 changes: 7 additions & 5 deletions cmake/sift_config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@

#pragma once

#define POPSIFT_IS_DEFINED(F) F() == 1
#define POPSIFT_IS_DEFINED(F) F() == 1
#define POPSIFT_IS_UNDEFINED(F) F() == 0

#define POPSIFT_HAVE_SHFL_DOWN_SYNC() @HAVE_SHFL_DOWN_SYNC@
#define POPSIFT_HAVE_NORMF() @PopSift_HAVE_NORMF@
#define POPSIFT_DISABLE_GRID_FILTER() @DISABLE_GRID_FILTER@
#define POPSIFT_USE_NVTX() @PopSift_USE_NVTX@
#define POPSIFT_HAVE_SHFL_DOWN_SYNC() @PopSift_HAVE_SHFL_DOWN_SYNC@
#define POPSIFT_HAVE_NORMF() @PopSift_HAVE_NORMF@
#define POPSIFT_DISABLE_GRID_FILTER() @DISABLE_GRID_FILTER@
#define POPSIFT_USE_NVTX() @PopSift_USE_NVTX@
#define POPSIFT_HAVE_COOPERATIVE_GROUPS() @PopSift_HAVE_COOPERATIVE_GROUPS@


9 changes: 8 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ CUDA_ADD_LIBRARY(popsift
popsift/sift_constants.cu popsift/sift_constants.h
popsift/sift_conf.cu popsift/sift_conf.h
popsift/gauss_filter.cu popsift/gauss_filter.h
popsift/filtergrid.cu popsift/filtergrid.h
popsift/initial_extremum.h
popsift/s_image.cu popsift/s_image.h
popsift/sift_pyramid.cu popsift/sift_pyramid.h
popsift/sift_octave.cu popsift/sift_octave.h
Expand All @@ -16,17 +18,18 @@ CUDA_ADD_LIBRARY(popsift
popsift/sift_extremum.h
popsift/sift_extremum.cu popsift/s_extrema.cu
popsift/s_orientation.cu
popsift/s_filtergrid.cu
popsift/sift_desc.cu
popsift/s_desc_loop.cu popsift/s_desc_loop.h
popsift/s_desc_iloop.cu popsift/s_desc_iloop.h
popsift/s_desc_grid.cu popsift/s_desc_grid.h
popsift/s_desc_igrid.cu popsift/s_desc_igrid.h
popsift/s_desc_notile.cu popsift/s_desc_notile.h
popsift/s_desc_vlfeat.cu popsift/s_desc_vlfeat.h
popsift/s_desc_norm_rs.h
popsift/s_desc_norm_l2.h
popsift/s_desc_normalize.h
popsift/s_gradiant.h
popsift/s_gradiant_cuda9plus.h
popsift/s_solve.h
popsift/common/assist.cu popsift/common/assist.h
popsift/common/clamp.h
Expand Down Expand Up @@ -149,3 +152,7 @@ if(PopSift_BUILD_EXAMPLES)
add_subdirectory(application)
endif()

if(PopSift_USE_TEST_CMD)
add_subdirectory(compareSiftFiles)
endif()

4 changes: 2 additions & 2 deletions src/application/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ endif(PopSift_USE_NVTX_PROFILING)
# popsift-demo
#############################################################

add_executable(popsift-demo main.cpp pgmread.cpp pgmread.h)
add_executable(popsift-demo main.cpp pgmread.cpp pgmread.h common_opt.cpp)

set_property(TARGET popsift-demo PROPERTY CXX_STANDARD 11)

Expand All @@ -82,7 +82,7 @@ target_link_libraries(popsift-demo PUBLIC PopSift::popsift ${PD_LINK_LIBS})
# popsift-match
#############################################################

add_executable(popsift-match match.cpp pgmread.cpp pgmread.h)
add_executable(popsift-match match.cpp pgmread.cpp pgmread.h common_opt.cpp)

set_property(TARGET popsift-match PROPERTY CXX_STANDARD 11)

Expand Down
111 changes: 111 additions & 0 deletions src/application/common_opt.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/*
* Copyright 2021, University of Oslo
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include "common_opt.h"

// #include <popsift/common/device_prop.h>
// #include <popsift/features.h>
// #include <popsift/popsift.h>
// #include <popsift/sift_config.h>
// #include <popsift/version.hpp>

// #include <boost/filesystem.hpp>

// #include <cmath>
// #include <cstdlib>
// #include <fstream>
// #include <iomanip>
// #include <iostream>
// #include <list>
// #include <sstream>
// #include <stdexcept>
#include <string>

using namespace std;
using namespace boost::program_options;

void option_init_parameters( popsift::Config& config, options_description& parameters )
{
parameters.add_options()
("octaves",
value<int>(&config.octaves)->default_value(config.getOctaves()),
"Number of octaves")
("levels",
value<int>(&config.levels)->default_value(config.getLevels()),
"Number of levels per octave")
("sigma",
value<float>()->notifier([&](float f) { config.setSigma(f); })->default_value(config.getSigma()),
"Initial sigma value")
("threshold",
value<float>()->notifier([&](float f) { config.setThreshold(f); })->default_value(config.getThreshold()),
popsift::Config::getPeakThreshUsage().c_str() )
("edge-threshold",
value<float>()->notifier([&](float f) { config.setEdgeLimit(f); })->default_value(config.getEdgeLimit()),
popsift::Config::getEdgeThreshUsage().c_str() )
("edge-limit",
value<float>()->notifier([&](float f) { config.setEdgeLimit(f); }),
"synonym to --edge-threshold" )
("downsampling",
value<float>()->notifier([&](float f) { config.setDownsampling(f); })->default_value(config.getDownsampling()),
"Downscale width and height of input by 2^N")
("initial-blur",
value<float>()->notifier([&](float f) {config.setInitialBlur(f); })->default_value(config.getInitialBlur()),
"Assume initial blur, subtract when blurring first time");
}

void option_init_modes( popsift::Config& config, options_description& modes )
{
modes.add_options()
( "gauss-mode",
value<std::string>()->notifier([&](const std::string& s) { config.setGaussMode(s); }),
popsift::Config::getGaussModeUsage() )
// "Choice of span (1-sided) for Gauss filters. Default is VLFeat-like computation depending on sigma. "
// "Options are: vlfeat, relative, relative-all, opencv, fixed9, fixed15"
( "desc-mode",
value<std::string>()->notifier([&](const std::string& s) { config.setDescMode(s); }),
popsift::Config::getDescModeUsage() )
( "popsift-mode",
bool_switch()->notifier([&](bool b) { if(b) config.setMode(popsift::Config::PopSift); }),
"During the initial upscale, shift pixels by 1. In extrema refinement, steps up to 0.6, do not reject points when reaching max iterations, "
"first contrast threshold is .8 * peak thresh. Shift feature coords octave 0 back to original pos.")
( "vlfeat-mode",
bool_switch()->notifier([&](bool b) { if(b) config.setMode(popsift::Config::VLFeat); }),
"During the initial upscale, shift pixels by 1. That creates a sharper upscaled image. "
"In extrema refinement, steps up to 0.6, levels remain unchanged, "
"do not reject points when reaching max iterations, "
"first contrast threshold is .8 * peak thresh.")
( "opencv-mode",
bool_switch()->notifier([&](bool b) { if(b) config.setMode(popsift::Config::OpenCV); }),
"During the initial upscale, shift pixels by 0.5. "
"In extrema refinement, steps up to 0.5, "
"reject points when reaching max iterations, "
"first contrast threshold is floor(.5 * peak thresh). "
"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.")
( "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() )
( "root-sift",
bool_switch()->notifier([&](bool b) { if(b) config.setNormMode(popsift::Config::RootSift); }),
"synonym to --norm-mode=RootSift" )
( "filter-max-extrema",
value<int>()->notifier([&](int f) {config.setFilterMaxExtrema(f); }),
"Approximate max number of extrema.")
( "filter-grid",
value<int>()->notifier([&](int f) {config.setFilterGridSize(f); }),
"Grid edge length for extrema filtering (ie. value 4 leads to a 4x4 grid)")
( "filter-sort",
value<std::string>()->notifier([&](const std::string& s) {config.setFilterSorting(s); }),
popsift::Config::getFilterGridModeUsage() );

}

18 changes: 18 additions & 0 deletions src/application/common_opt.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright 2021, University of Oslo
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#pragma once

#include <boost/program_options.hpp>

#include <popsift/sift_conf.h>

void option_init_parameters( popsift::Config& config,
boost::program_options::options_description& parameters );
void option_init_modes( popsift::Config& config,
boost::program_options::options_description& modes );

60 changes: 10 additions & 50 deletions src/application/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <devil_cpp_wrapper.hpp>
#endif
#include "pgmread.h"
#include "common_opt.h"

#if POPSIFT_IS_DEFINED(POPSIFT_USE_NVTX)
#include <nvToolsExtCuda.h>
Expand All @@ -42,6 +43,7 @@ using namespace std;
static bool print_dev_info = false;
static bool print_time_info = false;
static bool write_as_uchar = false;
static bool write_with_ori = false;
static bool dont_write = false;
static bool pgmread_loading = false;
static bool float_mode = false;
Expand All @@ -59,57 +61,13 @@ static void parseargs(int argc, char** argv, popsift::Config& config, string& in
("input-file,i", value<std::string>(&inputFile)->required(), "Input file");

}

options_description parameters("Parameters");
{
parameters.add_options()
("octaves", value<int>(&config.octaves), "Number of octaves")
("levels", value<int>(&config.levels), "Number of levels per octave")
("sigma", value<float>()->notifier([&](float f) { config.setSigma(f); }), "Initial sigma value")

("threshold", value<float>()->notifier([&](float f) { config.setThreshold(f); }), "Contrast threshold")
("edge-threshold", value<float>()->notifier([&](float f) { config.setEdgeLimit(f); }), "On-edge threshold")
("edge-limit", value<float>()->notifier([&](float f) { config.setEdgeLimit(f); }), "On-edge threshold")
("downsampling", value<float>()->notifier([&](float f) { config.setDownsampling(f); }), "Downscale width and height of input by 2^N")
("initial-blur", value<float>()->notifier([&](float f) {config.setInitialBlur(f); }), "Assume initial blur, subtract when blurring first time");
}
options_description modes("Modes");
{
modes.add_options()
( "gauss-mode", value<std::string>()->notifier([&](const std::string& s) { config.setGaussMode(s); }),
popsift::Config::getGaussModeUsage() )
// "Choice of span (1-sided) for Gauss filters. Default is VLFeat-like computation depending on sigma. "
// "Options are: vlfeat, relative, relative-all, opencv, fixed9, fixed15"
("desc-mode", value<std::string>()->notifier([&](const std::string& s) { config.setDescMode(s); }),
"Choice of descriptor extraction modes:\n"
"loop, iloop, grid, igrid, notile\n"
"Default is loop\n"
"loop is OpenCV-like horizontal scanning, computing only valid points, grid extracts only useful points but rounds them, iloop uses linear texture and rotated gradiant fetching. igrid is grid with linear interpolation. notile is like igrid but avoids redundant gradiant fetching.")
("popsift-mode", bool_switch()->notifier([&](bool b) { if(b) config.setMode(popsift::Config::PopSift); }),
"During the initial upscale, shift pixels by 1. In extrema refinement, steps up to 0.6, do not reject points when reaching max iterations, "
"first contrast threshold is .8 * peak thresh. Shift feature coords octave 0 back to original pos.")
("vlfeat-mode", bool_switch()->notifier([&](bool b) { if(b) config.setMode(popsift::Config::VLFeat); }),
"During the initial upscale, shift pixels by 1. That creates a sharper upscaled image. "
"In extrema refinement, steps up to 0.6, levels remain unchanged, "
"do not reject points when reaching max iterations, "
"first contrast threshold is .8 * peak thresh.")
("opencv-mode", bool_switch()->notifier([&](bool b) { if(b) config.setMode(popsift::Config::OpenCV); }),
"During the initial upscale, shift pixels by 0.5. "
"In extrema refinement, steps up to 0.5, "
"reject points when reaching max iterations, "
"first contrast threshold is floor(.5 * peak thresh). "
"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.")
("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() )
( "root-sift", bool_switch()->notifier([&](bool b) { if(b) config.setNormMode(popsift::Config::RootSift); }),
popsift::Config::getNormModeUsage() )
("filter-max-extrema", value<int>()->notifier([&](int f) {config.setFilterMaxExtrema(f); }), "Approximate max number of extrema.")
("filter-grid", value<int>()->notifier([&](int f) {config.setFilterGridSize(f); }), "Grid edge length for extrema filtering (ie. value 4 leads to a 4x4 grid)")
("filter-sort", value<std::string>()->notifier([&](const std::string& s) {config.setFilterSorting(s); }), "Sort extrema in each cell by scale, either random (default), up or down");

}
option_init_parameters( config, parameters );
option_init_modes( config, modes );

options_description informational("Informational");
{
informational.add_options()
Expand All @@ -118,6 +76,7 @@ static void parseargs(int argc, char** argv, popsift::Config& config, string& in
("print-time-info", bool_switch(&print_time_info)->default_value(false), "A debug output printing image processing time after load()")
("write-as-uchar", bool_switch(&write_as_uchar)->default_value(false), "Output descriptors rounded to int.\n"
"Scaling to sensible ranges is not automatic, should be combined with --norm-multi=9 or similar")
("write-with-ori", bool_switch(&write_with_ori)->default_value(false), "Output points are written with sigma and orientation.\n")
("dont-write", bool_switch(&dont_write)->default_value(false), "Suppress descriptor output")
("pgmread-loading", bool_switch(&pgmread_loading)->default_value(false), "Use the old image loader instead of LibDevIL")
("float-mode", bool_switch(&float_mode)->default_value(false), "Upload image to GPU as float instead of byte")
Expand Down Expand Up @@ -254,7 +213,7 @@ void read_job( SiftJob* job, bool really_write )
nvtxRangePushA( "Writing features to disk" );

std::ofstream of( "output-features.txt" );
feature_list->print( of, write_as_uchar );
feature_list->print( of, write_as_uchar, write_with_ori );
}
delete feature_list;

Expand All @@ -273,6 +232,8 @@ int main(int argc, char **argv)

std::cout << "PopSift version: " << POPSIFT_VERSION_STRING << std::endl;

config.setDescMode( popsift::Config::VLFeat_Desc );

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not a problem with your changes but it would be better to add an else branch in the check for the file to exist at line 246 below:

    if( boost::filesystem::exists( inputFile ) ) {
        if( boost::filesystem::is_directory( inputFile ) ) {
            cout << "BOOST " << inputFile << " is directory" << endl;
            collectFilenames( inputFiles, inputFile );
            if( inputFiles.empty() ) {
                cerr << "No files in directory, nothing to do" << endl;
                return EXIT_SUCCESS;
            }
        } else if( boost::filesystem::is_regular_file( inputFile ) ) {
            inputFiles.push_back( inputFile );
        } else {
            cout << "Input file is neither regular file nor directory, nothing to do" << endl;
            return EXIT_FAILURE;
        }
    }
+    else 
+    {
+        cout << "Input file/directory does not exist" << endl;
+        return EXIT_FAILURE;
+    }

so that the program exits if the input does not exist

try {
parseargs( argc, argv, config, inputFile ); // Parse command line
std::cout << inputFile << std::endl;
Expand Down Expand Up @@ -327,4 +288,3 @@ int main(int argc, char **argv)

return EXIT_SUCCESS;
}