1 #ifndef INCLUDE_NET_NET_H_
2 #define INCLUDE_NET_NET_H_
4 #include <glog/logging.h>
9 #include "proto/model.pb.h"
10 #include "neuralnet/layer.h"
11 #include "utils/factory.h"
12 #include "utils/graph.h"
17 using std::shared_ptr;
78 void ShareParams(shared_ptr<NeuralNet> other,
int flag);
79 void ToProto(
NetProto *net_proto,
bool copyData=
false);
80 const std::vector<shared_ptr<Layer>>& layers() {
87 if(parserlayers_.size()==0){
88 for(
auto& layer: layers_)
89 if(layer->is_parserlayer())
90 parserlayers_.push_back(static_cast<ParserLayer*>(layer.get()));
94 const std::vector<LossLayer*>& losslayers() {
95 if(losslayers_.size()==0){
96 for(
auto& layer: layers_)
97 if(layer->is_losslayer())
98 losslayers_.push_back(static_cast<LossLayer*>(layer.get()));
102 const std::vector<DataLayer*>& datalayers() {
103 if(datalayers_.size()==0){
104 for(
auto& layer: layers_)
105 if(layer->is_datalayer())
106 datalayers_.push_back(static_cast<DataLayer*>(layer.get()));
110 const std::vector<shared_ptr<Param>> ¶ms()
const {
113 shared_ptr<Layer> name2layer(
string name){
114 if (name2layer_.find(name)!=name2layer_.end())
115 return name2layer_[name];
119 shared_ptr<Param> paramid2param(
int id) {
120 if(paramid2param_.size()==0){
121 for(
auto& layer: layers_){
122 for(shared_ptr<Param> p: layer->GetParams()){
123 paramid2param_[p->id()]=p;
127 return paramid2param_[id];
131 void ConstructNeuralNet(
const NetProto &net_proto);
132 void PartitionNeuralNet();
133 map<string, shared_ptr<Layer>> GetNameToLayer(
134 const vector<shared_ptr<Layer>>& layers);
135 Graph CreatePartitonedGraph(
const vector<shared_ptr<Layer>>& layers,
136 const map<
string, shared_ptr<Layer>>& name2layer);
143 const vector<shared_ptr<Layer>>& layers);
146 vector<shared_ptr<Layer>> layers_;
147 vector<ParserLayer*> parserlayers_;
148 vector<LossLayer*> losslayers_;
149 vector<DataLayer*> datalayers_;
150 vector<shared_ptr<Param>> params_;
151 map<string, shared_ptr<Layer>> name2layer_;
152 map<int, shared_ptr<Param>> paramid2param_;
154 map<string, LayerProto> name2layerproto_;
159 #endif // INCLUDE_NET_NET_H_
const std::vector< ParserLayer * > & parserlayers()
return ParserLayer of the neuralnet.
Definition: neuralnet.h:86
Definition: model.pb.h:1128
For partition neuralnet and displaying the neuralnet structure.
Definition: graph.h:81
void AddLayer(const LayerProto &layer_proto)
Add layer explicitly used in manually programming/constructing neural net.
Definition: neuralnet.h:70
static shared_ptr< NeuralNet > SetupNeuralNet(const NetProto &np, Phase phase, int group_size)
Setup the neural network for training, test or validation.
std::string ToAdjacency()
to display the adjacency layers
map< string, vector< shared_ptr< Layer > > > PartitionLayers(const vector< shared_ptr< Layer >> &layers)
Partition each layer according its partition type and dimension.
string DebugInfo()
Print Norm1 of data and grad of each Layer and parameter.
Definition: model.pb.h:669
Base layer class.
Definition: base_layer.h:37
void ShareParams(shared_ptr< NeuralNet > other, int flag)
share weights from other neuralnet
NeuralNet(NetProto net_proto, int group_size=1)
construct the net structure from protocol buffer.
The neural network is constructed from user configured layers through google protocol buffer...
Definition: neuralnet.h:27
std::string ToString()
construct a json string representing the neuralnet graph.
static void RegisterLayers()
Register Layers.
void AddLayer(const Layer *layer)
Add layer explicitly used in manually programming/constructing neural net.
Definition: neuralnet.h:74