1 // Copyright 2013 Yangqing Jia
10 #include "caffe/blob.hpp"
11 #include "caffe/common.hpp"
12 #include "caffe/layer.hpp"
13 #include "caffe/proto/caffe.pb.h"
22 template <typename Dtype>
25 Net(const NetParameter& param,
26 const vector<Blob<Dtype>* >& bottom);
28 const vector<Blob<Dtype>*>& Forward(const vector<Blob<Dtype>* > & bottom);
29 // The network backward should take no input and output, since it solely
30 // computes the gradient w.r.t the parameters, and the data has already
31 // been provided during the forward pass.
34 Dtype ForwardBackward(const vector<Blob<Dtype>* > & bottom) {
39 // For an already initialized net, CopyTrainedLayersFrom() copies the already
40 // trained layers from another net parameter instance.
41 void CopyTrainedLayersFrom(const NetParameter& param);
42 // Writes the net to a proto.
43 void ToProto(NetParameter* param, bool write_diff = false);
45 // returns the network name.
46 inline const string& name() { return name_; }
47 // returns the layer names
48 inline const vector<string>& layer_names() { return layer_names_; }
49 // returns the blob names
50 inline const vector<string>& blob_names() { return blob_names_; }
52 inline const vector<shared_ptr<Blob<Dtype> > >& blobs() { return blobs_; }
54 inline const vector<shared_ptr<Layer<Dtype> > >& layers() { return layers_; }
55 // returns the bottom and top vecs for each layer - usually you won't need
56 // this unless you do per-layer checks such as gradients.
57 inline vector<vector<Blob<Dtype>*> >& bottom_vecs() { return bottom_vecs_; }
58 inline vector<vector<Blob<Dtype>*> >& top_vecs() { return top_vecs_; }
59 // returns the parameters
60 inline vector<shared_ptr<Blob<Dtype> > >& params() { return params_; }
61 // returns the parameter learning rate multipliers
62 inline vector<float>& params_lr() {return params_lr_; }
63 // Updates the network
67 // Individual layers in the net
68 vector<shared_ptr<Layer<Dtype> > > layers_;
69 vector<string> layer_names_;
70 // blobs stores the blobs that store intermediate results between the
72 vector<shared_ptr<Blob<Dtype> > > blobs_;
73 vector<string> blob_names_;
74 // bottom_vecs stores the vectors containing the input for each layer
75 vector<vector<Blob<Dtype>*> > bottom_vecs_;
76 vector<vector<int> > bottom_id_vecs_;
77 // top_vecs stores the vectors containing the output for each layer
78 vector<vector<Blob<Dtype>*> > top_vecs_;
79 vector<vector<int> > top_id_vecs_;
80 // blob indices for the input and the output of the net.
81 vector<int> net_input_blob_indices_;
82 vector<int> net_output_blob_indices_;
83 vector<Blob<Dtype>*> net_output_blobs_;
85 // The parameters in the network.
86 vector<shared_ptr<Blob<Dtype> > > params_;
87 // the learning rate multipliers
88 vector<float> params_lr_;
89 DISABLE_COPY_AND_ASSIGN(Net);
95 #endif // CAFFE_NET_HPP_