Giter Site home page Giter Site logo

hikapok / psroialign Goto Github PK

View Code? Open in Web Editor NEW
48.0 5.0 18.0 39 KB

(Oriented) PsRoIAlign Operation In Tensorflow C++ API

License: MIT License

C 0.57% CMake 2.31% Shell 0.05% C++ 63.43% Cuda 26.31% Python 7.33%
tensorflow roipooling roialign psroipooling objectdetection cpp faster-rcnn

psroialign's Introduction

PsRoIAlign Operation In Tensorflow C++ API

PsRoIAlign involves interpolation techniques for PsRoiPooling (position-sensitive RoI pooling operation), the interpolation idea is proposed in RoIAlign to avoid any quantization of the RoI boundaries. The first adoption of PsRoIAlign might be in this paper Light-Head R-CNN: In Defense of Two-Stage Object Detector.

You can find more details about the RoiPooling technique in Fast R-CNN and Spatial Pyramid Pooling in Deep Convolutional Networks for Visual Recognition.

This repository contains code of the implement of PsRoIAlign operation in Tensorflow C++ API. You can use this operation in many popular two-stage object detector. Both research work using PsRoIAlign and contribution to this repository are welcomed.

For using this op in your own machine, just following these steps:

  • copy the header file "cuda_config.h" from "your_python_path/site-packages/external/local_config_cuda/cuda/cuda/cuda_config.h" to "your_python_path/site-packages/tensorflow/include/tensorflow/stream_executor/cuda/cuda_config.h".

  • run the following script:

mkdir build
cd build && cmake ..
make
  • run "test_op.py" and check the numeric errors to test your install

  • follow the below codes snippet to integrate this Op into your own code:

     op_module = tf.load_op_library(so_lib_path)
     ps_roi_align = op_module.ps_roi_align
    
     @ops.RegisterGradient("PsRoiAlign")
     def _ps_roi_align_grad(op, grad, _):
       '''The gradients for `PsRoiAlign`.
       '''
       inputs_features = op.inputs[0]
       rois = op.inputs[1]
       pooled_features_grad = op.outputs[0]
       pooled_index = op.outputs[1]
       grid_dim_width = op.get_attr('grid_dim_width')
       grid_dim_height = op.get_attr('grid_dim_height')
     
       return [op_module.ps_roi_align_grad(inputs_features, rois, grad, pooled_index, grid_dim_width, grid_dim_height, pool_method), None]
    
     pool_method = 'max' # or 'mean'
     pool_result = ps_roi_align(features, rois, 2, 2, pool_method)

The code is tested under TensorFlow 1.6 with CUDA 8.0 using Ubuntu 16.04. This PsRoIAlign Op had been used to train Xception based Light-Head RCNN successfully with performance at ~75%mAP on PASCAL VOC 2007 Test dataset, you can see codes here.

Update:

  • Added support for mean pooling (default is max pooling)
  • PsRoIAlign now support oriented RoI inputs (for both max and mean pooling).

Future Work:

  • Check if there is need to ensure the convex of polygon
  • Improve performance

If you encountered some linkage problem when generating or loading *.so, you are highly recommended to read this section in the official tourial to make sure you were using the same C++ ABI version.

The MIT License

psroialign's People

Contributors

hikapok avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

psroialign's Issues

Linking CXX shared library libps_roi_align.so Error running link command: No such file or directory

Hello!

I want to import your Light-Head RCNN code. Then i have tried to build PSROIAlign but some trouble has occured.

when trying to make:

[ 10%] Building NVCC (Device) object CMakeFiles/cuda_compile.dir/cuda_compile_generated_rotated_ps_roi_align_grad_op.cu.o
.....
[100%] Linking CXX shared library libps_roi_align.so
Error running link command: No such file or directory
CMakeFiles/ps_roi_align.dir/build.make:236: recipe for target 'libps_roi_align.so' failed
make[2]: *** [libps_roi_align.so] Error 2
make[2]: *** Deleting file 'libps_roi_align.so'
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/ps_roi_align.dir/all' failed
make[1]: *** [CMakeFiles/ps_roi_align.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

I tried using python2 and tensorflow 1.8. How can I solve this problem?

undefined symbol problem

I wrote a custom op, and use gcc cmd to build it, it worked well. Then I try to rewirte the build script with cmake, and use your CMakeLists.txt as example, but when calling the op, it gives the undefined symbol error. It seems the op is skipped by the cmake. The following is gcc script and cmakelists. could you give some advice?
gcc script

TF_CFLAGS=( $(python -c 'import tensorflow as tf; print(" ".join(tf.sysconfig.get_compile_flags()))') ) 
TF_LFLAGS=( $(python -c 'import tensorflow as tf; print(" ".join(tf.sysconfig.get_link_flags()))') ) 

nvcc -std=c++11 -c -o resize_trilinear.cu.o resize_trilinear.cu.cc \
    ${TF_CFLAGS[@]} -I/usr/local \
    -D GOOGLE_CUDA=1 \
    -x cu -Xcompiler -fPIC -DNDEBUG --expt-relaxed-constexpr

g++ -std=c++11 -shared -o libresize_trilinear.so resize_trilinear.cc resize_trilinear.cu.o \
    ${TF_CFLAGS[@]} -I/usr/local/cuda/include \
    ${TF_LFLAGS[@]} -lcudart \
    -D GOOGLE_CUDA=1 \
    -fPIC -O2

CMakeLists.txt

cmake_minimum_required(VERSION 3.14)

project(resize_trilinear)

set(CMAKE_CXX_STANDARD 11)

#enable_language(CUDA)
find_package(CUDA REQUIRED)

set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} \
                    -gencode arch=compute_61,code=sm_61 \
                    -D GOOGLE_CUDA=1 -x cu \
                    -Xcompiler -fPIC -DNDEBUG \
                    --expt-relaxed-constexpr")

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \
                    -std=c++11 \
                    -DGOOGLE_CUDA=1 \
                    -fPIC -O2")

set(TF_INC /home/zoud/program/anaconda3/envs/tf2/lib/python3.6/site-packages/tensorflow_core/include)
set(TF_LIB /home/zoud/program/anaconda3/envs/tf2/lib/python3.6/site-packages/tensorflow_core)

cuda_compile(RESIZE_TRILINEAR_CU_O resize_trilinear.cu.cc MODULE OPTIONS -I$TF_INC -I/usr/local)

include_directories(${TF_INC} /usr/local/cuda/include)

link_directories(${TF_LIB} /usr/local/cuda/lib64)

#add_link_options(-Wl,--no-as-needed)
#add_link_options(-Wl,--allow-multiple-definition)

add_library(resize_trilinear SHARED
        ${RESIZE_TRILINEAR_CU_O}
        resize_trilinear.h
        resize_trilinear.cc)

target_link_libraries(resize_trilinear
        libtensorflow_framework.so.2
        libcudart.so)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.