// Copyright 2013 Yangqing Jia #ifndef CAFFE_NET_HPP_ #define CAFFE_NET_HPP_ #include #include #include #include "caffe/blob.hpp" #include "caffe/common.hpp" #include "caffe/layer.hpp" #include "caffe/proto/caffe.pb.h" using std::map; using std::vector; using std::string; namespace caffe { template class Net { public: Net(const NetParameter& param, const vector* >& bottom); ~Net() {} const vector*>& Forward(const vector* > & bottom); // The network backward should take no input and output, since it solely // computes the gradient w.r.t the parameters, and the data has already // been provided during the forward pass. Dtype Backward(); Dtype ForwardBackward(const vector* > & bottom) { Forward(bottom); return Backward(); } // For an already initialized net, CopyTrainedLayersFrom() copies the already // trained layers from another net parameter instance. void CopyTrainedLayersFrom(const NetParameter& param); // Writes the net to a proto. void ToProto(NetParameter* param, bool write_diff = false); // returns the network name. inline const string& name() { return name_; } // returns the layer names inline const vector& layer_names() { return layer_names_; } // returns the blob names inline const vector& blob_names() { return blob_names_; } // returns the blobs inline const vector > >& blobs() { return blobs_; } // returns the layers inline const vector > >& layers() { return layers_; } // returns the bottom and top vecs for each layer - usually you won't need // this unless you do per-layer checks such as gradients. inline vector*> >& bottom_vecs() { return bottom_vecs_; } inline vector*> >& top_vecs() { return top_vecs_; } // returns the parameters inline vector > >& params() { return params_; } // returns the parameter learning rate multipliers inline vector& params_lr() {return params_lr_; } // Updates the network void Update(); protected: // Individual layers in the net vector > > layers_; vector layer_names_; // blobs stores the blobs that store intermediate results between the // layers. vector > > blobs_; vector blob_names_; // bottom_vecs stores the vectors containing the input for each layer vector*> > bottom_vecs_; vector > bottom_id_vecs_; // top_vecs stores the vectors containing the output for each layer vector*> > top_vecs_; vector > top_id_vecs_; // blob indices for the input and the output of the net. vector net_input_blob_indices_; vector net_output_blob_indices_; vector*> net_output_blobs_; string name_; // The parameters in the network. vector > > params_; // the learning rate multipliers vector params_lr_; DISABLE_COPY_AND_ASSIGN(Net); }; } // namespace caffe #endif // CAFFE_NET_HPP_