Skip to content

Commit

Permalink
Merge pull request #189 from kingstarcraft/windows
Browse files Browse the repository at this point in the history
Porting this code to Windows
  • Loading branch information
jwyang authored Jun 15, 2018
2 parents 0e6f131 + 4519038 commit 009d7a9
Show file tree
Hide file tree
Showing 49 changed files with 6,779 additions and 95 deletions.
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
data/*
*.pyc
*~
/images - Copy
*.pyd
*.ipch
*.tlog
*.deps
*.cache
*.obj
*.log
*.pdb
/vgg16_caffe.pth
/windows/.vs/faster_rcnn/v15
*.dll
*.lib
/.vs/FasterRCNN/v15
6,074 changes: 6,074 additions & 0 deletions FasterRCNN.pyproj

Large diffs are not rendered by default.

23 changes: 23 additions & 0 deletions FasterRCNN.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27703.2026
MinimumVisualStudioVersion = 10.0.40219.1
Project("{888888A0-9F3D-457C-B088-3A5042F75D52}") = "FasterRCNN", "FasterRCNN.pyproj", "{331BAC87-6D9D-4023-954A-0A35943A3358}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{331BAC87-6D9D-4023-954A-0A35943A3358}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{331BAC87-6D9D-4023-954A-0A35943A3358}.Release|Any CPU.ActiveCfg = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {4969271A-7E02-44A8-B9CD-00F0B4151CC0}
EndGlobalSection
EndGlobal
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,10 @@ Install all the python dependencies using pip:
pip install -r requirements.txt
```

Compile the cuda dependencies using following simple commands:

if bulid on windows, please click [README.md](./windows/README.md).

else compile the cuda dependencies using following simple commands:

```
cd lib
sh make.sh
Expand Down
4 changes: 2 additions & 2 deletions demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ def parse_args():
default='cfgs/vgg16.yml', type=str)
parser.add_argument('--net', dest='net',
help='vgg16, res50, res101, res152',
default='res101', type=str)
default='vgg16', type=str)
parser.add_argument('--set', dest='set_cfgs',
help='set config keys', default=None,
nargs=argparse.REMAINDER)
parser.add_argument('--load_dir', dest='load_dir',
help='directory to load models',
default="/srv/share/jyang375/models")
default="F:/Pascal/faster_rcnn_pytorch")
parser.add_argument('--image_dir', dest='image_dir',
help='directory to load images for demo',
default="images")
Expand Down
Binary file modified images/img1_det.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed images/img1_det_res101.jpg
Binary file not shown.
Binary file removed images/img2.jpg
Binary file not shown.
Binary file removed images/img2_det.jpg
Binary file not shown.
Binary file removed images/img2_det_res101.jpg
Binary file not shown.
Binary file removed images/img3.jpg
Binary file not shown.
Binary file removed images/img3_det.jpg
Binary file not shown.
Binary file removed images/img3_det_res101.jpg
Binary file not shown.
Binary file modified images/img4_det.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed images/img4_det_res101.jpg
Binary file not shown.
18 changes: 9 additions & 9 deletions lib/make.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

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

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

cd ../
python build.py
Expand All @@ -25,25 +25,25 @@ python build.py
cd ../../
cd model/roi_pooling/src
echo "Compiling roi pooling kernels by nvcc..."
nvcc -c -o roi_pooling.cu.o roi_pooling_kernel.cu \
-D GOOGLE_CUDA=1 -x cu -Xcompiler -fPIC $CUDA_ARCH
#nvcc -c -o roi_pooling.lib roi_pooling_kernel.cu \
# -D GOOGLE_CUDA=1 -x cu -Xcompiler -fPIC $CUDA_ARCH
cd ../
python build.py

# compile roi_align
cd ../../
cd model/roi_align/src
echo "Compiling roi align kernels by nvcc..."
nvcc -c -o roi_align_kernel.cu.o roi_align_kernel.cu \
-D GOOGLE_CUDA=1 -x cu -Xcompiler -fPIC $CUDA_ARCH
#nvcc -c -o roi_align_kernel.lib roi_align_kernel.cu \
# -D GOOGLE_CUDA=1 -x cu -Xcompiler -fPIC $CUDA_ARCH
cd ../
python build.py

# compile roi_crop
cd ../../
cd model/roi_crop/src
echo "Compiling roi crop kernels by nvcc..."
nvcc -c -o roi_crop_cuda_kernel.cu.o roi_crop_cuda_kernel.cu \
-D GOOGLE_CUDA=1 -x cu -Xcompiler -fPIC $CUDA_ARCH
#nvcc -c -o roi_crop_cuda_kernel.lib roi_crop_cuda_kernel.cu \
# -D GOOGLE_CUDA=1 -x cu -Xcompiler -fPIC $CUDA_ARCH
cd ../
python build.py
5 changes: 4 additions & 1 deletion lib/model/nms/_ext/nms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
def _import_symbols(locals):
for symbol in dir(_lib):
fn = getattr(_lib, symbol)
locals[symbol] = _wrap_function(fn, _ffi)
if callable(fn):
locals[symbol] = _wrap_function(fn, _ffi)
else:
locals[symbol] = fn
__all__.append(symbol)

_import_symbols(locals())
22 changes: 17 additions & 5 deletions lib/model/nms/build.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,36 @@
from __future__ import print_function
import os
import sys
import torch
from torch.utils.ffi import create_extension

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

sources = []
headers = []
defines = []
include_dirs = []
with_cuda = False

this_file = os.path.dirname(os.path.realpath(__file__))
print(this_file)

if torch.cuda.is_available():
print('Including CUDA code.')
sources += ['src/nms_cuda.c']
sources += ['src/nms_cuda.cpp']
headers += ['src/nms_cuda.h']
include_dirs += [os.path.join(cuda_root,"include"), os.path.join(torch_root,'include')]
defines += [('WITH_CUDA', None)]
with_cuda = True

this_file = os.path.dirname(os.path.realpath(__file__))
print(this_file)
extra_objects = ['src/nms_cuda_kernel.cu.o']

extra_objects = ['src/nms_cuda_kernel.lib']
extra_objects += [os.path.join(torch_root,'ATen.lib'),
os.path.join(cuda_root,'lib/x64/cudart.lib'),
os.path.join(torch_root,'_C.lib')]
extra_objects = [os.path.join(this_file, fname) for fname in extra_objects]
print(extra_objects)

Expand All @@ -30,7 +41,8 @@
define_macros=defines,
relative_to=__file__,
with_cuda=with_cuda,
extra_objects=extra_objects
extra_objects=extra_objects,
include_dirs=include_dirs
)

if __name__ == '__main__':
Expand Down
19 changes: 0 additions & 19 deletions lib/model/nms/src/nms_cuda.c

This file was deleted.

1 change: 0 additions & 1 deletion lib/model/nms/src/nms_cuda.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// int nms_cuda(THCudaTensor *keep_out, THCudaTensor *num_out,
// THCudaTensor *boxes_host, THCudaTensor *nms_overlap_thresh);

int nms_cuda(THCudaIntTensor *keep_out, THCudaTensor *boxes_host,
THCudaIntTensor *num_out, float nms_overlap_thresh);
5 changes: 4 additions & 1 deletion lib/model/roi_align/_ext/roi_align/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
def _import_symbols(locals):
for symbol in dir(_lib):
fn = getattr(_lib, symbol)
locals[symbol] = _wrap_function(fn, _ffi)
if callable(fn):
locals[symbol] = _wrap_function(fn, _ffi)
else:
locals[symbol] = fn
__all__.append(symbol)

_import_symbols(locals())
28 changes: 19 additions & 9 deletions lib/model/roi_align/build.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
from __future__ import print_function
import os
import sys
import torch
from torch.utils.ffi import create_extension

sources = ['src/roi_align.c']

torch_root = os.path.join(os.path.dirname(sys.executable),
'Lib/site-packages/torch/lib')
cuda_root = os.environ['CUDA_PATH']

sources = ['src/roi_align.cpp']
headers = ['src/roi_align.h']
extra_objects = []
#sources = []
#headers = []
include_dirs = []
defines = []
with_cuda = False

Expand All @@ -16,13 +20,18 @@

if torch.cuda.is_available():
print('Including CUDA code.')
sources += ['src/roi_align_cuda.c']
sources += ['src/roi_align_cuda.cpp']
headers += ['src/roi_align_cuda.h']
defines += [('WITH_CUDA', None)]
with_cuda = True

extra_objects = ['src/roi_align_kernel.cu.o']
extra_objects = [os.path.join(this_file, fname) for fname in extra_objects]
include_dirs += [os.path.join(cuda_root,"include"),
os.path.join(torch_root,'include')]
extra_objects = ['src/roi_align_kernel.lib']
extra_objects = [os.path.join(this_file, fname) for fname in extra_objects]
extra_objects += [os.path.join(torch_root,'ATen.lib'),
os.path.join(cuda_root,'lib/x64/cudart.lib'),
os.path.join(torch_root,'_C.lib')]
print(extra_objects)

ffi = create_extension(
'_ext.roi_align',
Expand All @@ -31,7 +40,8 @@
define_macros=defines,
relative_to=__file__,
with_cuda=with_cuda,
extra_objects=extra_objects
extra_objects=extra_objects,
include_dirs=include_dirs
)

if __name__ == '__main__':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ void ROIAlignBackwardCpu(const float* top_diff, const float spatial_scale, const
const int aligned_height, const int aligned_width, const float * bottom_rois,
float* top_data);

int roi_align_forward(int aligned_height, int aligned_width, float spatial_scale,
extern"C" __declspec(dllexport) int roi_align_forward(int aligned_height, int aligned_width, float spatial_scale,
THFloatTensor * features, THFloatTensor * rois, THFloatTensor * output)
{
//Grab the input tensor
Expand Down Expand Up @@ -44,7 +44,7 @@ int roi_align_forward(int aligned_height, int aligned_width, float spatial_scale
return 1;
}

int roi_align_backward(int aligned_height, int aligned_width, float spatial_scale,
extern"C" __declspec(dllexport) int roi_align_backward(int aligned_height, int aligned_width, float spatial_scale,
THFloatTensor * top_grad, THFloatTensor * rois, THFloatTensor * bottom_grad)
{
//Grab the input tensor
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#include <THC/THC.h>
#include <math.h>
#include <ATen/ATen.h>
#include "roi_align_kernel.h"

extern THCState *state;
THCState *state = at::globalContext().thc_state;

int roi_align_forward_cuda(int aligned_height, int aligned_width, float spatial_scale,
extern"C" __declspec(dllexport) int roi_align_forward_cuda(int aligned_height, int aligned_width, float spatial_scale,
THCudaTensor * features, THCudaTensor * rois, THCudaTensor * output)
{
// Grab the input tensor
Expand Down Expand Up @@ -39,7 +40,7 @@ int roi_align_forward_cuda(int aligned_height, int aligned_width, float spatial_
return 1;
}

int roi_align_backward_cuda(int aligned_height, int aligned_width, float spatial_scale,
extern"C" __declspec(dllexport) int roi_align_backward_cuda(int aligned_height, int aligned_width, float spatial_scale,
THCudaTensor * top_grad, THCudaTensor * rois, THCudaTensor * bottom_grad)
{
// Grab the input tensor
Expand Down
5 changes: 4 additions & 1 deletion lib/model/roi_crop/_ext/roi_crop/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
def _import_symbols(locals):
for symbol in dir(_lib):
fn = getattr(_lib, symbol)
locals[symbol] = _wrap_function(fn, _ffi)
if callable(fn):
locals[symbol] = _wrap_function(fn, _ffi)
else:
locals[symbol] = fn
__all__.append(symbol)

_import_symbols(locals())
25 changes: 19 additions & 6 deletions lib/model/roi_crop/build.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,38 @@
from __future__ import print_function
import os
import sys
import torch
from torch.utils.ffi import create_extension

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

sources = ['src/roi_crop.c']
sources = ['src/roi_crop.cpp']
headers = ['src/roi_crop.h']
include_dirs = []
defines = []
with_cuda = False

this_file = os.path.dirname(os.path.realpath(__file__))
print(this_file)

if torch.cuda.is_available():
print('Including CUDA code.')
sources += ['src/roi_crop_cuda.c']
sources += ['src/roi_crop_cuda.cpp']
headers += ['src/roi_crop_cuda.h']
include_dirs += [os.path.join(cuda_root,"include"),
os.path.join(torch_root,'include')]
defines += [('WITH_CUDA', None)]
with_cuda = True

this_file = os.path.dirname(os.path.realpath(__file__))
print(this_file)
extra_objects = ['src/roi_crop_cuda_kernel.cu.o']
extra_objects = ['src/roi_crop_cuda_kernel.lib']
extra_objects = [os.path.join(this_file, fname) for fname in extra_objects]
extra_objects += [os.path.join(torch_root,'ATen.lib'),
os.path.join(cuda_root,'lib/x64/cudart.lib'),
os.path.join(torch_root,'_C.lib')]
print(extra_objects)

ffi = create_extension(
'_ext.roi_crop',
Expand All @@ -29,7 +41,8 @@
define_macros=defines,
relative_to=__file__,
with_cuda=with_cuda,
extra_objects=extra_objects
extra_objects=extra_objects,
include_dirs=include_dirs
)

if __name__ == '__main__':
Expand Down
Loading

0 comments on commit 009d7a9

Please sign in to comment.