Skip to content

Commit b6fcf16

Browse files
committed
implement the rest part of ssd detection_output
1 parent fd7f96d commit b6fcf16

File tree

3 files changed

+452
-1
lines changed

3 files changed

+452
-1
lines changed
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
#ifndef CAFFE_SSD_SORT_LAYER_HPP_
2+
#define CAFFE_SSD_SORT_LAYER_HPP_
3+
4+
#include <boost/property_tree/json_parser.hpp>
5+
#include <boost/property_tree/ptree.hpp>
6+
#include <boost/regex.hpp>
7+
8+
#include <map>
9+
#include <string>
10+
#include <utility>
11+
#include <vector>
12+
13+
#include "caffe/blob.hpp"
14+
#include "caffe/data_transformer.hpp"
15+
#include "caffe/layer.hpp"
16+
#include "caffe/proto/caffe.pb.h"
17+
#include "caffe/util/bbox_util.hpp"
18+
19+
using namespace boost::property_tree; // NOLINT(build/namespaces)
20+
21+
namespace caffe {
22+
23+
/**
24+
* @brief Separate the nms and sort part from the detection_output layer
25+
* and simplify the implementations for host_fixed usage.
26+
*
27+
* NOTE: does not implement Backwards operation.
28+
*/
29+
template <typename Dtype>
30+
class SSDSortLayer : public Layer<Dtype> {
31+
public:
32+
explicit SSDSortLayer(const LayerParameter& param)
33+
: Layer<Dtype>(param) {}
34+
virtual void LayerSetUp(const vector<Blob<Dtype>*>& bottom,
35+
const vector<Blob<Dtype>*>& top);
36+
virtual void Reshape(const vector<Blob<Dtype>*>& bottom,
37+
const vector<Blob<Dtype>*>& top);
38+
39+
virtual inline const char* type() const { return "SSDSort"; }
40+
virtual inline int ExactNumBottomBlobs() const { return 2; } //bottom0 is decoded bbox, bottom1 is conf
41+
virtual inline int ExactNumTopBlobs() const { return 1; }
42+
43+
protected:
44+
/**
45+
* @brief Do non maximum suppression (nms) on prediction results.
46+
*
47+
* @param bottom input Blob vector (at least 2)
48+
* -# @f$ (N \times C1 \times 1 \times 1) @f$
49+
* the location predictions with C1 predictions.
50+
* -# @f$ (N \times C2 \times 1 \times 1) @f$
51+
* the confidence predictions with C2 predictions.
52+
* -# @f$ (N \times 2 \times C3 \times 1) @f$
53+
* the prior bounding boxes with C3 values.
54+
* @param top output Blob vector (length 1)
55+
* -# @f$ (1 \times 1 \times N \times 7) @f$
56+
* N is the number of detections after nms, and each row is:
57+
* [image_id, label, confidence, xmin, ymin, xmax, ymax]
58+
*/
59+
virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,
60+
const vector<Blob<Dtype>*>& top);
61+
/// @brief Not implemented
62+
virtual void Backward_cpu(const vector<Blob<Dtype>*>& top,
63+
const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom) {
64+
NOT_IMPLEMENTED;
65+
}
66+
67+
float objectness_score_;
68+
int num_classes_;
69+
bool share_location_;
70+
int num_loc_classes_;
71+
int background_label_id_;
72+
CodeType code_type_;
73+
bool variance_encoded_in_target_;
74+
int keep_top_k_;
75+
float confidence_threshold_;
76+
77+
int num_;
78+
int num_priors_;
79+
80+
float nms_threshold_;
81+
int top_k_;
82+
float eta_;
83+
84+
bool need_save_;
85+
string output_directory_;
86+
string output_name_prefix_;
87+
string output_format_;
88+
map<int, string> label_to_name_;
89+
map<int, string> label_to_display_name_;
90+
vector<string> names_;
91+
vector<pair<int, int> > sizes_;
92+
int num_test_image_;
93+
int name_count_;
94+
bool has_resize_;
95+
ResizeParameter resize_param_;
96+
97+
ptree detections_;
98+
99+
bool visualize_;
100+
float visualize_threshold_;
101+
shared_ptr<DataTransformer<Dtype> > data_transformer_;
102+
string save_file_;
103+
Blob<Dtype> bbox_preds_;
104+
Blob<Dtype> bbox_permute_;
105+
Blob<Dtype> conf_permute_;
106+
};
107+
108+
} // namespace caffe
109+
110+
#endif // CAFFE_SSD_SORT_LAYER_HPP_

src/caffe/layers/ssd_decoder_layer.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ void SSDDecoderLayer<Dtype>::LayerSetUp(const vector<Blob<Dtype>*>& bottom,
122122
if (!share_location_) {
123123
bbox_permute_.ReshapeLike(*(bottom[0]));
124124
}
125-
conf_permute_.ReshapeLike(*(bottom[1]));
126125
}
127126

128127
template <typename Dtype>

0 commit comments

Comments
 (0)