Skip to content

Commit

Permalink
Revert "Porting this code to Windows"
Browse files Browse the repository at this point in the history
  • Loading branch information
jwyang authored Jun 15, 2018
1 parent 009d7a9 commit 333ac7a
Show file tree
Hide file tree
Showing 49 changed files with 95 additions and 6,779 deletions.
14 changes: 0 additions & 14 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
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: 0 additions & 6,074 deletions FasterRCNN.pyproj

This file was deleted.

23 changes: 0 additions & 23 deletions FasterRCNN.sln

This file was deleted.

6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,8 @@ Install all the python dependencies using pip:
pip install -r requirements.txt
```

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

else compile the cuda dependencies using following simple commands:

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='vgg16', type=str)
default='res101', 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="F:/Pascal/faster_rcnn_pytorch")
default="/srv/share/jyang375/models")
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 added images/img1_det_res101.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 added images/img2.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 added images/img2_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 added images/img2_det_res101.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 added images/img3.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 added images/img3_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 added images/img3_det_res101.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 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 added images/img4_det_res101.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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="A:/NVIDIA/GPU Computing Toolkit/CUDA/v9.1"
CUDA_PATH=/usr/local/cuda/

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.lib nms_cuda_kernel.cu \
# -D GOOGLE_CUDA=1 -x cu -Xcompiler -fPIC $CUDA_ARCH
nvcc -c -o nms_cuda_kernel.cu.o 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.lib roi_pooling_kernel.cu \
# -D GOOGLE_CUDA=1 -x cu -Xcompiler -fPIC $CUDA_ARCH
nvcc -c -o roi_pooling.cu.o 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.lib roi_align_kernel.cu \
# -D GOOGLE_CUDA=1 -x cu -Xcompiler -fPIC $CUDA_ARCH
nvcc -c -o roi_align_kernel.cu.o 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.lib roi_crop_cuda_kernel.cu \
# -D GOOGLE_CUDA=1 -x cu -Xcompiler -fPIC $CUDA_ARCH
nvcc -c -o roi_crop_cuda_kernel.cu.o roi_crop_cuda_kernel.cu \
-D GOOGLE_CUDA=1 -x cu -Xcompiler -fPIC $CUDA_ARCH
cd ../
python build.py
5 changes: 1 addition & 4 deletions lib/model/nms/_ext/nms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
def _import_symbols(locals):
for symbol in dir(_lib):
fn = getattr(_lib, symbol)
if callable(fn):
locals[symbol] = _wrap_function(fn, _ffi)
else:
locals[symbol] = fn
locals[symbol] = _wrap_function(fn, _ffi)
__all__.append(symbol)

_import_symbols(locals())
22 changes: 5 additions & 17 deletions lib/model/nms/build.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,25 @@
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.cpp']
sources += ['src/nms_cuda.c']
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


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

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

if __name__ == '__main__':
Expand Down
19 changes: 19 additions & 0 deletions lib/model/nms/src/nms_cuda.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <THC/THC.h>
#include <stdio.h>
#include "nms_cuda_kernel.h"

// this symbol will be resolved automatically from PyTorch libs
extern THCState *state;

int nms_cuda(THCudaIntTensor *keep_out, THCudaTensor *boxes_host,
THCudaIntTensor *num_out, float nms_overlap_thresh) {

nms_cuda_compute(THCudaIntTensor_data(state, keep_out),
THCudaIntTensor_data(state, num_out),
THCudaTensor_data(state, boxes_host),
boxes_host->size[0],
boxes_host->size[1],
nms_overlap_thresh);

return 1;
}
1 change: 1 addition & 0 deletions lib/model/nms/src/nms_cuda.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// 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: 1 addition & 4 deletions lib/model/roi_align/_ext/roi_align/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
def _import_symbols(locals):
for symbol in dir(_lib):
fn = getattr(_lib, symbol)
if callable(fn):
locals[symbol] = _wrap_function(fn, _ffi)
else:
locals[symbol] = fn
locals[symbol] = _wrap_function(fn, _ffi)
__all__.append(symbol)

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


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']
sources = ['src/roi_align.c']
headers = ['src/roi_align.h']
include_dirs = []
extra_objects = []
#sources = []
#headers = []
defines = []
with_cuda = False

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

if torch.cuda.is_available():
print('Including CUDA code.')
sources += ['src/roi_align_cuda.cpp']
sources += ['src/roi_align_cuda.c']
headers += ['src/roi_align_cuda.h']
defines += [('WITH_CUDA', None)]
with_cuda = True
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)

extra_objects = ['src/roi_align_kernel.cu.o']
extra_objects = [os.path.join(this_file, fname) for fname in extra_objects]

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

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);

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

extern"C" __declspec(dllexport) int roi_align_backward(int aligned_height, int aligned_width, float spatial_scale,
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,11 +1,10 @@
#include <THC/THC.h>
#include <math.h>
#include <ATen/ATen.h>
#include "roi_align_kernel.h"

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

extern"C" __declspec(dllexport) int roi_align_forward_cuda(int aligned_height, int aligned_width, float spatial_scale,
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 @@ -40,7 +39,7 @@ extern"C" __declspec(dllexport) int roi_align_forward_cuda(int aligned_height, i
return 1;
}

extern"C" __declspec(dllexport) int roi_align_backward_cuda(int aligned_height, int aligned_width, float spatial_scale,
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: 1 addition & 4 deletions lib/model/roi_crop/_ext/roi_crop/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
def _import_symbols(locals):
for symbol in dir(_lib):
fn = getattr(_lib, symbol)
if callable(fn):
locals[symbol] = _wrap_function(fn, _ffi)
else:
locals[symbol] = fn
locals[symbol] = _wrap_function(fn, _ffi)
__all__.append(symbol)

_import_symbols(locals())
25 changes: 6 additions & 19 deletions lib/model/roi_crop/build.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,26 @@
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.cpp']
sources = ['src/roi_crop.c']
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.cpp']
sources += ['src/roi_crop_cuda.c']
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

extra_objects = ['src/roi_crop_cuda_kernel.lib']
this_file = os.path.dirname(os.path.realpath(__file__))
print(this_file)
extra_objects = ['src/roi_crop_cuda_kernel.cu.o']
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 @@ -41,8 +29,7 @@
define_macros=defines,
relative_to=__file__,
with_cuda=with_cuda,
extra_objects=extra_objects,
include_dirs=include_dirs
extra_objects=extra_objects
)

if __name__ == '__main__':
Expand Down
Loading

0 comments on commit 333ac7a

Please sign in to comment.