K-Nearest Neighbor in Pytorch

Overview

Pytorch KNN CUDA

  • 2019/11/02 This repository will no longer be maintained as pytorch supports sort() and kthvalue on tensors.
git clone https://github.com/chrischoy/pytorch_knn_cuda
cd pytorch_knn_cuda
make
python __init__.py
Issues
  • making code compatible with pytorch v0.4.1

    making code compatible with pytorch v0.4.1

    Due to some API changes made in pytorch v0.4.1 pytorch_knn_cuda was no longer able to compile (see issue #3).
    This PR makes the required changes, it now works with pytorch v.0.4.1

    opened by shaibagon 1
  • can not compile this when run make command

    can not compile this when run make command

    [email protected]:/pytorch_knn_cuda# make

    Separate cpp shared library that will be loaded to the extern C ffi

    nvcc -c -o build/knn_cuda_kernel.so src/knn_cuda_kernel.cu -x cu -Xcompiler -fPIC -shared -Isrc make: nvcc: Command not found Makefile:34: recipe for target 'build/knn_cuda_kernel.so' failed make: *** [build/knn_cuda_kernel.so] Error 127 [email protected]:/pytorch_knn_cuda#

    did anyone got this error as me, I do not know how to fix it.

    opened by EulerWong 1
  • APIs and Usage Examples

    APIs and Usage Examples

    Cool library! Could you provide any usage example or API?

    opened by guxd 0
  • Cannot compile with pyotrch 0.4.1

    Cannot compile with pyotrch 0.4.1

    Getting error

    gcc -pthread -B /home/bagon/anaconda3/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -DWITH_CUDA -I/home/bagon/anaconda3/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include -I/home/bagon/anaconda3/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/TH -I/home/bagon/anaconda3/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/THC -I/usr/local/cuda/include -I/home/bagon/anaconda3/pkgs/pytorch_knn_cuda/include -I/home/bagon/anaconda3/include/python3.6m -c /home/bagon/anaconda3/pkgs/pytorch_knn_cuda/src/knn_pytorch.c -o ./home/bagon/anaconda3/pkgs/pytorch_knn_cuda/src/knn_pytorch.o -std=c99
    In file included from /home/bagon/anaconda3/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/THC/THCGeneral.h:4:0,
                     from /home/bagon/anaconda3/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/THC/THC.h:4,
                     from /home/bagon/anaconda3/pkgs/pytorch_knn_cuda/src/knn_pytorch.c:1:
    /home/bagon/anaconda3/pkgs/pytorch_knn_cuda/src/knn_pytorch.c: In function ‘knn’:
    /home/bagon/anaconda3/pkgs/pytorch_knn_cuda/src/knn_pytorch.c:11:24: error: dereferencing pointer to incomplete type ‘THTensor {aka struct THTensor}’
       THArgCheck(ref_tensor->nDimension == 2 , 0, "ref_tensor: 2D Tensor expected");
                            ^
    /home/bagon/anaconda3/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/TH/THGeneral.h:111:35: note: in definition of macro ‘THArgCheck’
       _THArgCheck(__FILE__, __LINE__, __VA_ARGS__);
    

    It seems like the definition of struct THTensor was moved from THTensor.h to THTensor.hpp and this causes this issue.

    Any way to workaround this?

    opened by shaibagon 0
  • PyTorch 1.0 Support

    PyTorch 1.0 Support

    I want to use KNN with pytorch 1.0, can this libraray support the newest pytorch version?

    opened by rising-fallmoon 3
  • Illegal memory access with large N*M

    Illegal memory access with large N*M

    Tried on 10,000 reference points, 100 query points, and 3 feature dimensions, this crashes with the error:

    RuntimeError: cuda runtime error (77) : an illegal memory access was encountered at /pytorch/torch/lib/THC/generic/THCTensorCopy.c:70

    The error does not appear when executing the KNN code, but only when trying to assign or access any data on the GPU (including the results) after the code is called. Tested with GeForce GTX 1080 with 8 GB of VRAM.

    opened by agarret7 6
Owner
Chris Choy
Research Scientist @NVIDIA. Previously Ph.D. from Stanford Vision and Learning Lab @StanfordVL (SVL), Stanford AI Lab, SAIL.
Chris Choy
Simple and Effective Few-Shot Named Entity Recognition with Structured Nearest Neighbor Learning

structshot Code and data for paper "Simple and Effective Few-Shot Named Entity Recognition with Structured Nearest Neighbor Learning", Yi Yang and Arz

ASAPP Research 25 Nov 17, 2021
Optimal space decomposition based-product quantization for approximate nearest neighbor search

Optimal space decomposition based-product quantization for approximate nearest neighbor search Abstract Product quantization(PQ) is an effective neare

Mylove 1 Nov 19, 2021
Code for Subgraph Federated Learning with Missing Neighbor Generation (NeurIPS 2021)

To run the code Unzip the package to your local directory; Run 'pip install -r requirements.txt' to download required packages; Open file ~/nips_code/

null 2 Nov 23, 2021
Approximate Nearest Neighbors in C++/Python optimized for memory usage and loading/saving to disk

Annoy Annoy (Approximate Nearest Neighbors Oh Yeah) is a C++ library with Python bindings to search for points in space that are close to a given quer

Spotify 9.2k Dec 4, 2021
A gesture recognition system powered by OpenPose, k-nearest neighbours, and local outlier factor.

OpenHands OpenHands is a gesture recognition system powered by OpenPose, k-nearest neighbours, and local outlier factor. Currently the system can iden

Paul Treanor 11 Jul 13, 2021
An essential implementation of BYOL in PyTorch + PyTorch Lightning

Essential BYOL A simple and complete implementation of Bootstrap your own latent: A new approach to self-supervised Learning in PyTorch + PyTorch Ligh

Enrico Fini 41 Aug 20, 2021
RealFormer-Pytorch Implementation of RealFormer using pytorch

RealFormer-Pytorch Implementation of RealFormer using pytorch. Includes comparison with classical Transformer on image classification task (ViT) wrt C

Simo Ryu 82 Nov 15, 2021
Generic template to bootstrap your PyTorch project with PyTorch Lightning, Hydra, W&B, and DVC.

NN Template Generic template to bootstrap your PyTorch project. Click on Use this Template and avoid writing boilerplate code for: PyTorch Lightning,

Luca Moschella 302 Nov 23, 2021
A PyTorch Extension: Tools for easy mixed precision and distributed training in Pytorch

This repository holds NVIDIA-maintained utilities to streamline mixed precision and distributed training in Pytorch. Some of the code here will be included in upstream Pytorch eventually. The intention of Apex is to make up-to-date utilities available to users as quickly as possible.

NVIDIA Corporation 5.9k Dec 3, 2021
Objective of the repository is to learn and build machine learning models using Pytorch. 30DaysofML Using Pytorch

30 Days Of Machine Learning Using Pytorch Objective of the repository is to learn and build machine learning models using Pytorch. List of Algorithms

Mayur 105 Oct 21, 2021
Pretrained SOTA Deep Learning models, callbacks and more for research and production with PyTorch Lightning and PyTorch

Pretrained SOTA Deep Learning models, callbacks and more for research and production with PyTorch Lightning and PyTorch

Pytorch Lightning 1.2k Nov 28, 2021
Amazon Forest Computer Vision: Satellite Image tagging code using PyTorch / Keras with lots of PyTorch tricks

Amazon Forest Computer Vision Satellite Image tagging code using PyTorch / Keras Here is a sample of images we had to work with Source: https://www.ka

Mamy Ratsimbazafy 354 Nov 26, 2021
The Incredible PyTorch: a curated list of tutorials, papers, projects, communities and more relating to PyTorch.

This is a curated list of tutorials, projects, libraries, videos, papers, books and anything related to the incredible PyTorch. Feel free to make a pu

Ritchie Ng 8.5k Dec 2, 2021
A PyTorch implementation of the paper Mixup: Beyond Empirical Risk Minimization in PyTorch

Mixup: Beyond Empirical Risk Minimization in PyTorch This is an unofficial PyTorch implementation of mixup: Beyond Empirical Risk Minimization. The co

Harry Yang 116 Oct 20, 2021
A pytorch implementation of Pytorch-Sketch-RNN

Pytorch-Sketch-RNN A pytorch implementation of https://arxiv.org/abs/1704.03477 In order to draw other things than cats, you will find more drawing da

Alexis David Jacq 158 Nov 17, 2021
PyTorch implementation of Advantage async actor-critic Algorithms (A3C) in PyTorch

Advantage async actor-critic Algorithms (A3C) in PyTorch @inproceedings{mnih2016asynchronous, title={Asynchronous methods for deep reinforcement lea

LEI TAI 110 Oct 26, 2021
Amazon Forest Computer Vision: Satellite Image tagging code using PyTorch / Keras with lots of PyTorch tricks

Amazon Forest Computer Vision Satellite Image tagging code using PyTorch / Keras Here is a sample of images we had to work with Source: https://www.ka

Mamy Ratsimbazafy 354 Nov 26, 2021
A bunch of random PyTorch models using PyTorch's C++ frontend

PyTorch Deep Learning Models using the C++ frontend Gettting started Clone the repo 1. https://github.com/mrdvince/pytorchcpp 2. cd fashionmnist or

Vince 0 Jul 13, 2021