From ba9b7a09d37b13926d91e07880be7a19093e6884 Mon Sep 17 00:00:00 2001 From: Jonathan L Long Date: Thu, 25 Dec 2014 14:34:54 -0800 Subject: [PATCH] implement coord_map for all applicable layers --- include/caffe/common_layers.hpp | 18 ++++++++++++++++++ include/caffe/layer.hpp | 8 ++++++++ include/caffe/neuron_layers.hpp | 3 +++ include/caffe/vision_layers.hpp | 16 +++++++++++++++- 4 files changed, 44 insertions(+), 1 deletion(-) diff --git a/include/caffe/common_layers.hpp b/include/caffe/common_layers.hpp index 9718b825b14..db2310e30db 100644 --- a/include/caffe/common_layers.hpp +++ b/include/caffe/common_layers.hpp @@ -91,6 +91,9 @@ class ConcatLayer : public Layer { } virtual inline int MinBottomBlobs() const { return 2; } virtual inline int ExactNumTopBlobs() const { return 1; } + virtual inline DiagonalAffineMap coord_map() { + return DiagonalAffineMap::identity(2); + } protected: /** @@ -171,6 +174,9 @@ class EltwiseLayer : public Layer { } virtual inline int MinBottomBlobs() const { return 2; } virtual inline int ExactNumTopBlobs() const { return 1; } + virtual inline DiagonalAffineMap coord_map() { + return DiagonalAffineMap::identity(2); + } protected: virtual void Forward_cpu(const vector*>& bottom, @@ -301,6 +307,9 @@ class MVNLayer : public Layer { } virtual inline int ExactNumBottomBlobs() const { return 1; } virtual inline int ExactNumTopBlobs() const { return 1; } + virtual inline DiagonalAffineMap coord_map() { + return DiagonalAffineMap::identity(2); + } protected: virtual void Forward_cpu(const vector*>& bottom, @@ -367,6 +376,9 @@ class SoftmaxLayer : public Layer { } virtual inline int ExactNumBottomBlobs() const { return 1; } virtual inline int ExactNumTopBlobs() const { return 1; } + virtual inline DiagonalAffineMap coord_map() { + return DiagonalAffineMap::identity(2); + } protected: virtual void Forward_cpu(const vector*>& bottom, @@ -431,6 +443,9 @@ class SplitLayer : public Layer { } virtual inline int ExactNumBottomBlobs() const { return 1; } virtual inline int MinTopBlobs() const { return 1; } + virtual inline DiagonalAffineMap coord_map() { + return DiagonalAffineMap::identity(2); + } protected: virtual void Forward_cpu(const vector*>& bottom, @@ -466,6 +481,9 @@ class SliceLayer : public Layer { } virtual inline int ExactNumBottomBlobs() const { return 1; } virtual inline int MinTopBlobs() const { return 2; } + virtual inline DiagonalAffineMap coord_map() { + return DiagonalAffineMap::identity(2); + } protected: virtual void Forward_cpu(const vector*>& bottom, diff --git a/include/caffe/layer.hpp b/include/caffe/layer.hpp index 8a8330bca57..b14b632e694 100644 --- a/include/caffe/layer.hpp +++ b/include/caffe/layer.hpp @@ -3,12 +3,14 @@ #include #include +#include #include #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 { @@ -293,6 +295,12 @@ class Layer { param_propagate_down_[param_id] = value; } + virtual DiagonalAffineMap coord_map() { + NOT_IMPLEMENTED; + // suppress warnings + return DiagonalAffineMap(vector >()); + } + protected: /** The protobuf that stores the layer parameters */ diff --git a/include/caffe/neuron_layers.hpp b/include/caffe/neuron_layers.hpp index 5daeeefe7ae..312a2a0cf38 100644 --- a/include/caffe/neuron_layers.hpp +++ b/include/caffe/neuron_layers.hpp @@ -34,6 +34,9 @@ class NeuronLayer : public Layer { } virtual inline int ExactNumBottomBlobs() const { return 1; } virtual inline int ExactNumTopBlobs() const { return 1; } + virtual inline DiagonalAffineMap coord_map() { + return DiagonalAffineMap::identity(2); + } }; /** diff --git a/include/caffe/vision_layers.hpp b/include/caffe/vision_layers.hpp index 646378dea9f..b0f5c06ca74 100644 --- a/include/caffe/vision_layers.hpp +++ b/include/caffe/vision_layers.hpp @@ -159,6 +159,10 @@ class ConvolutionLayer : public BaseConvolutionLayer { virtual inline LayerParameter_LayerType type() const { return LayerParameter_LayerType_CONVOLUTION; } + virtual inline DiagonalAffineMap coord_map() { + return FilterMap(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*>& bottom, @@ -181,7 +185,10 @@ class DeconvolutionLayer : public BaseConvolutionLayer { virtual inline LayerParameter_LayerType type() const { return LayerParameter_LayerType_DECONVOLUTION; } - + virtual inline DiagonalAffineMap coord_map() { + return FilterMap(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*>& bottom, const vector*>& top); @@ -301,6 +308,9 @@ class LRNLayer : public Layer { } virtual inline int ExactNumBottomBlobs() const { return 1; } virtual inline int ExactNumTopBlobs() const { return 1; } + virtual inline DiagonalAffineMap coord_map() { + return DiagonalAffineMap::identity(2); + } protected: virtual void Forward_cpu(const vector*>& bottom, @@ -385,6 +395,10 @@ class PoolingLayer : public Layer { return (this->layer_param_.pooling_param().pool() == PoolingParameter_PoolMethod_MAX) ? 2 : 1; } + virtual inline DiagonalAffineMap coord_map() { + return FilterMap(kernel_h_, kernel_w_, stride_h_, stride_w_, + pad_h_, pad_w_).inv(); + } protected: virtual void Forward_cpu(const vector*>& bottom,