accuracy_layer.hpp
#ifndef CAFFE_ACCURACY_LAYER_HPP_
#define CAFFE_ACCURACY_LAYER_HPP_
#include <vector>
#include "caffe/blob.hpp"
#include "caffe/layer.hpp"
#include "caffe/proto/caffe.pb.h"
#include "caffe/layers/loss_layer.hpp"
namespace caffe {
template <typename Dtype>
class AccuracyLayer : public Layer<Dtype> {
public:
explicit AccuracyLayer(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 "Accuracy"; }
virtual inline int ExactNumBottomBlobs() const { return 2; }
// If there are two top blobs, then the second blob will contain
// accuracies per class.
virtual inline int MinTopBlobs() const { return 1; }
virtual inline int MaxTopBlobs() const { return 2; }
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) {
for (int i = 0; i < propagate_down.size(); ++i) {
if (propagate_down[i]) { NOT_IMPLEMENTED; }
}
}
virtual void Backward_gpu(const vector<Blob<Dtype>*>& top,
const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom);
int label_axis_, outer_num_, inner_num_;
int top_k_;
bool has_ignore_label_;
int ignore_label_;
Blob<Dtype> nums_buffer_;
};
} // namespace caffe
#endif // CAFFE_ACCURACY_LAYER_HPP_
caffe::AccuracyLayer::LayerSetUp
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
caffe::AccuracyLayer::nums_buffer_
Blob< Dtype > nums_buffer_
Keeps counts of the number of samples per class.
Definition: accuracy_layer.hpp:94
caffe::AccuracyLayer::Forward_gpu
virtual void Forward_gpu(const vector< Blob< Dtype > * > &bottom, const vector< Blob< Dtype > * > &top)
Using the GPU device, compute the layer output. Fall back to Forward_cpu() if unavailable.
caffe::AccuracyLayer::ExactNumBottomBlobs
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
caffe::AccuracyLayer::has_ignore_label_
bool has_ignore_label_
Whether to ignore instances with a certain label.
Definition: accuracy_layer.hpp:90
caffe::AccuracyLayer::MinTopBlobs
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
caffe::Blob
A wrapper around SyncedMemory holders serving as the basic computational unit through which Layers,...
Definition: blob.hpp:24
caffe::AccuracyLayer::Forward_cpu
virtual void Forward_cpu(const vector< Blob< Dtype > * > &bottom, const vector< Blob< Dtype > * > &top)
Definition: accuracy_layer.cpp:48
caffe::Layer
An interface for the units of computation which can be composed into a Net.
Definition: layer.hpp:33
caffe::AccuracyLayer::AccuracyLayer
AccuracyLayer(const LayerParameter &param)
Definition: accuracy_layer.hpp:29
caffe::AccuracyLayer::Backward_cpu
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:76
caffe::AccuracyLayer
Computes the classification accuracy for a one-of-many classification task.
Definition: accuracy_layer.hpp:19
caffe::AccuracyLayer::Reshape
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
caffe::AccuracyLayer::MaxTopBlobs
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
caffe::AccuracyLayer::Backward_gpu
virtual void Backward_gpu(const vector< Blob< Dtype > * > &top, const vector< bool > &propagate_down, const vector< Blob< Dtype > * > &bottom)
Using the GPU device, compute the gradients for any parameters and for the bottom blobs if propagate_...
caffe::AccuracyLayer::type
virtual const char * type() const
Returns the layer type.
Definition: accuracy_layer.hpp:36
caffe
A layer factory that allows one to register layers. During runtime, registered layers can be called b...
Definition: blob.hpp:14
caffe::AccuracyLayer::ignore_label_
int ignore_label_
The label indicating that an instance should be ignored.
Definition: accuracy_layer.hpp:92