22 #ifndef SINGA_NEURALNET_LAYER_H_
23 #define SINGA_NEURALNET_LAYER_H_
29 #include "proto/common.pb.h"
30 #include "proto/job.pb.h"
31 #include "utils/common.h"
32 #include "utils/blob.h"
33 #include "utils/param.h"
46 static Layer* Create(
const LayerProto& proto);
60 virtual void Setup(
const LayerProto& proto,
int npartitions = 1) {
61 CHECK_GE(npartitions, 1);
83 virtual const std::vector<Param*>
GetParams()
const {
84 return std::vector<Param*> {};
125 virtual const std::string
DebugString(
int step,
int flag);
133 CHECK_LE(layer_proto_.partition_dim(), 1);
134 return layer_proto_.partition_dim();
136 inline int partition_id()
const {
return layer_proto_.partition_id(); }
137 inline int type()
const {
return layer_proto_.type(); }
141 inline const std::string &
name()
const {
return layer_proto_.name(); }
160 virtual const Blob<float>& grad(
const Layer* from)
const {
172 inline const std::vector<Layer*>
srclayers()
const {
return srclayers_; }
176 inline const std::vector<Layer*>
dstlayers()
const {
return dstlayers_; }
177 inline int srclayers_size()
const {
return srclayers_.size(); }
178 inline int dstlayers_size()
const {
return dstlayers_.size(); }
179 inline void clear_dstlayers() { dstlayers_.clear(); }
180 inline void clear_srclayers() { srclayers_.clear(); }
181 inline void add_srclayer(Layer* src) { srclayers_.push_back(src); }
182 inline void add_dstlayer(Layer* dst) { dstlayers_.push_back(dst); }
185 LayerProto layer_proto_;
186 Blob<float> data_, grad_;
187 std::vector<Layer*> srclayers_, dstlayers_;
219 LOG(FATAL) <<
"Loss layer has no gradient blob";
229 #include "neuralnet/connection_layer.h"
230 #include "neuralnet/input_layer.h"
231 #include "neuralnet/loss_layer.h"
232 #include "neuralnet/neuron_layer.h"
233 #include "neuralnet/output_layer.h"
235 #endif // SINGA_NEURALNET_LAYER_H_
virtual ConnectionType src_neuron_connection(int k) const
Return the connection type between one neuron of this layer and its source layer. ...
Definition: layer.h:97
virtual void Setup(const LayerProto &proto, int npartitions=1)
Setup layer properties.
Definition: layer.h:60
virtual const std::string DebugString(int step, int flag)
For print debug info about each layer, e.g., norm of feature vector, norm of parameters.
const std::string & name() const
Return name of this layer.
Definition: layer.h:141
Base layer for connecting layers when neural net is partitioned.
Definition: layer.h:193
const std::vector< Layer * > srclayers() const
return LayerS that connected to this layer
Definition: layer.h:172
virtual ConnectionType dst_layer_connection() const
Return the connection type of this layer and all dst layers.
Definition: layer.h:113
Base layer for calculating loss and other metrics, e.g., precison.
Definition: layer.h:213
virtual void ComputeFeature(int flag, Metric *perf)=0
Compute features of this layer based on connected layers.
virtual void ComputeGradient(int flag, Metric *perf)=0
Compute gradients for parameters and connected layers.
const std::vector< Layer * > dstlayers() const
return LayerS that this layer connected to
Definition: layer.h:176
virtual const std::vector< Param * > GetParams() const
Layers that have paramters must override this function.
Definition: layer.h:83
Base layer class.
Definition: layer.h:44
Blob< float > * mutable_grad(const Layer *layer) override
Definition: layer.h:215
int partition_dim() const
Definition: layer.h:132
virtual Blob< float > * mutable_grad(const Layer *from)
Definition: layer.h:166
Performance mtrics.
Definition: common.h:85
virtual const Blob< float > & data(const Layer *from) const
Definition: layer.h:154