Skip to content

Commit

Permalink
implement coord_map for all applicable layers
Browse files Browse the repository at this point in the history
  • Loading branch information
longjon committed Dec 31, 2014
1 parent 8e459ef commit b6e1460
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1 deletion.
18 changes: 18 additions & 0 deletions include/caffe/common_layers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ class ConcatLayer : public Layer<Dtype> {
}
virtual inline int MinBottomBlobs() const { return 2; }
virtual inline int ExactNumTopBlobs() const { return 1; }
virtual inline DiagonalAffineMap<Dtype> coord_map() {
return DiagonalAffineMap<Dtype>::identity(2);
}

protected:
/**
Expand Down Expand Up @@ -171,6 +174,9 @@ class EltwiseLayer : public Layer<Dtype> {
}
virtual inline int MinBottomBlobs() const { return 2; }
virtual inline int ExactNumTopBlobs() const { return 1; }
virtual inline DiagonalAffineMap<Dtype> coord_map() {
return DiagonalAffineMap<Dtype>::identity(2);
}

protected:
virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,
Expand Down Expand Up @@ -301,6 +307,9 @@ class MVNLayer : public Layer<Dtype> {
}
virtual inline int ExactNumBottomBlobs() const { return 1; }
virtual inline int ExactNumTopBlobs() const { return 1; }
virtual inline DiagonalAffineMap<Dtype> coord_map() {
return DiagonalAffineMap<Dtype>::identity(2);
}

protected:
virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,
Expand Down Expand Up @@ -367,6 +376,9 @@ class SoftmaxLayer : public Layer<Dtype> {
}
virtual inline int ExactNumBottomBlobs() const { return 1; }
virtual inline int ExactNumTopBlobs() const { return 1; }
virtual inline DiagonalAffineMap<Dtype> coord_map() {
return DiagonalAffineMap<Dtype>::identity(2);
}

protected:
virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,
Expand Down Expand Up @@ -431,6 +443,9 @@ class SplitLayer : public Layer<Dtype> {
}
virtual inline int ExactNumBottomBlobs() const { return 1; }
virtual inline int MinTopBlobs() const { return 1; }
virtual inline DiagonalAffineMap<Dtype> coord_map() {
return DiagonalAffineMap<Dtype>::identity(2);
}

protected:
virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,
Expand Down Expand Up @@ -466,6 +481,9 @@ class SliceLayer : public Layer<Dtype> {
}
virtual inline int ExactNumBottomBlobs() const { return 1; }
virtual inline int MinTopBlobs() const { return 2; }
virtual inline DiagonalAffineMap<Dtype> coord_map() {
return DiagonalAffineMap<Dtype>::identity(2);
}

protected:
virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,
Expand Down
8 changes: 8 additions & 0 deletions include/caffe/layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@

#include <algorithm>
#include <string>
#include <utility>
#include <vector>

#include "caffe/blob.hpp"
#include "caffe/common.hpp"
#include "caffe/layer_factory.hpp"
#include "caffe/proto/caffe.pb.h"
#include "caffe/util/coords.hpp"
#include "caffe/util/device_alternate.hpp"

namespace caffe {
Expand Down Expand Up @@ -293,6 +295,12 @@ class Layer {
param_propagate_down_[param_id] = value;
}

virtual DiagonalAffineMap<Dtype> coord_map() {
NOT_IMPLEMENTED;
// suppress warnings
return DiagonalAffineMap<Dtype>(vector<pair<Dtype, Dtype> >());
}


protected:
/** The protobuf that stores the layer parameters */
Expand Down
3 changes: 3 additions & 0 deletions include/caffe/neuron_layers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ class NeuronLayer : public Layer<Dtype> {
}
virtual inline int ExactNumBottomBlobs() const { return 1; }
virtual inline int ExactNumTopBlobs() const { return 1; }
virtual inline DiagonalAffineMap<Dtype> coord_map() {
return DiagonalAffineMap<Dtype>::identity(2);
}
};

/**
Expand Down
16 changes: 15 additions & 1 deletion include/caffe/vision_layers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ class ConvolutionLayer : public BaseConvolutionLayer<Dtype> {
virtual inline LayerParameter_LayerType type() const {
return LayerParameter_LayerType_CONVOLUTION;
}
virtual inline DiagonalAffineMap<Dtype> coord_map() {
return FilterMap<Dtype>(this->kernel_h_, this->kernel_w_, this->stride_h_,
this->stride_w_, this->pad_h_, this->pad_w_).inv();
}

protected:
virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,
Expand All @@ -181,7 +185,10 @@ class DeconvolutionLayer : public BaseConvolutionLayer<Dtype> {
virtual inline LayerParameter_LayerType type() const {
return LayerParameter_LayerType_DECONVOLUTION;
}

virtual inline DiagonalAffineMap<Dtype> coord_map() {
return FilterMap<Dtype>(this->kernel_h_, this->kernel_w_, this->stride_h_,
this->stride_w_, this->pad_h_, this->pad_w_);
}
protected:
virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,
const vector<Blob<Dtype>*>& top);
Expand Down Expand Up @@ -301,6 +308,9 @@ class LRNLayer : public Layer<Dtype> {
}
virtual inline int ExactNumBottomBlobs() const { return 1; }
virtual inline int ExactNumTopBlobs() const { return 1; }
virtual inline DiagonalAffineMap<Dtype> coord_map() {
return DiagonalAffineMap<Dtype>::identity(2);
}

protected:
virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,
Expand Down Expand Up @@ -385,6 +395,10 @@ class PoolingLayer : public Layer<Dtype> {
return (this->layer_param_.pooling_param().pool() ==
PoolingParameter_PoolMethod_MAX) ? 2 : 1;
}
virtual inline DiagonalAffineMap<Dtype> coord_map() {
return FilterMap<Dtype>(kernel_h_, kernel_w_, stride_h_, stride_w_,
pad_h_, pad_w_).inv();
}

protected:
virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,
Expand Down

0 comments on commit b6e1460

Please sign in to comment.