Caffe
accuracy_layer.hpp
1 #ifndef CAFFE_ACCURACY_LAYER_HPP_
2 #define CAFFE_ACCURACY_LAYER_HPP_
3 
4 #include <vector>
5 
6 #include "caffe/blob.hpp"
7 #include "caffe/layer.hpp"
8 #include "caffe/proto/caffe.pb.h"
9 
10 #include "caffe/layers/loss_layer.hpp"
11 
12 namespace caffe {
13 
18 template <typename Dtype>
19 class AccuracyLayer : public Layer<Dtype> {
20  public:
29  explicit AccuracyLayer(const LayerParameter& param)
30  : Layer<Dtype>(param) {}
31  virtual void LayerSetUp(const vector<Blob<Dtype>*>& bottom,
32  const vector<Blob<Dtype>*>& top);
33  virtual void Reshape(const vector<Blob<Dtype>*>& bottom,
34  const vector<Blob<Dtype>*>& top);
35 
36  virtual inline const char* type() const { return "Accuracy"; }
37  virtual inline int ExactNumBottomBlobs() const { return 2; }
38 
39  // If there are two top blobs, then the second blob will contain
40  // accuracies per class.
41  virtual inline int MinTopBlobs() const { return 1; }
42  virtual inline int MaxTopBlobs() const { return 2; }
43 
44  protected:
69  virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,
70  const vector<Blob<Dtype>*>& top);
71 
72 
74  virtual void Backward_cpu(const vector<Blob<Dtype>*>& top,
75  const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom) {
76  for (int i = 0; i < propagate_down.size(); ++i) {
77  if (propagate_down[i]) { NOT_IMPLEMENTED; }
78  }
79  }
80 
81  int label_axis_, outer_num_, inner_num_;
82 
83  int top_k_;
84 
91 };
92 
93 } // namespace caffe
94 
95 #endif // CAFFE_ACCURACY_LAYER_HPP_
An interface for the units of computation which can be composed into a Net.
Definition: layer.hpp:33
A layer factory that allows one to register layers. During runtime, registered layers can be called b...
Definition: blob.hpp:14
virtual int ExactNumBottomBlobs() const
Returns the exact number of bottom blobs required by the layer, or -1 if no exact number is required...
Definition: accuracy_layer.hpp:37
virtual void LayerSetUp(const vector< Blob< Dtype > *> &bottom, const vector< Blob< Dtype > *> &top)
Does layer-specific setup: your layer should implement this function as well as Reshape.
Definition: accuracy_layer.cpp:11
int ignore_label_
The label indicating that an instance should be ignored.
Definition: accuracy_layer.hpp:88
virtual void Forward_cpu(const vector< Blob< Dtype > *> &bottom, const vector< Blob< Dtype > *> &top)
Definition: accuracy_layer.cpp:48
virtual void Reshape(const vector< Blob< Dtype > *> &bottom, const vector< Blob< Dtype > *> &top)
Adjust the shapes of top blobs and internal buffers to accommodate the shapes of the bottom blobs...
Definition: accuracy_layer.cpp:23
Computes the classification accuracy for a one-of-many classification task.
Definition: accuracy_layer.hpp:19
virtual int MaxTopBlobs() const
Returns the maximum number of top blobs required by the layer, or -1 if no maximum number is required...
Definition: accuracy_layer.hpp:42
bool has_ignore_label_
Whether to ignore instances with a certain label.
Definition: accuracy_layer.hpp:86
virtual int MinTopBlobs() const
Returns the minimum number of top blobs required by the layer, or -1 if no minimum number is required...
Definition: accuracy_layer.hpp:41
AccuracyLayer(const LayerParameter &param)
Definition: accuracy_layer.hpp:29
virtual const char * type() const
Returns the layer type.
Definition: accuracy_layer.hpp:36
Blob< Dtype > nums_buffer_
Keeps counts of the number of samples per class.
Definition: accuracy_layer.hpp:90
virtual void Backward_cpu(const vector< Blob< Dtype > *> &top, const vector< bool > &propagate_down, const vector< Blob< Dtype > *> &bottom)
Not implemented – AccuracyLayer cannot be used as a loss.
Definition: accuracy_layer.hpp:74
A wrapper around SyncedMemory holders serving as the basic computational unit through which Layers...
Definition: blob.hpp:24