Skip to content

Commit 009d7a9

Browse files
authored
Merge pull request jwyang#189 from kingstarcraft/windows
Porting this code to Windows
2 parents 0e6f131 + 4519038 commit 009d7a9

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

+6779
-95
lines changed

.gitignore

+14
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
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
Large diffs are not rendered by default.

FasterRCNN.sln

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.27703.2026
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{888888A0-9F3D-457C-B088-3A5042F75D52}") = "FasterRCNN", "FasterRCNN.pyproj", "{331BAC87-6D9D-4023-954A-0A35943A3358}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{331BAC87-6D9D-4023-954A-0A35943A3358}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{331BAC87-6D9D-4023-954A-0A35943A3358}.Release|Any CPU.ActiveCfg = Release|Any CPU
16+
EndGlobalSection
17+
GlobalSection(SolutionProperties) = preSolution
18+
HideSolutionNode = FALSE
19+
EndGlobalSection
20+
GlobalSection(ExtensibilityGlobals) = postSolution
21+
SolutionGuid = {4969271A-7E02-44A8-B9CD-00F0B4151CC0}
22+
EndGlobalSection
23+
EndGlobal

README.md

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

152-
Compile the cuda dependencies using following simple commands:
153-
152+
if bulid on windows, please click [README.md](./windows/README.md).
153+
154+
else compile the cuda dependencies using following simple commands:
155+
154156
```
155157
cd lib
156158
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='res101', type=str)
58+
default='vgg16', 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="/srv/share/jyang375/models")
64+
default="F:/Pascal/faster_rcnn_pytorch")
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
Binary file not shown.

images/img2.jpg

-111 KB
Binary file not shown.

images/img2_det.jpg

-111 KB
Binary file not shown.

images/img2_det_res101.jpg

-111 KB
Binary file not shown.

images/img3.jpg

-100 KB
Binary file not shown.

images/img3_det.jpg

-105 KB
Binary file not shown.

images/img3_det_res101.jpg

-105 KB
Binary file not shown.

images/img4_det.jpg

103 Bytes
Loading

images/img4_det_res101.jpg

-89.3 KB
Binary file not shown.

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=/usr/local/cuda/
3+
CUDA_PATH="A:/NVIDIA/GPU Computing Toolkit/CUDA/v9.1"
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.cu.o nms_cuda_kernel.cu \
19-
-D GOOGLE_CUDA=1 -x cu -Xcompiler -fPIC $CUDA_ARCH
18+
#nvcc -c -o nms_cuda_kernel.lib 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.cu.o roi_pooling_kernel.cu \
29-
-D GOOGLE_CUDA=1 -x cu -Xcompiler -fPIC $CUDA_ARCH
28+
#nvcc -c -o roi_pooling.lib 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.cu.o roi_align_kernel.cu \
38-
-D GOOGLE_CUDA=1 -x cu -Xcompiler -fPIC $CUDA_ARCH
37+
#nvcc -c -o roi_align_kernel.lib 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.cu.o roi_crop_cuda_kernel.cu \
47-
-D GOOGLE_CUDA=1 -x cu -Xcompiler -fPIC $CUDA_ARCH
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
4848
cd ../
4949
python build.py

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

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

1215
_import_symbols(locals())

lib/model/nms/build.py

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

67
#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']
711

812
sources = []
913
headers = []
1014
defines = []
15+
include_dirs = []
1116
with_cuda = False
1217

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

20-
this_file = os.path.dirname(os.path.realpath(__file__))
21-
print(this_file)
22-
extra_objects = ['src/nms_cuda_kernel.cu.o']
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')]
2334
extra_objects = [os.path.join(this_file, fname) for fname in extra_objects]
2435
print(extra_objects)
2536

@@ -30,7 +41,8 @@
3041
define_macros=defines,
3142
relative_to=__file__,
3243
with_cuda=with_cuda,
33-
extra_objects=extra_objects
44+
extra_objects=extra_objects,
45+
include_dirs=include_dirs
3446
)
3547

3648
if __name__ == '__main__':

lib/model/nms/src/nms_cuda.c

-19
This file was deleted.

lib/model/nms/src/nms_cuda.h

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

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

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

1215
_import_symbols(locals())

lib/model/roi_align/build.py

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

6-
sources = ['src/roi_align.c']
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']
713
headers = ['src/roi_align.h']
8-
extra_objects = []
9-
#sources = []
10-
#headers = []
14+
include_dirs = []
1115
defines = []
1216
with_cuda = False
1317

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

1721
if torch.cuda.is_available():
1822
print('Including CUDA code.')
19-
sources += ['src/roi_align_cuda.c']
23+
sources += ['src/roi_align_cuda.cpp']
2024
headers += ['src/roi_align_cuda.h']
2125
defines += [('WITH_CUDA', None)]
2226
with_cuda = True
23-
24-
extra_objects = ['src/roi_align_kernel.cu.o']
25-
extra_objects = [os.path.join(this_file, fname) for fname in extra_objects]
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)
2635

2736
ffi = create_extension(
2837
'_ext.roi_align',
@@ -31,7 +40,8 @@
3140
define_macros=defines,
3241
relative_to=__file__,
3342
with_cuda=with_cuda,
34-
extra_objects=extra_objects
43+
extra_objects=extra_objects,
44+
include_dirs=include_dirs
3545
)
3646

3747
if __name__ == '__main__':

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

+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-
int roi_align_forward(int aligned_height, int aligned_width, float spatial_scale,
16+
extern"C" __declspec(dllexport) 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 @@ int roi_align_forward(int aligned_height, int aligned_width, float spatial_scale
4444
return 1;
4545
}
4646

47-
int roi_align_backward(int aligned_height, int aligned_width, float spatial_scale,
47+
extern"C" __declspec(dllexport) 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.c renamed to lib/model/roi_align/src/roi_align_cuda.cpp

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

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

7-
int roi_align_forward_cuda(int aligned_height, int aligned_width, float spatial_scale,
8+
extern"C" __declspec(dllexport) int roi_align_forward_cuda(int aligned_height, int aligned_width, float spatial_scale,
89
THCudaTensor * features, THCudaTensor * rois, THCudaTensor * output)
910
{
1011
// Grab the input tensor
@@ -39,7 +40,7 @@ int roi_align_forward_cuda(int aligned_height, int aligned_width, float spatial_
3940
return 1;
4041
}
4142

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

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

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

1215
_import_symbols(locals())

lib/model/roi_crop/build.py

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

67
#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']
711

8-
sources = ['src/roi_crop.c']
12+
sources = ['src/roi_crop.cpp']
913
headers = ['src/roi_crop.h']
14+
include_dirs = []
1015
defines = []
1116
with_cuda = False
1217

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

20-
this_file = os.path.dirname(os.path.realpath(__file__))
21-
print(this_file)
22-
extra_objects = ['src/roi_crop_cuda_kernel.cu.o']
30+
extra_objects = ['src/roi_crop_cuda_kernel.lib']
2331
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)
2436

2537
ffi = create_extension(
2638
'_ext.roi_crop',
@@ -29,7 +41,8 @@
2941
define_macros=defines,
3042
relative_to=__file__,
3143
with_cuda=with_cuda,
32-
extra_objects=extra_objects
44+
extra_objects=extra_objects,
45+
include_dirs=include_dirs
3346
)
3447

3548
if __name__ == '__main__':

0 commit comments

Comments
 (0)