Skip to content

Commit 333ac7a

Browse files
authored
Revert "Porting this code to Windows"
1 parent 009d7a9 commit 333ac7a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+95
-6779
lines changed

.gitignore

-14
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,3 @@
11
data/*
22
*.pyc
33
*~
4-
/images - Copy
5-
*.pyd
6-
*.ipch
7-
*.tlog
8-
*.deps
9-
*.cache
10-
*.obj
11-
*.log
12-
*.pdb
13-
/vgg16_caffe.pth
14-
/windows/.vs/faster_rcnn/v15
15-
*.dll
16-
*.lib
17-
/.vs/FasterRCNN/v15

FasterRCNN.pyproj

-6,074
This file was deleted.

FasterRCNN.sln

-23
This file was deleted.

README.md

+2-4
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,8 @@ Install all the python dependencies using pip:
149149
pip install -r requirements.txt
150150
```
151151

152-
if bulid on windows, please click [README.md](./windows/README.md).
153-
154-
else compile the cuda dependencies using following simple commands:
155-
152+
Compile the cuda dependencies using following simple commands:
153+
156154
```
157155
cd lib
158156
sh make.sh

demo.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ def parse_args():
5555
default='cfgs/vgg16.yml', type=str)
5656
parser.add_argument('--net', dest='net',
5757
help='vgg16, res50, res101, res152',
58-
default='vgg16', type=str)
58+
default='res101', type=str)
5959
parser.add_argument('--set', dest='set_cfgs',
6060
help='set config keys', default=None,
6161
nargs=argparse.REMAINDER)
6262
parser.add_argument('--load_dir', dest='load_dir',
6363
help='directory to load models',
64-
default="F:/Pascal/faster_rcnn_pytorch")
64+
default="/srv/share/jyang375/models")
6565
parser.add_argument('--image_dir', dest='image_dir',
6666
help='directory to load images for demo',
6767
default="images")

images/img1_det.jpg

-1.12 KB
Loading

images/img1_det_res101.jpg

83.8 KB
Loading

images/img2.jpg

111 KB
Loading

images/img2_det.jpg

111 KB
Loading

images/img2_det_res101.jpg

111 KB
Loading

images/img3.jpg

100 KB
Loading

images/img3_det.jpg

105 KB
Loading

images/img3_det_res101.jpg

105 KB
Loading

images/img4_det.jpg

-103 Bytes
Loading

images/img4_det_res101.jpg

89.3 KB
Loading

lib/make.sh

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22

3-
CUDA_PATH="A:/NVIDIA/GPU Computing Toolkit/CUDA/v9.1"
3+
CUDA_PATH=/usr/local/cuda/
44

55
python setup.py build_ext --inplace
66
rm -rf build
@@ -15,8 +15,8 @@ CUDA_ARCH="-gencode arch=compute_30,code=sm_30 \
1515
# compile NMS
1616
cd model/nms/src
1717
echo "Compiling nms kernels by nvcc..."
18-
#nvcc -c -o nms_cuda_kernel.lib nms_cuda_kernel.cu \
19-
# -D GOOGLE_CUDA=1 -x cu -Xcompiler -fPIC $CUDA_ARCH
18+
nvcc -c -o nms_cuda_kernel.cu.o nms_cuda_kernel.cu \
19+
-D GOOGLE_CUDA=1 -x cu -Xcompiler -fPIC $CUDA_ARCH
2020

2121
cd ../
2222
python build.py
@@ -25,25 +25,25 @@ python build.py
2525
cd ../../
2626
cd model/roi_pooling/src
2727
echo "Compiling roi pooling kernels by nvcc..."
28-
#nvcc -c -o roi_pooling.lib roi_pooling_kernel.cu \
29-
# -D GOOGLE_CUDA=1 -x cu -Xcompiler -fPIC $CUDA_ARCH
28+
nvcc -c -o roi_pooling.cu.o roi_pooling_kernel.cu \
29+
-D GOOGLE_CUDA=1 -x cu -Xcompiler -fPIC $CUDA_ARCH
3030
cd ../
3131
python build.py
3232

3333
# compile roi_align
3434
cd ../../
3535
cd model/roi_align/src
3636
echo "Compiling roi align kernels by nvcc..."
37-
#nvcc -c -o roi_align_kernel.lib roi_align_kernel.cu \
38-
# -D GOOGLE_CUDA=1 -x cu -Xcompiler -fPIC $CUDA_ARCH
37+
nvcc -c -o roi_align_kernel.cu.o roi_align_kernel.cu \
38+
-D GOOGLE_CUDA=1 -x cu -Xcompiler -fPIC $CUDA_ARCH
3939
cd ../
4040
python build.py
4141

4242
# compile roi_crop
4343
cd ../../
4444
cd model/roi_crop/src
4545
echo "Compiling roi crop kernels by nvcc..."
46-
#nvcc -c -o roi_crop_cuda_kernel.lib roi_crop_cuda_kernel.cu \
47-
# -D GOOGLE_CUDA=1 -x cu -Xcompiler -fPIC $CUDA_ARCH
46+
nvcc -c -o roi_crop_cuda_kernel.cu.o roi_crop_cuda_kernel.cu \
47+
-D GOOGLE_CUDA=1 -x cu -Xcompiler -fPIC $CUDA_ARCH
4848
cd ../
4949
python build.py

lib/model/nms/_ext/nms/__init__.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@
66
def _import_symbols(locals):
77
for symbol in dir(_lib):
88
fn = getattr(_lib, symbol)
9-
if callable(fn):
10-
locals[symbol] = _wrap_function(fn, _ffi)
11-
else:
12-
locals[symbol] = fn
9+
locals[symbol] = _wrap_function(fn, _ffi)
1310
__all__.append(symbol)
1411

1512
_import_symbols(locals())

lib/model/nms/build.py

+5-17
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,25 @@
11
from __future__ import print_function
22
import os
3-
import sys
43
import torch
54
from torch.utils.ffi import create_extension
65

76
#this_file = os.path.dirname(__file__)
8-
torch_root = os.path.join(os.path.dirname(sys.executable),
9-
'Lib/site-packages/torch/lib')
10-
cuda_root = os.environ['CUDA_PATH']
117

128
sources = []
139
headers = []
1410
defines = []
15-
include_dirs = []
1611
with_cuda = False
1712

18-
this_file = os.path.dirname(os.path.realpath(__file__))
19-
print(this_file)
20-
2113
if torch.cuda.is_available():
2214
print('Including CUDA code.')
23-
sources += ['src/nms_cuda.cpp']
15+
sources += ['src/nms_cuda.c']
2416
headers += ['src/nms_cuda.h']
25-
include_dirs += [os.path.join(cuda_root,"include"), os.path.join(torch_root,'include')]
2617
defines += [('WITH_CUDA', None)]
2718
with_cuda = True
2819

29-
30-
extra_objects = ['src/nms_cuda_kernel.lib']
31-
extra_objects += [os.path.join(torch_root,'ATen.lib'),
32-
os.path.join(cuda_root,'lib/x64/cudart.lib'),
33-
os.path.join(torch_root,'_C.lib')]
20+
this_file = os.path.dirname(os.path.realpath(__file__))
21+
print(this_file)
22+
extra_objects = ['src/nms_cuda_kernel.cu.o']
3423
extra_objects = [os.path.join(this_file, fname) for fname in extra_objects]
3524
print(extra_objects)
3625

@@ -41,8 +30,7 @@
4130
define_macros=defines,
4231
relative_to=__file__,
4332
with_cuda=with_cuda,
44-
extra_objects=extra_objects,
45-
include_dirs=include_dirs
33+
extra_objects=extra_objects
4634
)
4735

4836
if __name__ == '__main__':

lib/model/nms/src/nms_cuda.c

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include <THC/THC.h>
2+
#include <stdio.h>
3+
#include "nms_cuda_kernel.h"
4+
5+
// this symbol will be resolved automatically from PyTorch libs
6+
extern THCState *state;
7+
8+
int nms_cuda(THCudaIntTensor *keep_out, THCudaTensor *boxes_host,
9+
THCudaIntTensor *num_out, float nms_overlap_thresh) {
10+
11+
nms_cuda_compute(THCudaIntTensor_data(state, keep_out),
12+
THCudaIntTensor_data(state, num_out),
13+
THCudaTensor_data(state, boxes_host),
14+
boxes_host->size[0],
15+
boxes_host->size[1],
16+
nms_overlap_thresh);
17+
18+
return 1;
19+
}

lib/model/nms/src/nms_cuda.h

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// int nms_cuda(THCudaTensor *keep_out, THCudaTensor *num_out,
22
// THCudaTensor *boxes_host, THCudaTensor *nms_overlap_thresh);
3+
34
int nms_cuda(THCudaIntTensor *keep_out, THCudaTensor *boxes_host,
45
THCudaIntTensor *num_out, float nms_overlap_thresh);

lib/model/roi_align/_ext/roi_align/__init__.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@
66
def _import_symbols(locals):
77
for symbol in dir(_lib):
88
fn = getattr(_lib, symbol)
9-
if callable(fn):
10-
locals[symbol] = _wrap_function(fn, _ffi)
11-
else:
12-
locals[symbol] = fn
9+
locals[symbol] = _wrap_function(fn, _ffi)
1310
__all__.append(symbol)
1411

1512
_import_symbols(locals())

lib/model/roi_align/build.py

+9-19
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
from __future__ import print_function
22
import os
3-
import sys
43
import torch
54
from torch.utils.ffi import create_extension
65

7-
8-
torch_root = os.path.join(os.path.dirname(sys.executable),
9-
'Lib/site-packages/torch/lib')
10-
cuda_root = os.environ['CUDA_PATH']
11-
12-
sources = ['src/roi_align.cpp']
6+
sources = ['src/roi_align.c']
137
headers = ['src/roi_align.h']
14-
include_dirs = []
8+
extra_objects = []
9+
#sources = []
10+
#headers = []
1511
defines = []
1612
with_cuda = False
1713

@@ -20,18 +16,13 @@
2016

2117
if torch.cuda.is_available():
2218
print('Including CUDA code.')
23-
sources += ['src/roi_align_cuda.cpp']
19+
sources += ['src/roi_align_cuda.c']
2420
headers += ['src/roi_align_cuda.h']
2521
defines += [('WITH_CUDA', None)]
2622
with_cuda = True
27-
include_dirs += [os.path.join(cuda_root,"include"),
28-
os.path.join(torch_root,'include')]
29-
extra_objects = ['src/roi_align_kernel.lib']
30-
extra_objects = [os.path.join(this_file, fname) for fname in extra_objects]
31-
extra_objects += [os.path.join(torch_root,'ATen.lib'),
32-
os.path.join(cuda_root,'lib/x64/cudart.lib'),
33-
os.path.join(torch_root,'_C.lib')]
34-
print(extra_objects)
23+
24+
extra_objects = ['src/roi_align_kernel.cu.o']
25+
extra_objects = [os.path.join(this_file, fname) for fname in extra_objects]
3526

3627
ffi = create_extension(
3728
'_ext.roi_align',
@@ -40,8 +31,7 @@
4031
define_macros=defines,
4132
relative_to=__file__,
4233
with_cuda=with_cuda,
43-
extra_objects=extra_objects,
44-
include_dirs=include_dirs
34+
extra_objects=extra_objects
4535
)
4636

4737
if __name__ == '__main__':

lib/model/roi_align/src/roi_align.cpp renamed to lib/model/roi_align/src/roi_align.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ void ROIAlignBackwardCpu(const float* top_diff, const float spatial_scale, const
1313
const int aligned_height, const int aligned_width, const float * bottom_rois,
1414
float* top_data);
1515

16-
extern"C" __declspec(dllexport) int roi_align_forward(int aligned_height, int aligned_width, float spatial_scale,
16+
int roi_align_forward(int aligned_height, int aligned_width, float spatial_scale,
1717
THFloatTensor * features, THFloatTensor * rois, THFloatTensor * output)
1818
{
1919
//Grab the input tensor
@@ -44,7 +44,7 @@ extern"C" __declspec(dllexport) int roi_align_forward(int aligned_height, int al
4444
return 1;
4545
}
4646

47-
extern"C" __declspec(dllexport) int roi_align_backward(int aligned_height, int aligned_width, float spatial_scale,
47+
int roi_align_backward(int aligned_height, int aligned_width, float spatial_scale,
4848
THFloatTensor * top_grad, THFloatTensor * rois, THFloatTensor * bottom_grad)
4949
{
5050
//Grab the input tensor

lib/model/roi_align/src/roi_align_cuda.cpp renamed to lib/model/roi_align/src/roi_align_cuda.c

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
#include <THC/THC.h>
22
#include <math.h>
3-
#include <ATen/ATen.h>
43
#include "roi_align_kernel.h"
54

6-
THCState *state = at::globalContext().thc_state;
5+
extern THCState *state;
76

8-
extern"C" __declspec(dllexport) int roi_align_forward_cuda(int aligned_height, int aligned_width, float spatial_scale,
7+
int roi_align_forward_cuda(int aligned_height, int aligned_width, float spatial_scale,
98
THCudaTensor * features, THCudaTensor * rois, THCudaTensor * output)
109
{
1110
// Grab the input tensor
@@ -40,7 +39,7 @@ extern"C" __declspec(dllexport) int roi_align_forward_cuda(int aligned_height, i
4039
return 1;
4140
}
4241

43-
extern"C" __declspec(dllexport) int roi_align_backward_cuda(int aligned_height, int aligned_width, float spatial_scale,
42+
int roi_align_backward_cuda(int aligned_height, int aligned_width, float spatial_scale,
4443
THCudaTensor * top_grad, THCudaTensor * rois, THCudaTensor * bottom_grad)
4544
{
4645
// Grab the input tensor

lib/model/roi_crop/_ext/roi_crop/__init__.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@
66
def _import_symbols(locals):
77
for symbol in dir(_lib):
88
fn = getattr(_lib, symbol)
9-
if callable(fn):
10-
locals[symbol] = _wrap_function(fn, _ffi)
11-
else:
12-
locals[symbol] = fn
9+
locals[symbol] = _wrap_function(fn, _ffi)
1310
__all__.append(symbol)
1411

1512
_import_symbols(locals())

lib/model/roi_crop/build.py

+6-19
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,26 @@
11
from __future__ import print_function
22
import os
3-
import sys
43
import torch
54
from torch.utils.ffi import create_extension
65

76
#this_file = os.path.dirname(__file__)
8-
torch_root = os.path.join(os.path.dirname(sys.executable),
9-
'Lib/site-packages/torch/lib')
10-
cuda_root = os.environ['CUDA_PATH']
117

12-
sources = ['src/roi_crop.cpp']
8+
sources = ['src/roi_crop.c']
139
headers = ['src/roi_crop.h']
14-
include_dirs = []
1510
defines = []
1611
with_cuda = False
1712

18-
this_file = os.path.dirname(os.path.realpath(__file__))
19-
print(this_file)
20-
2113
if torch.cuda.is_available():
2214
print('Including CUDA code.')
23-
sources += ['src/roi_crop_cuda.cpp']
15+
sources += ['src/roi_crop_cuda.c']
2416
headers += ['src/roi_crop_cuda.h']
25-
include_dirs += [os.path.join(cuda_root,"include"),
26-
os.path.join(torch_root,'include')]
2717
defines += [('WITH_CUDA', None)]
2818
with_cuda = True
2919

30-
extra_objects = ['src/roi_crop_cuda_kernel.lib']
20+
this_file = os.path.dirname(os.path.realpath(__file__))
21+
print(this_file)
22+
extra_objects = ['src/roi_crop_cuda_kernel.cu.o']
3123
extra_objects = [os.path.join(this_file, fname) for fname in extra_objects]
32-
extra_objects += [os.path.join(torch_root,'ATen.lib'),
33-
os.path.join(cuda_root,'lib/x64/cudart.lib'),
34-
os.path.join(torch_root,'_C.lib')]
35-
print(extra_objects)
3624

3725
ffi = create_extension(
3826
'_ext.roi_crop',
@@ -41,8 +29,7 @@
4129
define_macros=defines,
4230
relative_to=__file__,
4331
with_cuda=with_cuda,
44-
extra_objects=extra_objects,
45-
include_dirs=include_dirs
32+
extra_objects=extra_objects
4633
)
4734

4835
if __name__ == '__main__':

0 commit comments

Comments
 (0)