hermannhesse / faster_rcnn_cplusplus Goto Github PK
View Code? Open in Web Editor NEWC++ inference interface against the object detection neural networks trained with Faster R-CNN.
License: Other
C++ inference interface against the object detection neural networks trained with Faster R-CNN.
License: Other
When compiled with g++ 5.4.0 under Ubuntu 16.04, the preprocess function will segfault when copying the resized image into the buffer if you increase the MAX_INPUT_SIDE and MIN_INPUT_SIDE constants (to 2056x1504, in my case).
Reason seems to be that initializing variable length arrays, while legal in C, is UB in C++, causing a segfault in the implementation I'm using.
Fix is to replace the line
float data_buf[height_resized*width_resized*3];
with
float *data_buf = new float[height_resized*width_resized*3];
and add
delete[] data_buf;
at the end of the function.
I would strongly advise to use std::vector instead of C arrays for your buffers. The performance overhead is usually not measurable (they are just thin wrappers around C arrays; most importantly, the standard guarantees that they are contiguous in memory and use the same layout a C array would, so doing pointer arithmetic on them is fine), but they will not leak memory when an exception is thrown between creation and destruction, and don't cause heap corruption when used carelessly.
I got the below error with -std=c++11
usr/include/c++/4.8/bits/stl_algo.h: In instantiation of ‘_RandomAccessIterator std::__unguarded_partition(_RandomAccessIterator, _RandomAccessIterator, const _Tp&) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<Info*, std::vector >; _Tp = Info]’:
/usr/include/c++/4.8/bits/stl_algo.h:2283:70: required from ‘_RandomAccessIterator std::__unguarded_partition_pivot(_RandomAccessIterator, _RandomAccessIterator) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<Info*, std::vector >]’
/usr/include/c++/4.8/bits/stl_algo.h:2315:54: required from ‘void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<Info*, std::vector >; _Size = long int]’
/usr/include/c++/4.8/bits/stl_algo.h:5461:36: required from ‘void std::sort(_RAIter, _RAIter) [with _RAIter = __gnu_cxx::__normal_iterator<Info*, std::vector >]’
/home/faster_rcnn_cplusplus/faster_rcnn.cpp:262:35: required from here
/usr/include/c++/4.8/bits/stl_algo.h:2245:19: error: passing ‘const Info’ as ‘this’ argument of ‘bool Info::operator<(const Info&)’ discards qualifiers [-fpermissive]
while (__pivot < *__last)
^
make[2]: *** [CMakeFiles/faster_rcnn_cplusplus.dir/faster_rcnn.cpp.o] Error 1
make[1]: *** [CMakeFiles/faster_rcnn_cplusplus.dir/all] Error 2
make: *** [all] Error 2
when i tried with -std=c++0x in CMakeLists.txt, i got below errors.
/usr/include/c++/4.8/cmath(337): error: expected a ";"
/usr/include/c++/4.8/cmath(356): error: inline specifier allowed on function declarations only
/usr/include/c++/4.8/cmath(356): error: variable "std::constexpr" has already been defined
/usr/include/c++/4.8/cmath(356): error: expected a ";"
/usr/include/c++/4.8/cmath(375): error: inline specifier allowed on function declarations only
/usr/include/c++/4.8/cmath(375): error: variable "std::constexpr" has already been defined
/usr/include/c++/4.8/cmath(375): error: expected a ";"
/usr/include/c++/4.8/cmath(406): error: inline specifier allowed on function declarations only
/usr/include/c++/4.8/cmath(406): error: variable "std::constexpr" has already been defined
/usr/include/c++/4.8/cmath(406): error: expected a ";"
/usr/include/c++/4.8/cmath(443): error: inline specifier allowed on function declarations only
/usr/include/c++/4.8/cmath(443): error: variable "std::constexpr" has already been defined
/usr/include/c++/4.8/cmath(443): error: expected a ";"
Error limit reached.
100 errors detected in the compilation of "/tmp/tmpxft_00010fe0_00000000-7_nms_kernel.cpp1.ii".
Compilation terminated.
CMake Error at faster_rcnn_cplusplus_generated_nms_kernel.cu.o.cmake:282 (message):
Error generating file
/home/faster_rcnn_cplusplus/build/CMakeFiles/faster_rcnn_cplusplus.dir/py-faster-rcnn/lib/nms/./faster_rcnn_cplusplus_generated_nms_kernel.cu.o
make[2]: *** [CMakeFiles/faster_rcnn_cplusplus.dir/py-faster-rcnn/lib/nms/faster_rcnn_cplusplus_generated_nms_kernel.cu.o] Error 1
make[1]: *** [CMakeFiles/faster_rcnn_cplusplus.dir/all] Error 2
make: *** [all] Error 2
Any help, suggestion or followup would be highly appreciated
I1130 20:03:11.124338 16824 net.cpp:411] rpn_cls_prob_reshape -> rpn_cls_prob_reshape
I1130 20:03:11.124387 16824 net.cpp:150] Setting up rpn_cls_prob_reshape
I1130 20:03:11.124403 16824 net.cpp:157] Top shape: 1 18 15 15 (4050)
I1130 20:03:11.124413 16824 net.cpp:165] Memory required for data: 21835056
I1130 20:03:11.124420 16824 layer_factory.hpp:77] Creating layer proposal
Segmentation fault
it happend when I run the demo....
the word interface has been written twice, let me know if I can contribute to fix it :)
hello,
I was trying to compile your c++ version faster-rcnn
I have complied the original py-faster-rcnn and run the demo successfully. So I skip the caffe and pycaffe build step and complie the faster_rcnn_cplusplus directly. However I met the below error..
[ 25%] Building CXX object CMakeFiles/faster_rcnn_cplusplus.dir/main.cpp.o
[ 50%] Building CXX object CMakeFiles/faster_rcnn_cplusplus.dir/faster_rcnn.cpp.o
[ 75%] Linking CXX executable faster_rcnn_cplusplus
/usr/bin/ld: cannot find -lcaffe
/usr/bin/ld: cannot find -lopencv_dep_cudart
collect2: error: ld returned 1 exit status
CMakeFiles/faster_rcnn_cplusplus.dir/build.make:348: recipe for target 'faster_rcnn_cplusplus' failed
make[2]: *** [faster_rcnn_cplusplus] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/faster_rcnn_cplusplus.dir/all' failed
make[1]: *** [CMakeFiles/faster_rcnn_cplusplus.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
Cannot figure out where is the problem.. should I compile caffe and pycaffe again?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.