Repository URL to install this package:
|
Version:
1.0.0-8 ▾
|
#ifndef CAFFE_SEG_ACCURACY_LAYER_HPP_
#define CAFFE_SEG_ACCURACY_LAYER_HPP_
#include <vector>
#include "caffe/blob.hpp"
#include "caffe/common.hpp"
#include "caffe/layer.hpp"
#include "caffe/util/confusion_matrix.hpp"
#include "caffe/proto/caffe.pb.h"
namespace caffe {
template <typename Dtype>
class SegAccuracyLayer : public Layer<Dtype> {
public:
explicit SegAccuracyLayer(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 "SegAccuracy"; }
virtual inline int ExactNumBottomBlobs() const { return 2; }
virtual inline int ExactNumTopBlobs() const { return 1; }
protected:
/**
* @param bottom input Blob vector (length 2)
* -# @f$ (N \times C \times H \times W) @f$
* the predictions @f$ x @f$, a Blob with values in
* @f$ [-\infty, +\infty] @f$ indicating the predicted score for each of
* the @f$ K = CHW @f$ classes. Each @f$ x_n @f$ is mapped to a predicted
* label @f$ \hat{l}_n @f$ given by its maximal index:
* @f$ \hat{l}_n = \arg\max\limits_k x_{nk} @f$
* -# @f$ (N \times 1 \times 1 \times 1) @f$
* the labels @f$ l @f$, an integer-valued Blob with values
* @f$ l_n \in [0, 1, 2, ..., K - 1] @f$
* indicating the correct class label among the @f$ K @f$ classes
* @param top output Blob vector (length 1)
* -# @f$ (1 \times 1 \times 1 \times 1) @f$
* the computed accuracy: @f$
* \frac{1}{N} \sum\limits_{n=1}^N \delta\{ \hat{l}_n = l_n \}
* @f$, where @f$
* \delta\{\mathrm{condition}\} = \left\{
* \begin{array}{lr}
* 1 & \mbox{if condition} \\
* 0 & \mbox{otherwise}
* \end{array} \right.
* @f$
*/
virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,
const vector<Blob<Dtype>*>& top);
/// @brief Not implemented -- AccuracyLayer cannot be used as a loss.
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; }
}
}
ConfusionMatrix confusion_matrix_;
// set of ignore labels
std::set<int> ignore_label_;
};
} // namespace caffe
#endif // CAFFE_SEG_ACCURACY_HPP_