forked from BVLC/caffe
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request BVLC#12 from jessebrizzi/DEV-26376
DEV-26376: Recode python layer to C++ in detection net
- Loading branch information
Showing
19 changed files
with
1,317 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// ------------------------------------------------------------------ | ||
// Xuanyi . Refer to Dong Jian | ||
// 2016/03/31 | ||
// ------------------------------------------------------------------ | ||
#ifndef CAFFE_FRCNN_PROPOSAL_LAYER_HPP_ | ||
#define CAFFE_FRCNN_PROPOSAL_LAYER_HPP_ | ||
|
||
#include <vector> | ||
|
||
#include "caffe/blob.hpp" | ||
#include "caffe/common.hpp" | ||
#include "caffe/layer.hpp" | ||
#include "caffe/proto/caffe.pb.h" | ||
|
||
namespace caffe { | ||
|
||
/************************************************* | ||
FrcnnProposalLayer | ||
Outputs object detection proposals by applying estimated bounding-box | ||
transformations to a set of regular boxes (called "anchors"). | ||
bottom: 'rpn_cls_prob_reshape' | ||
bottom: 'rpn_bbox_pred' | ||
bottom: 'im_info' | ||
top: 'rpn_rois' | ||
**************************************************/ | ||
template <typename Dtype> | ||
class FrcnnProposalLayer : public Layer<Dtype> { | ||
public: | ||
explicit FrcnnProposalLayer(const LayerParameter& param) | ||
: Layer<Dtype>(param) {} | ||
virtual void LayerSetUp(const vector<Blob<Dtype>*>& bottom, | ||
const vector<Blob<Dtype>*>& top); | ||
virtual void Reshape(const vector<Blob<Dtype>*>& bottom, | ||
const vector<Blob<Dtype>*>& top){}; | ||
|
||
virtual inline const char* type() const { return "FrcnnProposal"; } | ||
|
||
virtual inline int MinBottomBlobs() const { return 3; } | ||
virtual inline int MaxBottomBlobs() const { return 3; } | ||
virtual inline int MinTopBlobs() const { return 1; } | ||
virtual inline int MaxTopBlobs() const { return 2; } | ||
|
||
#ifndef CPU_ONLY | ||
virtual ~FrcnnProposalLayer() { | ||
if (this->anchors_) { | ||
CUDA_CHECK(cudaFree(this->anchors_)); | ||
} | ||
if (this->transform_bbox_) { | ||
CUDA_CHECK(cudaFree(this->transform_bbox_)); | ||
} | ||
if (this->mask_) { | ||
CUDA_CHECK(cudaFree(this->mask_)); | ||
} | ||
if (this->selected_flags_) { | ||
CUDA_CHECK(cudaFree(this->selected_flags_)); | ||
} | ||
if (this->gpu_keep_indices_) { | ||
CUDA_CHECK(cudaFree(this->gpu_keep_indices_)); | ||
} | ||
} | ||
#endif | ||
|
||
protected: | ||
virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom, | ||
const vector<Blob<Dtype>*>& top); | ||
virtual void Forward_gpu(const vector<Blob<Dtype>*>& bottom, | ||
const vector<Blob<Dtype>*>& top); | ||
virtual void Backward_cpu(const vector<Blob<Dtype>*>& top, | ||
const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom); | ||
virtual void Backward_gpu(const vector<Blob<Dtype>*>& top, | ||
const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom); | ||
#ifndef CPU_ONLY | ||
// CUDA CU | ||
float* anchors_; | ||
float* transform_bbox_; | ||
unsigned long long *mask_; | ||
int *selected_flags_; | ||
int *gpu_keep_indices_; | ||
#endif | ||
}; | ||
|
||
} // namespace caffe | ||
|
||
#endif // CAFFE_FRCNN_PROPOSAL_LAYER_HPP_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#ifndef CAFFE_FRCNN_GPU_NMS_HPP_ | ||
#define CAFFE_FRCNN_GPU_NMS_HPP_ | ||
|
||
namespace caffe { | ||
|
||
void gpu_nms(int* keep_out, int* num_out, const float* boxes_dev, int boxes_num, | ||
int boxes_dim, float nms_overlap_thresh, int device_id=-1); | ||
|
||
} // namespace caffe | ||
#endif // CAFFE_FRCNN_UTILS_HPP_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// ------------------------------------------------------------------ | ||
// Xuanyi . Refer to Dong Jian | ||
// 2016/04/01 | ||
// ------------------------------------------------------------------ | ||
#ifndef CAFFE_FRCNN_HELPER_HPP_ | ||
#define CAFFE_FRCNN_HELPER_HPP_ | ||
|
||
#include "caffe/util/frcnn_utils.hpp" | ||
|
||
namespace caffe { | ||
|
||
template <typename Dtype> | ||
Point4f<Dtype> bbox_transform(const Point4f<Dtype>& ex_rois,const Point4f<Dtype>& gt_rois); | ||
|
||
template <typename Dtype> | ||
std::vector<Point4f<Dtype> > bbox_transform(const std::vector<Point4f<Dtype> >& ex_rois, | ||
const std::vector<Point4f<Dtype> >& gt_rois); | ||
|
||
template <typename Dtype> | ||
Point4f<Dtype> bbox_transform_inv(const Point4f<Dtype>& box, const Point4f<Dtype>& delta); | ||
|
||
template <typename Dtype> | ||
std::vector<Point4f<Dtype> > bbox_transform_inv(const Point4f<Dtype>& box, | ||
const std::vector<Point4f<Dtype> >& deltas); | ||
|
||
} // namespace caffe | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// ------------------------------------------------------------------ | ||
// Xuanyi . Refer to Dong Jian | ||
// 2016/03/31 | ||
// ------------------------------------------------------------------ | ||
#ifndef CAFFE_FRCNN_PRARM_HPP_ | ||
#define CAFFE_FRCNN_PRARM_HPP_ | ||
|
||
#include <vector> | ||
#include <string> | ||
|
||
namespace caffe{ | ||
|
||
class FrcnnParam { | ||
public: | ||
|
||
static float rpn_nms_thresh; | ||
static int rpn_pre_nms_top_n; | ||
static int rpn_post_nms_top_n; | ||
// Proposal height and width both need to be greater than RPN_MIN_SIZE (at | ||
// orig image scale) | ||
static float rpn_min_size; | ||
|
||
static float test_rpn_nms_thresh; | ||
static int test_rpn_pre_nms_top_n; | ||
static int test_rpn_post_nms_top_n; | ||
// Proposal height and width both need to be greater than RPN_MIN_SIZE (at | ||
// orig image scale) | ||
static float test_rpn_min_size; | ||
|
||
static int feat_stride; | ||
static std::vector<float> anchors; | ||
static int n_classes; | ||
// ======================================== | ||
static void load_param(const std::string default_config_path); | ||
static void print_param(); | ||
}; | ||
|
||
} | ||
|
||
#endif // CAFFE_FRCNN_PRARM_HPP_ |
Oops, something went wrong.