Coder Social home page Coder Social logo

acecoooool / roialign-roipool-pytorch Goto Github PK

View Code? Open in Web Editor NEW
71.0 4.0 15.0 88 KB

C++ extension implementation of RoIAlign & RolPool (both GPU and CPU) for PyTorch

CMake 1.63% C++ 50.11% Python 13.70% Cuda 34.56%
roialign roipooling pytorch object-detection cpu gpu

roialign-roipool-pytorch's Introduction

RoI-op-pytorch

C++ extension of RoIPool & RoIAlign (both CPU and GPU) in PyTorch,this code is converted from caffe2 operation. (need pytorch 0.4.0)

**Warning:**You may change AT_CHECK to AT_ASSERT(0.4 version using AT_ASSERT, and latest version using AT_CHECK

**Note: **

  1. roi_xxx_cpu.cpp&roi_xxx_binding.cpp:contains the cpu version of forward and backward operation.(Note: roi_xxx_binding.cpp is for pybind, you can put this code into roi_xxx_cpu.cpp as well)
  2. roi_xxx_kernel.cu&roi_xxx_cuda.cpp:contains the cuda version of forward and backward operation.
  3. main.py&temp.h&CMakeLists.txt:help you to debug in c++ code, rather than to run python setup.py install to debug. (Note: only support cpu version ~ I don't know how to debug .cu code 😣)
  4. setup.py:you can run python setup.py install to install this operation as a package (You can find this package in you python site-package)
  5. roi_xxx.py:wrap .cpp code to pytorch's Function & Module ,there is also a small demo testing.

Install

cd roixxx   # roipool or roialign
python setup.py install

RoI Pooling

The "strategy" of roi-pooling in this implementaion likes the follow picture:(:joy: so bad picture)

oi_poo

Note: (please stand on point view rather than block view)

  1. scale=0.5
  2. dotted line is the range of "seleted area" (int form in [left, right) and [top, bottom))

RoI Align

oialig

Note: left sample=1, right sample=2

There are several good resource to explain these two operations:

Reference

  1. caffe2 operator:most of the code is coming from here.
  2. extension-cpp: tutorial
  3. detectorch

roialign-roipool-pytorch's People

Contributors

acecoooool avatar chengfeng0113 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

roialign-roipool-pytorch's Issues

Question about batch data.

Hello,
First of all, really thank you for your hard work and sharing.

The reason why I write the issue is that I don't know exactly a meaning of "batch index" (the first element of "rois")

I hope to use your roi_align (or roi_pooling) to batch tensor. In that case, how to use your function?

Thank you

What are the requirements of this project?

my pytorch version is 1.8.1 and I meet this problem when running python setup.py install

In file included from roi_align_binding.cpp:2:0:
roi_align_cpu.cpp:241:57: 错误:‘rois_col’在此作用域中尚未声明
                        {channel, h, w}, pool_h, pool_w, rois_col, sample, grad_in.data<float>());
                                                         ^~~~~~~~
roi_align_cpu.cpp:241:57: 附注:suggested alternative: ‘rois’
                        {channel, h, w}, pool_h, pool_w, rois_col, sample, grad_in.data<float>());
                                                         ^~~~~~~~
                                                         rois
roi_align_cpu.cpp:241:88: 错误:expected primary-expression before ‘float’
                        {channel, h, w}, pool_h, pool_w, rois_col, sample, grad_in.data<float>());
                                                                                        ^~~~~

CUDA Eerror:an illegal memory access was encountered

class ROIPoolFunction(Function): @staticmethod def forward(ctx, feat, rois, pool_h, pool_w, scale, train): ctx.rois = rois ctx.feat_size = feat.size() ctx.pool_h = pool_h ctx.pool_w = pool_w if train: ctx.memory = torch.zeros((rois.size(0), feat.size(1), pool_h, pool_w), dtype=torch.int) else: ctx.memory = torch.zeros(0) if feat.is_cuda: ctx.memory = ctx.memory.cuda() output = roi_pool_cuda.forward_cuda(feat, rois, pool_h, pool_w, scale, ctx.memory) else: output = roi_pool_cpu.forward_cpu(feat, rois, pool_h, pool_w, scale, ctx.memory) return output

ctx.memory = torch.zeros(0)
i found this line will lead to the runtime error :CUDA Eerror:an illegal memory access was encountered

Origin boxes

Why's origin boxes = (1.6 1.6 9.2 11.0)? Also, how to calculate bin_w, bin_h and scale_boxes?

there seems to be a mistake?

Thank you for the code.But there seems to be a mistake?
in RoIAlign-RoIPool-pytorch/roialign/roi_align_kernel.cu , Line 85:
image
it should be :
const T *offset_input = input + (roi_batch_idx * channel+ c) * h * w;

Question about grad_out of roi_pooling

Thanks for your code. I have a question, why you add
grad_out = grad_out.contiguous() if not grad_out.is_contiguous() else grad_out in the roi_pool.py L32? Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.