Giter Club home page Giter Club logo

roialign.pytorch's Introduction

RoIAlign for PyTorch

This is a PyTorch version of RoIAlign. This implementation is based on crop_and_resize and supports both forward and backward on CPU and GPU.

NOTE: Thanks meikuam for updating this repo for PyTorch 1.0. You can find the original version for torch <= 0.4.1 in pytorch_0.4 branch.

Introduction

The crop_and_resize function is ported from tensorflow, and has the same interface with tensorflow version, except the input feature map should be in NCHW order in PyTorch. They also have the same output value (error < 1e-5) for both forward and backward as we expected, see the comparision in test.py.

Note: Document of crop_and_resize can be found here. And RoIAlign is a wrap of crop_and_resize that uses boxes with unnormalized (x1, y1, x2, y2) as input (while crop_and_resize use normalized (y1, x1, y2, x2) as input). See more details about the difference of RoIAlign and crop_and_resize in tensorpack.

Warning: Currently it only works using the default GPU (index 0)

Usage

  • Install and test

    python setup.py install
    ./test.sh
    
  • Use RoIAlign or crop_and_resize

    Since PyTorch 1.2.0 Legacy autograd function with non-static forward method is deprecated. We use new-style autograd function with static forward method. Example:

    import torch
    from roi_align import RoIAlign      # RoIAlign module
    from roi_align import CropAndResize # crop_and_resize module
    
    # input feature maps (suppose that we have batch_size==2)
    image = torch.arange(0., 49).view(1, 1, 7, 7).repeat(2, 1, 1, 1)
    image[0] += 10
    print('image: ', image)
    
    
    # for example, we have two bboxes with coords xyxy (first with batch_id=0, second with batch_id=1).
    boxes = torch.Tensor([[1, 0, 5, 4],
                         [0.5, 3.5, 4, 7]])
    
    box_index = torch.tensor([0, 1], dtype=torch.int) # index of bbox in batch
    
    # RoIAlign layer with crop sizes:
    crop_height = 4
    crop_width = 4
    roi_align = RoIAlign(crop_height, crop_width)
    
    # make crops:
    crops = roi_align(image, boxes, box_index)
    
    print('crops:', crops)

    Output:

    image:  tensor([[[[10., 11., 12., 13., 14., 15., 16.],
          [17., 18., 19., 20., 21., 22., 23.],
          [24., 25., 26., 27., 28., 29., 30.],
          [31., 32., 33., 34., 35., 36., 37.],
          [38., 39., 40., 41., 42., 43., 44.],
          [45., 46., 47., 48., 49., 50., 51.],
          [52., 53., 54., 55., 56., 57., 58.]]],
    
    
        [[[ 0.,  1.,  2.,  3.,  4.,  5.,  6.],
          [ 7.,  8.,  9., 10., 11., 12., 13.],
          [14., 15., 16., 17., 18., 19., 20.],
          [21., 22., 23., 24., 25., 26., 27.],
          [28., 29., 30., 31., 32., 33., 34.],
          [35., 36., 37., 38., 39., 40., 41.],
          [42., 43., 44., 45., 46., 47., 48.]]]])
          
    crops: tensor([[[[11.0000, 12.0000, 13.0000, 14.0000],
              [18.0000, 19.0000, 20.0000, 21.0000],
              [25.0000, 26.0000, 27.0000, 28.0000],
              [32.0000, 33.0000, 34.0000, 35.0000]]],
    
    
            [[[24.5000, 25.3750, 26.2500, 27.1250],
              [30.6250, 31.5000, 32.3750, 33.2500],
              [36.7500, 37.6250, 38.5000, 39.3750],
              [ 0.0000,  0.0000,  0.0000,  0.0000]]]])

roialign.pytorch's People

Contributors

charlesshang avatar longcw avatar meikuam avatar paucarre avatar simo23 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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

roialign.pytorch's Issues

why can not use float64

I have debugged the code for about ten years. Finally, I found cannot use dtype of the box as float64.

WHY??????????????????????????????????????????????

I think this code is a little bit stupid.

How about the GPU memory cost?

Hi, thanks for your sharing codes.
So how about the GPU memory cost compared with original RoiPool?
And it seems like the function grid_sample in PyTorch could also do the similar work, so what's the difference?

LinkError: command 'gcc' failed with exit status 1

LinkError: command 'gcc' failed with exit status 1
During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "build.py", line 40, in
ffi.build()
File "/home/wei.li/anaconda3/envs/group_1/lib/python3.6/site-packages/torch/utils/ffi/init.py", line 189, in build
_build_extension(ffi, cffi_wrapper_name, target_dir, verbose)
File "/home/wei.li/anaconda3/envs/group_1/lib/python3.6/site-packages/torch/utils/ffi/init.py", line 111, in _build_extension
outfile = ffi.compile(tmpdir=tmpdir, verbose=verbose, target=libname)
File "/home/wei.li/anaconda3/envs/group_1/lib/python3.6/site-packages/cffi-1.15.0-py3.6-linux-x86_64.egg/cffi/api.py", line 727, in compile
compiler_verbose=verbose, debug=debug, **kwds)
File "/home/wei.li/anaconda3/envs/group_1/lib/python3.6/site-packages/cffi-1.15.0-py3.6-linux-x86_64.egg/cffi/recompiler.py", line 1565, in recompile
compiler_verbose, debug)
File "/home/wei.li/anaconda3/envs/group_1/lib/python3.6/site-packages/cffi-1.15.0-py3.6-linux-x86_64.egg/cffi/ffiplatform.py", line 22, in compile
outputfilename = _build(tmpdir, ext, compiler_verbose, debug)
File "/home/wei.li/anaconda3/envs/group_1/lib/python3.6/site-packages/cffi-1.15.0-py3.6-linux-x86_64.egg/cffi/ffiplatform.py", line 58, in _build
raise VerificationError('%s: %s' % (e.class.name, e))
cffi.VerificationError: LinkError: command 'gcc' failed with exit status 1

install error

Hi, thank you for your work and share. The system is ubuntu16.04 with pytorch 0.5.0. When I run ./install.sh, an error:
dereferencing pointer to incomplete type 'THTensor {aka struct THTensor}'
const int batch_size = image->size[0];
occurred. I cannot find a solution on google, could you give me a cue to solve this error. Thank you very much!

adding nms to this package

Thanks for this package. Is it possible to add nms too in this package? that way we have all we need for mask rcnn in one package :)

Install log

Before command "python setup.py install"
you better command export CUDA_HOME="/usr/local/cuda/" , this is your cuda path.

crop_and_resize.obj : error LNK2001: unresolved external symbol __imp_THFloatTensor_zero

When I run install.sh ,the error occured. I found the error came when I run build.py

Creating library .\Release_crop_and_resize.lib and object .\Release_crop_and_resize.exp
crop_and_resize.obj : error LNK2001: unresolved external symbol __imp_THFloatTensor_zero
crop_and_resize.obj : error LNK2001: unresolved external symbol __imp_THFloatTensor_data
crop_and_resize.obj : error LNK2001: unresolved external symbol __imp_THFloatTensor_resize4d
crop_and_resize.obj : error LNK2001: unresolved external symbol __imp_THFloatTensor_size
crop_and_resize.obj : error LNK2001: unresolved external symbol __imp_THIntTensor_data
._crop_and_resize.pyd : fatal error LNK1120: 5 unresolved externals
Traceback (most recent call last):
File "D:\Anaconda\lib\distutils_msvccompiler.py", line 520, in link
self.spawn([self.linker] + ld_args)
File "D:\Anaconda\lib\distutils_msvccompiler.py", line 543, in spawn
return super().spawn(cmd)
File "D:\Anaconda\lib\distutils\ccompiler.py", line 909, in spawn
spawn(cmd, dry_run=self.dry_run)
File "D:\Anaconda\lib\distutils\spawn.py", line 38, in spawn
_spawn_nt(cmd, search_path, dry_run=dry_run)
File "D:\Anaconda\lib\distutils\spawn.py", line 81, in _spawn_nt
"command %r failed with exit status %d" % (cmd, rc))
distutils.errors.DistutilsExecError: command 'C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.25.28610\bin\HostX86\x64\link.exe' failed with exit status 1120

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "D:\Anaconda\lib\site-packages\cffi\ffiplatform.py", line 51, in _build
dist.run_command('build_ext')
File "D:\Anaconda\lib\distutils\dist.py", line 985, in run_command
cmd_obj.run()
File "D:\Anaconda\lib\site-packages\setuptools\command\build_ext.py", line 84, in run
_build_ext.run(self)
File "D:\Anaconda\lib\site-packages\Cython\Distutils\old_build_ext.py", line 186, in run
_build_ext.build_ext.run(self)
File "D:\Anaconda\lib\distutils\command\build_ext.py", line 340, in run
self.build_extensions()
File "D:\Anaconda\lib\site-packages\Cython\Distutils\old_build_ext.py", line 194, in build_extensions
self.build_extension(ext)
File "D:\Anaconda\lib\site-packages\setuptools\command\build_ext.py", line 205, in build_extension
_build_ext.build_extension(self, ext)
File "D:\Anaconda\lib\distutils\command\build_ext.py", line 559, in build_extension
target_lang=language)
File "D:\Anaconda\lib\distutils\ccompiler.py", line 717, in link_shared_object
extra_preargs, extra_postargs, build_temp, target_lang)
File "D:\Anaconda\lib\distutils_msvccompiler.py", line 523, in link
raise LinkError(msg)
distutils.errors.LinkError: command 'C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.25.28610\bin\HostX86\x64\link.exe' failed with exit status 1120

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:/Users/%user%/Desktop/graduatio_project/Group-Activity-Recognition-master/RoIAlign.pytorch-pytorch_0.4/roi_align/build.py", line 40, in
ffi.build()
File "D:\Anaconda\lib\site-packages\torch\utils\ffi_init_.py", line 189, in build
build_extension(ffi, cffi_wrapper_name, target_dir, verbose)
File "D:\Anaconda\lib\site-packages\torch\utils\ffi_init
.py", line 111, in _build_extension
outfile = ffi.compile(tmpdir=tmpdir, verbose=verbose, target=libname)
File "D:\Anaconda\lib\site-packages\cffi\api.py", line 723, in compile
compiler_verbose=verbose, debug=debug, **kwds)
File "D:\Anaconda\lib\site-packages\cffi\recompiler.py", line 1526, in recompile
compiler_verbose, debug)
File "D:\Anaconda\lib\site-packages\cffi\ffiplatform.py", line 22, in compile
outputfilename = _build(tmpdir, ext, compiler_verbose, debug)
File "D:\Anaconda\lib\site-packages\cffi\ffiplatform.py", line 58, in _build
raise VerificationError('%s: %s' % (e.class.name, e))
cffi.VerificationError: LinkError: command 'C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.25.28610\bin\HostX86\x64\link.exe' failed with exit status 1120

Can anyone tell me how to solve this problem?
Thx a lot!!!

What is the advantage of transform_fpcoor=True as opposed to False?

I've run some tests in order to try and understand how exactly this implementation works.

Let's suppose my features are as follows:

input:
tensor([[[[0., 1., 2., 3., 4., 5., 6.],
          [0., 1., 2., 3., 4., 5., 6.],
          [0., 1., 2., 3., 4., 5., 6.],
          [0., 1., 2., 3., 4., 5., 6.],
          [0., 1., 2., 3., 4., 5., 6.],
          [0., 1., 2., 3., 4., 5., 6.]]]])

and I want to apply RoIAlign (crop size 3x3) for a box having the following coordinates:

box:
tensor([[2., 2., 4., 4.]])

Now, the result I obtain with transform_fpcoor=False is as follows:

tensor([[[[2., 3., 4.],
          [2., 3., 4.],
          [2., 3., 4.]]]])

which makes sense, since I'm cropping a 3x3 box that is aligned with the coordinates of the input.
What I don't quite understand is why the result of the RoIAlign (transform_fpcoor=True) is supposed to be like this:

tensor([[[[1.8333, 2.5000, 3.1667],
          [1.8333, 2.5000, 3.1667],
          [1.8333, 2.5000, 3.1667]]]])

In particular:

  1. why are values fetched outside the box (2, 2, 4, 4)? (Notice the values < 2)
  2. why does the interpolation seem to stop earlier than it's supposed to be? (Notice the max value is slightly above 3). It seems like the box it tries to extract the coordinates from is (2, 2, 3, 3).
    This is confirmed by the fact that if I run RoIAlign (fpcoor=True) on the box (2, 2, 5, 5) I get:
tensor([[[[2., 3., 4.],
          [2., 3., 4.],
          [2., 3., 4.]]]])

Could you please explain to me why the RoiAlign behaves like this? Thank you!

crop a patch from image

I write a simple test code code 1 as follows. I first generate a 3D ndarray randomly, and add a new dimensionality to represente the batch_size dimension. The box is set to [0, 0, 3, 3], and the croped width and heght of RoIAlign are set to 3 and 3, respectively. And the output is what I want.

code 1

import numpy as np
import torch
from torch.autograd import Variable
import matplotlib.pyplot as plt
from roialign.roi_align.roi_align import RoIAlign
import cv2

def to_varabile(arr, requires_grad=False, is_cuda=True):
    tensor = torch.from_numpy(arr)
    if is_cuda:
        tensor = tensor.cuda()
    var = Variable(tensor, requires_grad=requires_grad)
    return var

# the data you want
is_cuda = False

# --------------- image data generation ---------------------------
image_data = np.random.randn(3, 7, 5) * 100
image_data = np.asarray(image_data, dtype=np.float32)
image_data = image_data[np.newaxis]
# -------------- end of image data generation---------------------

boxes_data = np.asarray([[0, 0, 3, 3]], dtype=np.float32)
box_index_data = np.asarray([0], dtype=np.int32)

image_torch = to_varabile(image_data, requires_grad=True, is_cuda=is_cuda)
boxes = to_varabile(boxes_data, requires_grad=False, is_cuda=is_cuda)
box_index = to_varabile(box_index_data, requires_grad=False, is_cuda=is_cuda)

# set transform_fpcoor to False is the crop_and_resize
roi_align = RoIAlign(crop_width=3, crop_height=3, transform_fpcoor=True)
croped = roi_align(image_torch, boxes, box_index)

print(image_torch, '\n')
print(croped)

output 1

tensor([[[[ 155.2937,   27.9904,   74.7080,   66.1174,   34.2396],
          [-140.2568,  164.4559,  -88.8006,  -37.5217,  156.6059],
          [  44.5218,    1.7729,  146.5069,  149.6736,    5.5269],
          [-222.4462,   65.9821,  -52.1707, -145.4467,  -49.2179],
          [ -96.1867,  -40.4554,  -25.5354,   75.1842,  -69.6537],
          [  12.1659,  -15.9438,    0.2947,  -55.0050,    9.0175],
          [ -23.8114,   -9.1514,  -11.3899,  -33.1432, -120.8428]],

         [[  78.6541,   -1.6860,  -81.5798,  -46.7906,  -41.1748],
          [-106.7531,  -40.6971,   15.0387,   50.8834, -122.1978],
          [ -52.3712,   -2.0634,   80.5198,   92.6046,   30.9877],
          [ -44.0200,   34.4229,   83.7537,  -53.1896,   68.1574],
          [  11.3319, -117.5049,  -28.6529,   52.9562,  -59.5388],
          [ 104.2405,  148.5067,  -51.5808,  -82.6794,  104.9984],
          [  46.2745, -140.3886, -134.5971, -106.4377,  146.3157]],

         [[ -12.9685,  -22.6475,   42.1217,  -71.6224,  153.7339],
          [  -1.0168,  -76.6128,    4.3941, -157.5561,  -93.8834],
          [   7.0985,   21.7129,   -2.5151,  272.5159,  -74.3853],
          [  35.7283,  106.1746, -112.5265,  -13.9350,   26.7033],
          [ -36.1484,  -51.4258,  -78.5966,  123.6539,  -83.3441],
          [  60.9276,   63.7939,  -42.0873,  207.5641,   58.5911],
          [  28.2906,   25.9808,   95.6436,  211.1584, -151.0635]]]]) 

tensor([[[[ 155.2937,   27.9904,   74.7080],
          [-140.2568,  164.4559,  -88.8006],
          [  44.5218,    1.7729,  146.5069]],

         [[  78.6541,   -1.6860,  -81.5798],
          [-106.7531,  -40.6971,   15.0387],
          [ -52.3712,   -2.0634,   80.5198]],

         [[ -12.9685,  -22.6475,   42.1217],
          [  -1.0168,  -76.6128,    4.3941],
          [   7.0985,   21.7129,   -2.5151]]]])

Next, I modify the code 1, and I get code 2 . What I did is just change the generation of image dada. Instead generate randomly, I load a image from the disk, and pick a small patch from the image. But there are some thing wrong. code 2 and output are as follows:

code 2

import numpy as np
import torch
from torch.autograd import Variable
import matplotlib.pyplot as plt
from roialign.roi_align.roi_align import RoIAlign
import cv2

def to_varabile(arr, requires_grad=False, is_cuda=True):
    tensor = torch.from_numpy(arr)
    if is_cuda:
        tensor = tensor.cuda()
    var = Variable(tensor, requires_grad=requires_grad)
    return var

# the data you want
is_cuda = False

# ------------------------- image data generation ---------------------------------
frame_path = '/data0/liuqk/MOTChallenge/2DMOT2015/train/TUD-Campus/img1/000068.jpg'
image_data = plt.imread(frame_path) # HxWxC
image_data = image_data[200:207, 200:205, :]
image_data = np.transpose(image_data, (2, 0, 1)) # CxHxW
image_data = np.asarray(image_data, dtype=np.float32)
image_data = image_data[np.newaxis]
# ------------------------- end of image data generation --------------------------

# image_data = image_data[np.newaxis, np.newaxis]
boxes_data = np.asarray([[0, 0, 3, 3]], dtype=np.float32)
box_index_data = np.asarray([0], dtype=np.int32)

image_torch = to_varabile(image_data, requires_grad=True, is_cuda=is_cuda)
boxes = to_varabile(boxes_data, requires_grad=False, is_cuda=is_cuda)
box_index = to_varabile(box_index_data, requires_grad=False, is_cuda=is_cuda)

# set transform_fpcoor to False is the crop_and_resize
roi_align = RoIAlign(crop_width=3, crop_height=3, transform_fpcoor=True)
croped = roi_align(image_torch, boxes, box_index)

print(image_torch, '\n')
print(croped)

output 2

tensor([[[[ 67.,  67.,  66.,  66.,  64.],
          [ 67.,  67.,  66.,  64.,  64.],
          [ 67.,  67.,  65.,  64.,  65.],
          [ 67.,  65.,  65.,  65.,  65.],
          [ 64.,  64.,  64.,  64.,  64.],
          [ 63.,  63.,  63.,  63.,  63.],
          [ 62.,  62.,  62.,  62.,  62.]],

         [[ 65.,  65.,  64.,  64.,  64.],
          [ 64.,  64.,  63.,  64.,  64.],
          [ 64.,  64.,  65.,  64.,  65.],
          [ 64.,  65.,  65.,  65.,  65.],
          [ 64.,  64.,  64.,  64.,  64.],
          [ 63.,  63.,  63.,  63.,  63.],
          [ 62.,  62.,  62.,  62.,  62.]],

         [[ 53.,  53.,  52.,  52.,  52.],
          [ 55.,  55.,  54.,  54.,  54.],
          [ 55.,  55.,  55.,  54.,  55.],
          [ 55.,  55.,  55.,  55.,  55.],
          [ 54.,  54.,  54.,  54.,  54.],
          [ 53.,  53.,  53.,  53.,  53.],
          [ 52.,  52.,  52.,  52.,  52.]]]]) 

tensor([[[[ 67.,  65.,  53.],
          [ 53.,  66.,  64.],
          [ 64.,  52.,  64.]],

         [[ 55.,  65.,  65.],
          [ 64.,  54.,  65.],
          [ 67.,  64.,  55.]],

         [[ 64.,  54.,  64.],
          [ 63.,  63.,  53.],
          [ 53.,  63.,  63.]]]])

As you can see, the out put is not what I want and I can not figure out how RoIAlign works here. So I am wondering why this happening? Can anyone tell me please?

fp16 support

hi @longcw, thanks a lot for your excellent work, it really helped!

I am now trying to use crop_and _resize on image_feature_maps with dtype of torch.float16 to speed up training and inference, however it seems that your repo doesn't support fp16 yet throwing following error:

RuntimeError: image.type().scalarType() == torch::ScalarType::Float ASSERT FAILED at roi_aligfloat Tensor (crop_and_resize_gpu_forward at roi_align/src/crop_and_resize_gpu.cpp:27)
frame #0: c10::Error::Error(c10::SourceLocation, std::__cxx11::basic_string<char, std::char_t/miniconda3/lib/python3.6/site-packages/torch/lib/libc10.so)
frame #1: torch::crop_and_resize_gpu_forward(at::Tensor, at::Tensor, at::Tensor, float, int, site-packages/roi_align-0.0.1-py3.6-linux-x86_64.egg/roi_align/crop_and_resize_gpu.cpython-36
frame #2: + 0x157c7 (0x7fc110c767c7 in /usr/local/miniconda3/lib/python3.6gpu.cpython-36m-x86_64-linux-gnu.so)
frame #3: + 0x1598e (0x7fc110c7698e in /usr/local/miniconda3/lib/python3.6gpu.cpython-36m-x86_64-linux-gnu.so)
frame #4: + 0x125f5 (0x7fc110c735f5 in /usr/local/miniconda3/lib/python3.6gpu.cpython-36m-x86_64-linux-gnu.so)

Could you please tell me how can I modify the code to support fp 16? Thank you very much!

Hi does your roi align layer support multi gpu?

Hi,
Does your roi align layer support multi gpu?
I got the weird result when RoI align layer from yours.. For example, if I use 2 gpu, the number of batch of the output tensor is 2 times less.

Can you check?

Got the ModuleNotFoundError error,please check

File "C:\Users\user\Air-Clothing-MA\roi_align\crop_and_resize.py", line 7, in
import roi_align.crop_and_resize_cpu as crop_and_resize_cpu
ModuleNotFoundError: No module named 'roi_align.crop_and_resize_cpu'

CropAndResize seems to have wrong outputs

Hi,

I am a pytorch beginner. Recently I am trying to implement the ROIAlign in PyTorch with CropAndResize and torch.nn.functional.max_pool2d . But the output is different from torchvision.ops.RoIAlign.

code:

import torch
import torch.nn.functional as F
from torchvision.ops import RoIAlign
from my_roi_align import CropAndResize # I rename the folder as I encountered issures#32


output_size = (3,3)
spatial_scale = 1/4 
sampling_ratio = 2 

x = torch.randn(1, 1, 6, 6)
rois = torch.tensor([[0,1.0,6.6,6.7,10.1]])

x1, y1 = rois[:,1::4] * spatial_scale, rois[:,2::4] * spatial_scale
x2, y2 = rois[:,3::4] * spatial_scale, rois[:,4::4] * spatial_scale
H, W = x.shape[2], x.shape[3]

ya = RoIAlign(output_size, spatial_scale=spatial_scale, sampling_ratio=sampling_ratio)(x, rois)
yb = CropAndResize(sampling_ratio*output_size[1], sampling_ratio*output_size[0])(x, torch.cat([y1/(H-1), x1/(W-1), y2/(H-1), x2/(W-1)], 1), rois[:, 0].int())
yb = F.avg_pool2d(yb, sampling_ratio)

print('ya:\n', ya)
print('yb:\n', yb)
print('IsEqual: ', yb.equal(ya)) 

one case of output:

ya:
 tensor([[[[-0.9476,  0.1967,  0.0017],
          [-0.9198,  0.2392, -0.0529],
          [-0.3397,  0.1514, -0.0426]]]])
yb:
 tensor([[[[-1.0746,  0.1233, -0.0497],
          [-1.3218,  0.2025, -0.1869],
          [-0.5540,  0.1371, -0.1202]]]])
IsEqual:  False

I am not sure whether I have some misunderstanding of RoIAlign or there is some problem in using CropAndResize. I could not appreciate it more if anyone offers help.

When I tested it, it gives an importerror: no module named _crop_and_resize

sudo python tests/test.py

('Unexpected error:', <type 'exceptions.ImportError'>)
Traceback (most recent call last):
File "tests/test.py", line 13, in
from roi_align.crop_and_resize import CropAndResizeFunction
File "/usr/local/lib/python2.7/dist-packages/roi_align-0.0.1-py2.7.egg/roi_align/crop_and_resize.py", line 7, in
from ._ext import crop_and_resize as _backend
File "/usr/local/lib/python2.7/dist-packages/roi_align-0.0.1-py2.7.egg/roi_align/_ext/crop_and_resize/init.py", line 3, in
from ._crop_and_resize import lib as _lib, ffi as _ffi
ImportError: No module named _crop_and_resize

error with test.py

Hi,
When i run test.py, there is an error occured, as follows:
F tensorflow/stream_executor/cuda/cuda_driver.cc:334] current context was not created by the StreamExecutor cuda_driver API: 0x3af31a0; a CUDA runtime call was likely performed without using a StreamExecutor context
I only have a GPU ,what should i do ?
Thanks

"IndexError: _Map_base::at" when calling `CropAndResize`

🐛 Bug

I updated the conda environment I use for my project (based on PyTorch Lightning and PyTorch), and I'm now getting an error when making the following call (where x is a Tensor):

from roi_align import CropAndResize
CropAndResize(height, width)(x, roi_bbox_hat, torch.arange(x.shape[0], dtype=torch.int32, device=x.device))

The error I'm getting is the following:

Traceback (most recent call last):
  [...]
  File "my_code.py", line XX, in forward
    cropped_x = CropAndResize(height, width)(x, roi_bbox_hat, torch.arange(x.shape[0], dtype=torch.int32, device=x.device))
  File "$CONDA_ENV_PATH/lib/python3.8/site-packages/torch/nn/modules/module.py", line 720, in _call_impl
    result = self._slow_forward(*input, **kwargs)
  File "$CONDA_ENV_PATH/lib/python3.8/site-packages/torch/nn/modules/module.py", line 704, in _slow_forward
    result = self.forward(*input, **kwargs)
  File "$CONDA_ENV_PATH/lib/python3.8/site-packages/roi_align/crop_and_resize.py", line 70, in forward
    return CropAndResizeFunction.apply(image, boxes, box_ind, self.crop_height, self.crop_width, self.extrapolation_value)
  File "$CONDA_ENV_PATH/lib/python3.8/site-packages/roi_align/crop_and_resize.py", line 23, in forward
    crop_and_resize_gpu.forward(
IndexError: _Map_base::at
python-BaseException

Prior to the update, I was using PyTorch Lightning 0.8.5 with PyTorch 1.5. I assume the cause of the error is related to the update from PyTorch 1.5 to 1.6 (since it's a major update), but I can't pinpoint the exact cause. Does anyone have clues about the cause of the error and/or suggestions on how to fix it?

Environment

Below is my configuration following the update (I didn't change any of the hardware).

  • CUDA:
    - GPU: TITAN Xp
    - available: True
    - version: 10.2
  • Packages:
    - numpy: 1.19.1
    - pyTorch_debug: False
    - pyTorch_version: 1.6.0
    - pytorch-lightning: 0.9.0
    - tensorboard: 2.2.0
    - tqdm: 4.48.2
  • System:
    - OS: Linux
    - architecture: 64bit, ELF
    - processor: x86_64
    - python: 3.8.5
    - version: #56~18.04.1-Ubuntu SMP

TypeError from crop_and_resize.py : "initializer for ctype 'struct THCudaTensor *' must be a pointer to same type, not cdata 'struct THFloatTensor *"

Hi, I am trying to use the CropAndResize function on a GPU and am getting the following error. Does anyone have any suggestions? I am running with Python 3.7 and Pytorch 0.4.1.

X_conv451_crop = CropAndResizeFunction(self.crop_height, self.crop_width, 0)(X_conv451_torch, boxes, box_index) File "/home/kdo/anaconda3/envs/honours/lib/python3.7/site-packages/roi_align-0.0.1-py3.7.egg/roi_align/crop_and_resize.py", line 23, in forward self.extrapolation_value, self.crop_height, self.crop_width, crops) File "/home/kdo/anaconda3/envs/honours/lib/python3.7/site-packages/torch/utils/ffi/__init__.py", line 202, in safe_call result = torch._C._safe_call(*args, **kwargs) TypeError: initializer for ctype 'struct THCudaTensor *' must be a pointer to same type, not cdata 'struct THFloatTensor *'

pytorch-1.0

Hi,
I cannot install your RoIAlign with the latest pytorch version (stable 1.0). I get the following error when I run the install.sh:

Compiling crop_and_resize kernels by nvcc...
./install.sh: ligne 7: /usr/local/cuda/bin/nvcc: Aucun fichier ou dossier de ce type
Traceback (most recent call last):
  File "build.py", line 3, in <module>
    from torch.utils.ffi import create_extension
  File "/home/fbaradel/anaconda3/envs/pytorch-1.0/lib/python3.6/site-packages/torch/utils/ffi/__init__.py", line 1, in <module>
    raise ImportError("torch.utils.ffi is deprecated. Please use cpp extensions instead.")
ImportError: torch.utils.ffi is deprecated. Please use cpp extensions instead.
running install
running bdist_egg
running egg_info
creating roi_align.egg-info
writing roi_align.egg-info/PKG-INFO
writing dependency_links to roi_align.egg-info/dependency_links.txt
writing requirements to roi_align.egg-info/requires.txt
writing top-level names to roi_align.egg-info/top_level.txt
writing manifest file 'roi_align.egg-info/SOURCES.txt'
reading manifest file 'roi_align.egg-info/SOURCES.txt'
writing manifest file 'roi_align.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-x86_64/egg
running install_lib
running build_py
creating build
creating build/lib
creating build/lib/roi_align
copying roi_align/build.py -> build/lib/roi_align
copying roi_align/crop_and_resize.py -> build/lib/roi_align
copying roi_align/roi_align.py -> build/lib/roi_align
copying roi_align/__init__.py -> build/lib/roi_align
creating build/lib/roi_align/_ext
copying roi_align/_ext/__init__.py -> build/lib/roi_align/_ext
creating build/lib/roi_align/_ext/crop_and_resize
copying roi_align/_ext/crop_and_resize/__init__.py -> build/lib/roi_align/_ext/crop_and_resize
creating build/bdist.linux-x86_64
creating build/bdist.linux-x86_64/egg
creating build/bdist.linux-x86_64/egg/roi_align
copying build/lib/roi_align/build.py -> build/bdist.linux-x86_64/egg/roi_align
copying build/lib/roi_align/crop_and_resize.py -> build/bdist.linux-x86_64/egg/roi_align
creating build/bdist.linux-x86_64/egg/roi_align/_ext
creating build/bdist.linux-x86_64/egg/roi_align/_ext/crop_and_resize
copying build/lib/roi_align/_ext/crop_and_resize/__init__.py -> build/bdist.linux-x86_64/egg/roi_align/_ext/crop_and_resize
copying build/lib/roi_align/_ext/__init__.py -> build/bdist.linux-x86_64/egg/roi_align/_ext
copying build/lib/roi_align/roi_align.py -> build/bdist.linux-x86_64/egg/roi_align
copying build/lib/roi_align/__init__.py -> build/bdist.linux-x86_64/egg/roi_align
byte-compiling build/bdist.linux-x86_64/egg/roi_align/build.py to build.cpython-36.pyc
byte-compiling build/bdist.linux-x86_64/egg/roi_align/crop_and_resize.py to crop_and_resize.cpython-36.pyc
byte-compiling build/bdist.linux-x86_64/egg/roi_align/_ext/crop_and_resize/__init__.py to __init__.cpython-36.pyc
byte-compiling build/bdist.linux-x86_64/egg/roi_align/_ext/__init__.py to __init__.cpython-36.pyc
byte-compiling build/bdist.linux-x86_64/egg/roi_align/roi_align.py to roi_align.cpython-36.pyc
byte-compiling build/bdist.linux-x86_64/egg/roi_align/__init__.py to __init__.cpython-36.pyc
creating build/bdist.linux-x86_64/egg/EGG-INFO
copying roi_align.egg-info/PKG-INFO -> build/bdist.linux-x86_64/egg/EGG-INFO
copying roi_align.egg-info/SOURCES.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying roi_align.egg-info/dependency_links.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying roi_align.egg-info/requires.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying roi_align.egg-info/top_level.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
zip_safe flag not set; analyzing archive contents...
roi_align.__pycache__.build.cpython-36: module references __file__
creating dist
creating 'dist/roi_align-0.0.1-py3.6.egg' and adding 'build/bdist.linux-x86_64/egg' to it
removing 'build/bdist.linux-x86_64/egg' (and everything under it)
Processing roi_align-0.0.1-py3.6.egg
creating /home/fbaradel/anaconda3/envs/pytorch-1.0/lib/python3.6/site-packages/roi_align-0.0.1-py3.6.egg
Extracting roi_align-0.0.1-py3.6.egg to /home/fbaradel/anaconda3/envs/pytorch-1.0/lib/python3.6/site-packages
Adding roi-align 0.0.1 to easy-install.pth file

Installed /home/fbaradel/anaconda3/envs/pytorch-1.0/lib/python3.6/site-packages/roi_align-0.0.1-py3.6.egg
Processing dependencies for roi-align==0.0.1
Searching for cffi==1.11.5
Best match: cffi 1.11.5
Adding cffi 1.11.5 to easy-install.pth file

Using /home/fbaradel/anaconda3/envs/pytorch-1.0/lib/python3.6/site-packages
Searching for pycparser==2.19
Best match: pycparser 2.19
Adding pycparser 2.19 to easy-install.pth file

Using /home/fbaradel/anaconda3/envs/pytorch-1.0/lib/python3.6/site-packages
Finished processing dependencies for roi-align==0.0.1

It seems that the create_extension has moved somewhere else...
Thanks for your answer.

RuntimeError: image.is_contiguous()INTERNAL ASSERT FAILED at ".\\RoIAlign\\roi_align\\src\\crop_and_resize_gpu.cpp":27, please report a bug to PyTorch. image must be contiguous

Hellow ,thanks for your work.
I reload this work in pytorch1.11.0 and foud a RuntimeError

The error log follows:

Traceback (most recent call last):
  File "c:/Users/29006/Desktop/GAR/scripts/train_volleyball_stage1.py", line 21, in <module>
    train_net(cfg)
  File ".\train_net.py", line 110, in train_net
    return forward_call(*input, **kwargs)
  File ".\base_model.py", line 117, in forward
    boxes_idx_flat)  #B*T*N, D, K, K,
  File "D:\Anaconda\envs\GCN\lib\site-packages\torch\nn\modules\module.py", line 1110, in _call_impl
    return forward_call(*input, **kwargs)
  File "D:\Anaconda\envs\GCN\lib\site-packages\roi_align-0.0.2-py3.7-win-amd64.egg\roi_align\roi_align.py", line 48, in forward
    return CropAndResizeFunction.apply(featuremap, boxes, box_ind, self.crop_height, self.crop_width, self.extrapolation_value)
  File "D:\Anaconda\envs\GCN\lib\site-packages\roi_align-0.0.2-py3.7-win-amd64.egg\roi_align\crop_and_resize.py", line 25, in forward        
    ctx.extrapolation_value, ctx.crop_height, ctx.crop_width, crops)
RuntimeError: image.is_contiguous()INTERNAL ASSERT FAILED at "C:\\Users\\29006\\Desktop\\RoIAlign\\roi_align\\src\\crop_and_resize_gpu.cpp":27, please report a bug to PyTorch. image must be contiguous

So, does any one can solve this?

‘’Legacy autograd function with non-static forward method is deprecated.” on Pytorch 1.5

When I use this function on Pytorch 1.5, there is an error like that :

RuntimeError: Legacy autograd function with non-static forward method is deprecated. Please use new-sty le autograd function with static forward method. (Example: https://pytorch.org/docs/stable/autograd.htm l#torch.autograd.Function)

But there exists @staticmethod before forward and backward function. Did anyone encounter this problem?How to solve it?

Hi gradcheck failed

Hi thanks for sharing your implementation.

I want to use RoIAlign layer in my pytorch code, and I found your implementation.
To verify your implementation, I ran the test.py and the gradcheck failed.
Did you check the code?

ModuleNotFoundError: No module named 'roi_align.crop_and_resize_cpu'

I am using anaconda 3. When I run

python setup.py install

it works fine without any errors:

running install
running bdist_egg
running egg_info
creating roi_align.egg-info
writing roi_align.egg-info/PKG-INFO
writing dependency_links to roi_align.egg-info/dependency_links.txt
writing requirements to roi_align.egg-info/requires.txt
writing top-level names to roi_align.egg-info/top_level.txt
writing manifest file 'roi_align.egg-info/SOURCES.txt'
reading manifest file 'roi_align.egg-info/SOURCES.txt'
writing manifest file 'roi_align.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-x86_64/egg
running install_lib
running build_py
creating build
creating build/lib.linux-x86_64-3.7
creating build/lib.linux-x86_64-3.7/roi_align
copying roi_align/crop_and_resize.py -> build/lib.linux-x86_64-3.7/roi_align
copying roi_align/__init__.py -> build/lib.linux-x86_64-3.7/roi_align
copying roi_align/roi_align.py -> build/lib.linux-x86_64-3.7/roi_align
running build_ext
building 'roi_align.crop_and_resize_cpu' extension
creating build/temp.linux-x86_64-3.7
creating build/temp.linux-x86_64-3.7/roi_align
creating build/temp.linux-x86_64-3.7/roi_align/src
gcc -pthread -B /home/kirill/workspace/software/anaconda3/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/home/kirill/workspace/software/anaconda3/lib/python3.7/site-packages/torch/include -I/home/kirill/workspace/software/anaconda3/lib/python3.7/site-packages/torch/include/torch/csrc/api/include -I/home/kirill/workspace/software/anaconda3/lib/python3.7/site-packages/torch/include/TH -I/home/kirill/workspace/software/anaconda3/lib/python3.7/site-packages/torch/include/THC -I/home/kirill/workspace/software/anaconda3/include/python3.7m -c roi_align/src/crop_and_resize.cpp -o build/temp.linux-x86_64-3.7/roi_align/src/crop_and_resize.o -DTORCH_API_INCLUDE_EXTENSION_H -DTORCH_EXTENSION_NAME=crop_and_resize_cpu -D_GLIBCXX_USE_CXX11_ABI=0 -std=c++11
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++
roi_align/src/crop_and_resize.cpp:31:0: warning: ignoring #pragma omp parallel [-Wunknown-pragmas]
     #pragma omp parallel for
 
g++ -pthread -shared -B /home/kirill/workspace/software/anaconda3/compiler_compat -L/home/kirill/workspace/software/anaconda3/lib -Wl,-rpath=/home/kirill/workspace/software/anaconda3/lib -Wl,--no-as-needed -Wl,--sysroot=/ build/temp.linux-x86_64-3.7/roi_align/src/crop_and_resize.o -o build/lib.linux-x86_64-3.7/roi_align/crop_and_resize_cpu.cpython-37m-x86_64-linux-gnu.so
building 'roi_align.crop_and_resize_gpu' extension
creating build/temp.linux-x86_64-3.7/roi_align/src/cuda
gcc -pthread -B /home/kirill/workspace/software/anaconda3/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/home/kirill/workspace/software/anaconda3/lib/python3.7/site-packages/torch/include -I/home/kirill/workspace/software/anaconda3/lib/python3.7/site-packages/torch/include/torch/csrc/api/include -I/home/kirill/workspace/software/anaconda3/lib/python3.7/site-packages/torch/include/TH -I/home/kirill/workspace/software/anaconda3/lib/python3.7/site-packages/torch/include/THC -I/usr/local/cuda/include -I/home/kirill/workspace/software/anaconda3/include/python3.7m -c roi_align/src/crop_and_resize_gpu.cpp -o build/temp.linux-x86_64-3.7/roi_align/src/crop_and_resize_gpu.o -g -fopenmp -DTORCH_API_INCLUDE_EXTENSION_H -DTORCH_EXTENSION_NAME=crop_and_resize_gpu -D_GLIBCXX_USE_CXX11_ABI=0 -std=c++11
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++
/usr/local/cuda/bin/nvcc -I/home/kirill/workspace/software/anaconda3/lib/python3.7/site-packages/torch/include -I/home/kirill/workspace/software/anaconda3/lib/python3.7/site-packages/torch/include/torch/csrc/api/include -I/home/kirill/workspace/software/anaconda3/lib/python3.7/site-packages/torch/include/TH -I/home/kirill/workspace/software/anaconda3/lib/python3.7/site-packages/torch/include/THC -I/usr/local/cuda/include -I/home/kirill/workspace/software/anaconda3/include/python3.7m -c roi_align/src/cuda/crop_and_resize_kernel.cu -o build/temp.linux-x86_64-3.7/roi_align/src/cuda/crop_and_resize_kernel.o -D__CUDA_NO_HALF_OPERATORS__ -D__CUDA_NO_HALF_CONVERSIONS__ -D__CUDA_NO_HALF2_OPERATORS__ --compiler-options '-fPIC' -O2 -DTORCH_API_INCLUDE_EXTENSION_H -DTORCH_EXTENSION_NAME=crop_and_resize_gpu -D_GLIBCXX_USE_CXX11_ABI=0 -std=c++11
g++ -pthread -shared -B /home/kirill/workspace/software/anaconda3/compiler_compat -L/home/kirill/workspace/software/anaconda3/lib -Wl,-rpath=/home/kirill/workspace/software/anaconda3/lib -Wl,--no-as-needed -Wl,--sysroot=/ build/temp.linux-x86_64-3.7/roi_align/src/crop_and_resize_gpu.o build/temp.linux-x86_64-3.7/roi_align/src/cuda/crop_and_resize_kernel.o -L/usr/local/cuda/lib64 -lcudart -o build/lib.linux-x86_64-3.7/roi_align/crop_and_resize_gpu.cpython-37m-x86_64-linux-gnu.so
creating build/bdist.linux-x86_64
creating build/bdist.linux-x86_64/egg
creating build/bdist.linux-x86_64/egg/roi_align
copying build/lib.linux-x86_64-3.7/roi_align/crop_and_resize.py -> build/bdist.linux-x86_64/egg/roi_align
copying build/lib.linux-x86_64-3.7/roi_align/crop_and_resize_gpu.cpython-37m-x86_64-linux-gnu.so -> build/bdist.linux-x86_64/egg/roi_align
copying build/lib.linux-x86_64-3.7/roi_align/__init__.py -> build/bdist.linux-x86_64/egg/roi_align
copying build/lib.linux-x86_64-3.7/roi_align/crop_and_resize_cpu.cpython-37m-x86_64-linux-gnu.so -> build/bdist.linux-x86_64/egg/roi_align
copying build/lib.linux-x86_64-3.7/roi_align/roi_align.py -> build/bdist.linux-x86_64/egg/roi_align
byte-compiling build/bdist.linux-x86_64/egg/roi_align/crop_and_resize.py to crop_and_resize.cpython-37.pyc
byte-compiling build/bdist.linux-x86_64/egg/roi_align/__init__.py to __init__.cpython-37.pyc
byte-compiling build/bdist.linux-x86_64/egg/roi_align/roi_align.py to roi_align.cpython-37.pyc
creating stub loader for roi_align/crop_and_resize_cpu.cpython-37m-x86_64-linux-gnu.so
creating stub loader for roi_align/crop_and_resize_gpu.cpython-37m-x86_64-linux-gnu.so
byte-compiling build/bdist.linux-x86_64/egg/roi_align/crop_and_resize_cpu.py to crop_and_resize_cpu.cpython-37.pyc
byte-compiling build/bdist.linux-x86_64/egg/roi_align/crop_and_resize_gpu.py to crop_and_resize_gpu.cpython-37.pyc
creating build/bdist.linux-x86_64/egg/EGG-INFO
copying roi_align.egg-info/PKG-INFO -> build/bdist.linux-x86_64/egg/EGG-INFO
copying roi_align.egg-info/SOURCES.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying roi_align.egg-info/dependency_links.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying roi_align.egg-info/requires.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying roi_align.egg-info/top_level.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
writing build/bdist.linux-x86_64/egg/EGG-INFO/native_libs.txt
zip_safe flag not set; analyzing archive contents...
roi_align.__pycache__.crop_and_resize_cpu.cpython-37: module references __file__
roi_align.__pycache__.crop_and_resize_gpu.cpython-37: module references __file__
creating dist
creating 'dist/roi_align-0.0.1-py3.7-linux-x86_64.egg' and adding 'build/bdist.linux-x86_64/egg' to it
removing 'build/bdist.linux-x86_64/egg' (and everything under it)
Processing roi_align-0.0.1-py3.7-linux-x86_64.egg
removing '/home/kirill/workspace/software/anaconda3/lib/python3.7/site-packages/roi_align-0.0.1-py3.7-linux-x86_64.egg' (and everything under it)
creating /home/kirill/workspace/software/anaconda3/lib/python3.7/site-packages/roi_align-0.0.1-py3.7-linux-x86_64.egg
Extracting roi_align-0.0.1-py3.7-linux-x86_64.egg to /home/kirill/workspace/software/anaconda3/lib/python3.7/site-packages
roi-align 0.0.1 is already the active version in easy-install.pth

Installed /home/kirill/workspace/software/anaconda3/lib/python3.7/site-packages/roi_align-0.0.1-py3.7-linux-x86_64.egg
Processing dependencies for roi-align==0.0.1
Searching for torch==1.1.0
Best match: torch 1.1.0
Adding torch 1.1.0 to easy-install.pth file
Installing convert-caffe2-to-onnx script to /home/kirill/workspace/software/anaconda3/bin
Installing convert-onnx-to-caffe2 script to /home/kirill/workspace/software/anaconda3/bin

Using /home/kirill/workspace/software/anaconda3/lib/python3.7/site-packages
Searching for numpy==1.16.2
Best match: numpy 1.16.2
Adding numpy 1.16.2 to easy-install.pth file
Installing f2py script to /home/kirill/workspace/software/anaconda3/bin
Installing f2py3 script to /home/kirill/workspace/software/anaconda3/bin
Installing f2py3.7 script to /home/kirill/workspace/software/anaconda3/bin

Using /home/kirill/workspace/software/anaconda3/lib/python3.7/site-packages
Finished processing dependencies for roi-align==0.0.1

However, when I run

./test.sh

it outputs the following:

Unexpected error: <class 'ModuleNotFoundError'>
Traceback (most recent call last):
  File "tests/test.py", line 13, in <module>
    from roi_align.crop_and_resize import CropAndResizeFunction
  File "/data/kirill/volleyball_activity/software/RoIAlign.pytorch/roi_align/__init__.py", line 1, in <module>
    from .roi_align import RoIAlign, CropAndResizeFunction
  File "/data/kirill/volleyball_activity/software/RoIAlign.pytorch/roi_align/roi_align.py", line 4, in <module>
    from .crop_and_resize import CropAndResizeFunction, CropAndResize
  File "/data/kirill/volleyball_activity/software/RoIAlign.pytorch/roi_align/crop_and_resize.py", line 7, in <module>
    import roi_align.crop_and_resize_cpu as crop_and_resize_cpu
ModuleNotFoundError: No module named 'roi_align.crop_and_resize_cpu'
Traceback (most recent call last):
  File "tests/test2.py", line 5, in <module>
    from roi_align.roi_align import RoIAlign
  File "/data/kirill/volleyball_activity/software/RoIAlign.pytorch/roi_align/__init__.py", line 1, in <module>
    from .roi_align import RoIAlign, CropAndResizeFunction
  File "/data/kirill/volleyball_activity/software/RoIAlign.pytorch/roi_align/roi_align.py", line 4, in <module>
    from .crop_and_resize import CropAndResizeFunction, CropAndResize
  File "/data/kirill/volleyball_activity/software/RoIAlign.pytorch/roi_align/crop_and_resize.py", line 7, in <module>
    import roi_align.crop_and_resize_cpu as crop_and_resize_cpu
ModuleNotFoundError: No module named 'roi_align.crop_and_resize_cpu'
Traceback (most recent call last):
  File "tests/crop_and_resize_example.py", line 5, in <module>
    from roi_align.crop_and_resize import CropAndResizeFunction
  File "/data/kirill/volleyball_activity/software/RoIAlign.pytorch/roi_align/__init__.py", line 1, in <module>
    from .roi_align import RoIAlign, CropAndResizeFunction
  File "/data/kirill/volleyball_activity/software/RoIAlign.pytorch/roi_align/roi_align.py", line 4, in <module>
    from .crop_and_resize import CropAndResizeFunction, CropAndResize
  File "/data/kirill/volleyball_activity/software/RoIAlign.pytorch/roi_align/crop_and_resize.py", line 7, in <module>
    import roi_align.crop_and_resize_cpu as crop_and_resize_cpu
ModuleNotFoundError: No module named 'roi_align.crop_and_resize_cpu'

What could be the reason of the problem? How to fix it?

output roi all zeros

Hi I tried to test ROIAlign on images with rois = roi_align(detections, boxes, box_index)
detections' shape is torch.Size([1, 3, 271, 271]) and boxes looks like
tensor([[ 151.6779, 18.8237, 270.0000, 84.2876], [ 175.6971, 9.2199, 255.9987, 92.7847], [ 165.4188, 0.0000, 233.8400, 119.7061], [ 134.8676, 25.9375, 270.0000, 79.1737]], device='cuda:0')
and box_index looks like
tensor([ 0, 0, 0, 0], dtype=torch.int8, device='cuda:0')
The output shape is (4, 50, 50, 3), which means 4 cropped images.
But I got only the first image that looks
correct and the rest 3 are all zeros.
0
1
2
3

from ._crop_and_resize import lib as _lib, ffi as _ffi ModuleNotFoundError: No module named 'roi_align._ext.crop_and_resize._crop_and_resize'

when i test,i saw the problem.
how can i solve it?
ying@ying-TM1701:/下载/RoIAlign.pytorch-pytorch_0.4$ ./tests
bash: ./tests: 是一个目录
(pytorch0.4.1_group) ying@ying-TM1701:
/下载/RoIAlign.pytorch-pytorch_0.4$ ./test.sh
Unexpected error: <class 'ModuleNotFoundError'>
Traceback (most recent call last):
File "tests/test.py", line 13, in
from roi_align.crop_and_resize import CropAndResizeFunction
File "/home/ying/.conda/envs/pytorch0.4.1_group/lib/python3.6/site-packages/roi_align-0.0.1-py3.6.egg/roi_align/crop_and_resize.py", line 7, in
from ._ext import crop_and_resize as _backend
File "/home/ying/.conda/envs/pytorch0.4.1_group/lib/python3.6/site-packages/roi_align-0.0.1-py3.6.egg/roi_align/_ext/crop_and_resize/init.py", line 3, in
from ._crop_and_resize import lib as _lib, ffi as _ffi
ModuleNotFoundError: No module named 'roi_align._ext.crop_and_resize._crop_and_resize'
Traceback (most recent call last):
File "tests/test2.py", line 5, in
from roi_align.roi_align import RoIAlign
File "/home/ying/.conda/envs/pytorch0.4.1_group/lib/python3.6/site-packages/roi_align-0.0.1-py3.6.egg/roi_align/roi_align.py", line 4, in
from .crop_and_resize import CropAndResizeFunction, CropAndResize
File "/home/ying/.conda/envs/pytorch0.4.1_group/lib/python3.6/site-packages/roi_align-0.0.1-py3.6.egg/roi_align/crop_and_resize.py", line 7, in
from ._ext import crop_and_resize as _backend
File "/home/ying/.conda/envs/pytorch0.4.1_group/lib/python3.6/site-packages/roi_align-0.0.1-py3.6.egg/roi_align/_ext/crop_and_resize/init.py", line 3, in
from ._crop_and_resize import lib as _lib, ffi as _ffi
ModuleNotFoundError: No module named 'roi_align._ext.crop_and_resize._crop_and_resize'
Traceback (most recent call last):
File "tests/crop_and_resize_example.py", line 5, in
from roi_align.crop_and_resize import CropAndResizeFunction
File "/home/ying/.conda/envs/pytorch0.4.1_group/lib/python3.6/site-packages/roi_align-0.0.1-py3.6.egg/roi_align/crop_and_resize.py", line 7, in
from ._ext import crop_and_resize as _backend
File "/home/ying/.conda/envs/pytorch0.4.1_group/lib/python3.6/site-packages/roi_align-0.0.1-py3.6.egg/roi_align/_ext/crop_and_resize/init.py", line 3, in
from ._crop_and_resize import lib as _lib, ffi as _ffi
ModuleNotFoundError: No module named 'roi_align._ext.crop_and_resize._crop_and_resize'

ImportError: No module named crop_and_resize_cpu

deep-server@server:~/Air-Clothing-MA$ python file_demo.py
Traceback (most recent call last):
File "file_demo.py", line 10, in
from model import EncoderClothing, DecoderClothing
File "/home/deep-server/Air-Clothing-MA/model.py", line 6, in
from roi_align.roi_align import RoIAlign
File "build/bdist.linux-x86_64/egg/roi_align/init.py", line 1, in
File "build/bdist.linux-x86_64/egg/roi_align/roi_align.py", line 4, in
File "build/bdist.linux-x86_64/egg/roi_align/crop_and_resize.py", line 7, in
ImportError: No module named crop_and_resize_cpu

image

pytorch1.0 ffi was deprecated

Traceback (most recent call last):
File "build.py", line 3, in
from torch.utils.ffi import create_extension
File "/home/lzy/.local/lib/python2.7/site-packages/torch/utils/ffi/init.py", line 1, in
raise ImportError("torch.utils.ffi is deprecated. Please use cpp extensions instead.")
ImportError: torch.utils.ffi is deprecated. Please use cpp extensions instead.

fail to install in window10

Thank you for the RoIAlign for pytorch.

When i try to install in window 10, with pytorch 1.0 it fails with the following errors.

  1. lib\site-packages\torch\utils\cpp_extension.py:184: UserWarning: Error checking compiler version for cl: [WinError 2] The system cannot find the file specified
    warnings.warn('Error checking compiler version for {}: {}'.format(compiler, error))

  2. c1xx: fatal error C1083: Cannot open source file: 'roi_align/src/crop_and_resize.cpp': No such file or directory
    error: command 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.14.26428\bin\HostX86\x64\cl.exe' failed with exit status 2

How can I solve this?

import problem

Can we just import the .cpp file?As a beginner I can not import the crop_and_resize_gpu.cpp,what should i do,thank you

Crop height and Crop width

I get the following issue for Extrapolation value:

TypeError: initializer for ctype 'struct THCudaIntTensor *' must be a pointer to same type, not cdata 'struct THCudaLongTensor *'

License

Hello everyone,

First of all, thanks for the material!
I tried to look for the licensing terms under which the software is distributed, but I did not find anything. Since it is inspired by a Tensorflow function, I guess that everything is under Apache 2.0.
Am I correct? :-)

Thanks a lot,
Matteo

Problem on box_ind

Hi All,

I noticed that this RoI Align takes three inputs:
crops = roi_align(image, boxes, box_index)
I am now wondering how the box_index should be prepared? Thanks.

兄弟,你这没按定义吧

bro 测试用例的输出按照maskrcnn里align的定义

输出应该是
crops: tensor([[[[15.0000, 16.0000, 17.0000, 18.0000],
|||||||||||||||||||||||||||||[22.0000, 23.0000, 24.0000, 25.0000],
|||||||||||||||||||||||||||||[29.0000, 30.0000, 31.0000, 32.0000],
|||||||||||||||||||||||||||||[36.0000, 37.0000, 38.0000, 39.0000]]],

|||||||||||||||||||||||||||[[[28.5000, 29.3750, 30.2500, 31.1250],
|||||||||||||||||||||||||||||[34.6250, 35.5000, 36.3750, 37.2500],
|||||||||||||||||||||||||||||[40.7500, 41.6250, 42.5000, 43.3750],
|||||||||||||||||||||||||||||[42.9375, 43.8125, 44.6875, 45.5625]]]])

我用
https://github.com/jwyang/faster-rcnn.pytorch
https://github.com/timy90022/One-Shot-Object-Detection

提供的库测出来都是我这个输出

GPU support

Hi,
thank you very much for this code!

The code works fine for me if I change the capability of the gpu in make.sh as:

$CUDA_PATH/bin/nvcc -c -o crop_and_resize_kernel.cu.o crop_and_resize_kernel.cu -x cu -Xcompiler -fPIC -arch=sm_50

Because I have a GPU with 5.0 capability which is slightly less than sm_52 as you wrote. Maybe it is worth mentioning it in the README to check the capability of the GPU before building.

Error compiling objects for extension (PyTorch=1.9.0 in anaconda)?

Hi,

I am getting the following compiling error. Does RoIAlign work with Pytorch 1.9.0?

  File "C:\Users\...\Anaconda3\lib\site-packages\torch\utils\cpp_extension.py", line 1682, in _run_ninja_build
    raise RuntimeError(message) from e

RuntimeError: Error compiling objects for extension

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.