In caffe, the layer is fully connected is called "inner_product_layer", the distinguished tensorflow fullyconnected_layer.
1, prototxt defined in
Layer {
bottom: "FC7"
Top: "FC8"
name: "FC8"
type: "InnerProduct" param { # weight learning parameter lr_mult: 10 # learning rate decay_mult: . 1} param { # BIAS learning parameters lr_mult: 20 is # general , bias learning rate is a weight twice the learning rate decay_mult:. 0} inner_product_param {num_output: 1000 # number output unit weight_filler { # weights initializer type: "Gaussian" STD: 0.005} bias_filler { # BIAS initializer type: " Constant "value: 0.1}}}
2, as defined in caffe.proto
LayerParameter {Message
optional InnerProductParameter = inner_product_param 117;
}
Message {InnerProductParameter
optional UInt32 num_output = . 1; // number of network layer output optional BOOL bias_term = 2 [ default = to true]; // item if there is bias FillerParameter weight_filler = optional . 3; / / weight Filler optional FillerParameter bias_filler = weight . 4; // Filler bias bIAS // inner product computation for a single first Axis. // -1 is the last optional Axis Int32 = Axis . 5 [ default = . 1]; // if the weight matrix is transposed optional BOOL tRANSPOSE = . 6 [default = false]; }
3、inner_product_layer.hpp
#ifndef CAFFE_INNER_PRODUCT_LAYER_HPP_
#define CAFFE_INNER_PRODUCT_LAYER_HPP_
#include <vector>
#include "caffe/blob.hpp" #include "caffe/layer.hpp" #include "caffe/proto/caffe.pb.h" namespace caffe { /** * @brief Also known as a "fully-connected" layer, computes an inner product * with a set of learned weights, and (optionally) adds biases. * * TODO(dox): thorough documentation for Forward, Backward, and proto params. */ template <typename Dtype> class InnerProductLayer : public Layer<Dtype> { public: explicit InnerProductLayer(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 "InnerProduct"; } virtual inline int ExactNumBottomBlobs() const { return 1; } virtual inline int ExactNumTopBlobs() const { return 1; } 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); virtual void Backward_gpu(const vector<Blob<Dtype>*>& top, const