| 22 | */ |
| 23 | template <typename Dtype> |
| 24 | class Net { |
| 25 | public: |
| 26 | explicit Net(const NetParameter& param, const Net* root_net = NULL); |
| 27 | explicit Net(const string& param_file, Phase phase, |
| 28 | const int level = 0, const vector<string>* stages = NULL, |
| 29 | const Net* root_net = NULL); |
| 30 | virtual ~Net() {} |
| 31 | |
| 32 | /// @brief Initialize a network with a NetParameter. |
| 33 | void Init(const NetParameter& param); |
| 34 | |
| 35 | /** |
| 36 | * @brief Run Forward and return the result. |
| 37 | * |
| 38 | */ |
| 39 | const vector<Blob<Dtype>*>& Forward(Dtype* loss = NULL); |
| 40 | /// @brief DEPRECATED; use Forward() instead. |
| 41 | const vector<Blob<Dtype>*>& ForwardPrefilled(Dtype* loss = NULL) { |
| 42 | LOG_EVERY_N(WARNING, 1000) << "DEPRECATED: ForwardPrefilled() " |
| 43 | << "will be removed in a future version. Use Forward()."; |
| 44 | return Forward(loss); |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * The From and To variants of Forward and Backward operate on the |
| 49 | * (topological) ordering by which the net is specified. For general DAG |
| 50 | * networks, note that (1) computing from one layer to another might entail |
| 51 | * extra computation on unrelated branches, and (2) computation starting in |
| 52 | * the middle may be incorrect if all of the layers of a fan-in are not |
| 53 | * included. |
| 54 | */ |
| 55 | Dtype ForwardFromTo(int start, int end); |
| 56 | Dtype ForwardFrom(int start); |
| 57 | Dtype ForwardTo(int end); |
| 58 | /// @brief DEPRECATED; set input blobs then use Forward() instead. |
| 59 | const vector<Blob<Dtype>*>& Forward(const vector<Blob<Dtype>* > & bottom, |
| 60 | Dtype* loss = NULL); |
| 61 | |
| 62 | /** |
| 63 | * @brief Zeroes out the diffs of all net parameters. |
| 64 | * Should be run before Backward. |
| 65 | */ |
| 66 | void ClearParamDiffs(); |
| 67 | |
| 68 | /** |
| 69 | * The network backward should take no input and output, since it solely |
| 70 | * computes the gradient w.r.t the parameters, and the data has already been |
| 71 | * provided during the forward pass. |
| 72 | */ |
| 73 | void Backward(); |
| 74 | void BackwardFromTo(int start, int end); |
| 75 | void BackwardFrom(int start); |
| 76 | void BackwardTo(int end); |
| 77 | |
| 78 | /** |
| 79 | * @brief Reshape all layers from bottom to top. |
| 80 | * |
| 81 | * This is useful to propagate changes to layer sizes without running |