{"id":13700466,"url":"https://github.com/Celebrandil/CudaSift","last_synced_at":"2025-05-04T18:35:19.537Z","repository":{"id":9055034,"uuid":"10821793","full_name":"Celebrandil/CudaSift","owner":"Celebrandil","description":"A CUDA implementation of SIFT for NVidia GPUs (1.2 ms on a GTX 1060)","archived":false,"fork":false,"pushed_at":"2023-09-12T18:52:16.000Z","size":6143,"stargazers_count":861,"open_issues_count":39,"forks_count":286,"subscribers_count":41,"default_branch":"Pascal","last_synced_at":"2024-11-13T06:33:22.396Z","etag":null,"topics":["cuda","gpu","nvidia","sift","vision"],"latest_commit_sha":null,"homepage":"","language":"Cuda","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Celebrandil.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2013-06-20T14:38:10.000Z","updated_at":"2024-11-09T09:40:34.000Z","dependencies_parsed_at":"2022-07-21T04:34:54.198Z","dependency_job_id":"4883a771-22c5-421b-bbd9-c287c2c5d455","html_url":"https://github.com/Celebrandil/CudaSift","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Celebrandil%2FCudaSift","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Celebrandil%2FCudaSift/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Celebrandil%2FCudaSift/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Celebrandil%2FCudaSift/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Celebrandil","download_url":"https://codeload.github.com/Celebrandil/CudaSift/tar.gz/refs/heads/Pascal","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252383253,"owners_count":21739296,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cuda","gpu","nvidia","sift","vision"],"created_at":"2024-08-02T20:00:56.919Z","updated_at":"2025-05-04T18:35:14.505Z","avatar_url":"https://github.com/Celebrandil.png","language":"Cuda","funding_links":[],"categories":["Cuda"],"sub_categories":[],"readme":"# CudaSift - SIFT features with CUDA\n\nThis is the fourth version of a SIFT (Scale Invariant Feature Transform) implementation using CUDA for GPUs from NVidia. The first version is from 2007 and GPUs have evolved since then. This version is slightly more precise and considerably faster than the previous versions and has been optimized for Kepler and later generations of GPUs.\n\nOn a GTX 1060 GPU the code takes about 1.2 ms on a 1280x960 pixel image and 1.7 ms on a 1920x1080 pixel image. There is also code for brute-force matching of features that takes about 2.2 ms for two sets of around 1900 SIFT features each.\n\nThe code relies on CMake for compilation and OpenCV for image containers. OpenCV can however be quite easily changed to something else. The code can be relatively hard to read, given the way things have been parallelized for maximum speed.\n\nThe code is free to use for non-commercial applications. If you use the code for research, please cite to the following paper.\n\nM. Bj\u0026ouml;rkman, N. Bergstr\u0026ouml;m and D. Kragic, \"Detecting, segmenting and tracking unknown objects using multi-label MRF inference\", CVIU, 118, pp. 111-127, January 2014. [ScienceDirect](http://www.sciencedirect.com/science/article/pii/S107731421300194X)\n\n## Update in feature matching (2019-05-17)\n\nThe brute force feature matcher has been significantly improved in speed. The largest improvements can be seen for large feature sets with 10000 features or more, but as can be seen below, it performs rather well even with just 2000 features. The file [match.pdf](https://github.com/Celebrandil/CudaSift/blob/Pascal/match.pdf) includes a description of the optimizations done in this version.\n\n## New version for Pascal (2018-10-26)\n\nThere is a new version optimized for Pascal cards, but it should work also on many older cards. Since it includes some bug fixes that changes slightly how features are extracted, which might affect matching to features extracted using an older version, the changes are kept in a new branch (Pascal). The fixes include a small change in ScaleDown that corrects an odd behaviour for images with heights not divisible by 2^(#octaves). The second change is a correction of an improper shift of (0.5,0.5) pixels, when pixel values were read from the image to create a descriptor. \n\nThen there are some improvements in terms of speed, especially in the Laplace function, that detects DoG features, and the LowPass function, that is seen as preprocessing and is not included in the benchmarking below. Maybe surprisingly, even if optimizations were done with respect to Pascal cards, these improvements were even better for older cards. The changes involve trying to make each CUDA thread have more work to do, using fewer thread blocks. For typical images of today, there will be enough blocks to feed the streaming multiprocessors anyway.\n\nLatest result of version under test:\n\n|         |                     | 1280x960 | 1920x1080 |  GFLOPS  | Bandwidth | Matching |\n| ------- | ------------------- | -------| ---------| ---------- | --------|--------|\n| Turing  | GeForce RTX 2080 Ti |   0.42* |     0.56* |\t11750    |  616    |   0.30* |\n| Pascal  | GeForce GTX 1080 Ti |   0.58* |     0.80* |\t10609    |  484    |   0.42* |\n| Pascal  | GeForce GTX 1060    |   1.2 |     1.7 |\t3855    |  192    |   2.2 |\n| Maxwell | GeForce GTX 970     |   1.3 |     1.8 |    3494    |  224    |   2.5 |\n| Kepler  | Tesla K40c          |   2.4 |     3.4 |    4291    |  288    |   4.7 |\n\nMatching is done between two sets of 1911 and 2086 features respectively. A star indicates results from the last checked in version.\n\n## Benchmarking of new version (2018-08-22)\n\nAbout every 2nd year, I try to update the code to gain even more speed through further optimization. Here are some results for a new version of the code. Improvements in speed have primarilly been gained by reducing communication between host and device, better balancing the load on caches, shared and global memory, and increasing the workload of each thread block.\n\n|         |                     | 1280x960 | 1920x1080 |  GFLOPS  | Bandwidth | Matching |\n| ------- | ------------------- | -------| ---------| ---------- | --------|--------|\n| Pascal  | GeForce GTX 1080 Ti |   0.7  |     1.0  |\t10609    |  484    |   1.0 |\n| Pascal  | GeForce GTX 1060    |   1.6  |     2.4  |\t3855    |  192    |   2.2 |\n| Maxwell | GeForce GTX 970     |   1.9  |     2.8  |    3494    |  224    |   2.5 |\n| Kepler  | Tesla K40c          |   3.1  |     4.7  |    4291    |  288    |   4.7 |\n| Kepler  | GeForce GTX TITAN   |   2.9  |     4.3  |    4500    |  288    |   4.5 |\n\nMatching is done between two sets of 1818 and 1978 features respectively. \n\nIt's questionable whether further optimization really makes sense, given that the cost of just transfering an 1920x1080 pixel image to the device takes about 1.4 ms on a GTX 1080 Ti. Even if the brute force feature matcher is not much faster than earlier versions, it does not have the same O(N^2) temporary memory overhead, which is preferable if there are many features.\n\n## Benchmarking of previous version (2017-05-24)\n\nComputational cost (in milliseconds) on different GPUs:\n\n|         |                     | 1280x960 | 1920x1080 |  GFLOPS  | Bandwidth | Matching |\n| ------- | ------------------- | -------| ---------| ---------- | --------|--------|\n| Pascal  | GeForce GTX 1080 Ti |   1.7  |     2.3  |\t10609    |  484    |   1.4 |\n| Pascal  | GeForce GTX 1060    |   2.7  |     4.0  |\t 3855    |  192    |   2.6 |\n| Maxwell | GeForce GTX 970     |   3.8  |     5.6  |    3494    |  224    |   2.8 |\n| Kepler  | Tesla K40c          |   5.4  |     8.0  |    4291    |  288    |   5.5 |\n| Kepler  | GeForce GTX TITAN   |   4.4  |     6.6  |    4500    |  288    |   4.6 |\n\nMatching is done between two sets of 1616 and 1769 features respectively. \n \nThe improvements in this version involved a slight adaptation for Pascal, changing from textures to global memory (mostly through L2) in the most costly function LaplaceMulti. The medium-end card GTX 1060 is impressive indeed. \n\n## Usage\n\nThere are two different containers for storing data on the host and on the device; *SiftData* for SIFT features and *CudaImage* for images. Since memory allocation on GPUs is slow, it's usually preferable to preallocate a sufficient amount of memory using *InitSiftData()*, in particular if SIFT features are extracted from a continuous stream of video camera images. On repeated calls *ExtractSift()* will reuse memory previously allocated.\n~~~c\n#include \u003copencv2/core/core.hpp\u003e\n#include \u003copencv2/highgui/highgui.hpp\u003e\n#include \u003ccudaImage.h\u003e\n#include \u003ccudaSift.h\u003e\n\n/* Reserve memory space for a whole bunch of SIFT features. */\nSiftData siftData;\nInitSiftData(siftData, 25000, true, true);\n\n/* Read image using OpenCV and convert to floating point. */\ncv::Mat limg;\ncv::imread(\"image.png\", 0).convertTo(limg, CV32FC1);\n/* Allocate 1280x960 pixel image with device side pitch of 1280 floats. */ \n/* Memory on host side already allocated by OpenCV is reused.           */\nCudaImage img;\nimg.Allocate(1280, 960, 1280, false, NULL, (float*) limg.data);\n/* Download image from host to device */\nimg.Download();\n\nint numOctaves = 5;    /* Number of octaves in Gaussian pyramid */\nfloat initBlur = 1.0f; /* Amount of initial Gaussian blurring in standard deviations */\nfloat thresh = 3.5f;   /* Threshold on difference of Gaussians for feature pruning */\nfloat minScale = 0.0f; /* Minimum acceptable scale to remove fine-scale features */\nbool upScale = false;  /* Whether to upscale image before extraction */\n/* Extract SIFT features */\nExtractSift(siftData, img, numOctaves, initBlur, thresh, minScale, upScale);\n...\n/* Free space allocated from SIFT features */\nFreeSiftData(siftData);\n\n~~~\n\n## Parameter setting\n\nThe requirements on number and quality of features vary from application to application. Some applications benefit from a smaller number of high quality features, while others require as many features as possible. More distinct features with higher DoG (difference of Gaussians) responses tend to be of higher quality and are easier to match between multiple views. With the parameter *thresh* a threshold can be set on the minimum DoG to prune features of less quality. \n\nIn many cases the most fine-scale features are of little use, especially when noise conditions are severe or when features are matched between very different views. In such cases the most fine-scale features can be pruned by setting *minScale* to the minimum acceptable feature scale, where 1.0 corresponds to the original image scale without upscaling. As a consequence of pruning the computational cost can also be reduced.\n\nTo increase the number of SIFT features, but also increase the computational cost, the original image can be automatically upscaled to double the size using the *upScale* parameter, in accordance to Lowe's recommendations. One should keep in mind though that by doing so the fraction of features that can be matched tend to go down, even if the total number of extracted features increases significantly. If it's enough to instead reduce the *thresh* parameter to get more features, that is often a better alternative.\n\nResults without upscaling (upScale=False) of 1280x960 pixel input image. \n\n| *thresh* | #Matches | %Matches | Cost (ms) |\n|-----------|----------|----------|-----------|\n|    1.0    |   4236   |   40.4%  |    5.8    |\n|    1.5    |   3491   |   42.5%  |    5.2    |\n|    2.0    |   2720   |   43.2%  |    4.7    |\n|    2.5    |   2121   |   44.4%  |    4.2    |\n|    3.0    |   1627   |   45.8%  |    3.9    |\n|    3.5    |   1189   |   46.2%  |    3.6    |\n|    4.0    |    881   |   48.5%  |    3.3    |\n\n\nResults with upscaling (upScale=True) of 1280x960 pixel input image.\n\n| *thresh* | #Matches | %Matches | Cost (ms) |\n|-----------|----------|----------|-----------|\n|    2.0    |   4502   |   34.9%  |   13.2    |\n|    2.5    |   3389   |   35.9%  |   11.2    |\n|    3.0    |   2529   |   37.1%  |   10.6    |\n|    3.5    |   1841   |   38.3%  |    9.9    |\n|    4.0    |   1331   |   39.8%  |    9.5    |\n|    4.5    |    954   |   42.2%  |    9.3    |\n|    5.0    |    611   |   39.3%  |    9.1    |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FCelebrandil%2FCudaSift","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FCelebrandil%2FCudaSift","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FCelebrandil%2FCudaSift/lists"}