Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ Currently it only works using the default GPU (index 0)
./test.sh
```

## Adjust
+ Build and test
```
export CUDA_HOME=/usr/local/cuda-11.3
python setup.py build
```
Move the compiled dynamic link library to the *roi_align* file directory, Then start testing
```
./test.sh
```

+ Use RoIAlign or crop_and_resize

Since PyTorch 1.2.0 [Legacy autograd function with non-static forward method is deprecated.](https://github.com/pytorch/pytorch/blob/fdfc676eb6c4d9f50496e564976fbe6d124e23a5/torch/csrc/autograd/python_function.cpp#L636-L638)
Expand Down
2 changes: 2 additions & 0 deletions tests/crop_and_resize_example.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import sys, os
sys.path.append(os.getcwd())
import torch
from torch import nn
from torchvision import transforms, utils
Expand Down
2 changes: 2 additions & 0 deletions tests/test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import sys, os
sys.path.append(os.getcwd())
import numpy as np
import torch
import sys
Expand Down
6 changes: 5 additions & 1 deletion tests/test2.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import sys, os
sys.path.append(os.getcwd())
import numpy as np
import torch
from torch.autograd import Variable
Expand Down Expand Up @@ -25,4 +27,6 @@ def to_varabile(arr, requires_grad=False, is_cuda=True):
box_index = to_varabile(box_index_data, requires_grad=False, is_cuda=is_cuda)

# set transform_fpcoor to False is the crop_and_resize
print(RoIAlign.apply(image_torch, boxes, box_index, 3, 3, transform_fpcoor=True))
roi_align =RoIAlign(3, 3, transform_fpcoor=True)
print(roi_align(image_torch, boxes, box_index))
# print(RoIAlign.apply(image_torch, boxes, box_index, 3, 3, transform_fpcoor=True))
27 changes: 27 additions & 0 deletions tests/test3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import torch
import sys,os
sys.path.append(os.getcwd())
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)