MCPcopy Create free account
hub / github.com/BVLC/caffe / Init

Method Init

src/caffe/net.cpp:44–256  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

42
43template <typename Dtype>
44void Net<Dtype>::Init(const NetParameter& in_param) {
45 // Set phase from the state.
46 phase_ = in_param.state().phase();
47 // Filter layers based on their include/exclude rules and
48 // the current NetState.
49 NetParameter filtered_param;
50 FilterNet(in_param, &filtered_param);
51 LOG_IF(INFO, Caffe::root_solver())
52 << "Initializing net from parameters: " << std::endl
53 << filtered_param.DebugString();
54 // Create a copy of filtered_param with splits added where necessary.
55 NetParameter param;
56 InsertSplits(filtered_param, &param);
57 // Basically, build all the layers and set up their connections.
58 name_ = param.name();
59 map<string, int> blob_name_to_idx;
60 set<string> available_blobs;
61 memory_used_ = 0;
62 // For each layer, set up its input and output
63 bottom_vecs_.resize(param.layer_size());
64 top_vecs_.resize(param.layer_size());
65 bottom_id_vecs_.resize(param.layer_size());
66 param_id_vecs_.resize(param.layer_size());
67 top_id_vecs_.resize(param.layer_size());
68 bottom_need_backward_.resize(param.layer_size());
69 for (int layer_id = 0; layer_id < param.layer_size(); ++layer_id) {
70 // Inherit phase from net if unset.
71 if (!param.layer(layer_id).has_phase()) {
72 param.mutable_layer(layer_id)->set_phase(phase_);
73 }
74 // Setup layer.
75 const LayerParameter& layer_param = param.layer(layer_id);
76 if (layer_param.propagate_down_size() > 0) {
77 CHECK_EQ(layer_param.propagate_down_size(),
78 layer_param.bottom_size())
79 << "propagate_down param must be specified "
80 << "either 0 or bottom_size times ";
81 }
82 layers_.push_back(LayerRegistry<Dtype>::CreateLayer(layer_param));
83 layer_names_.push_back(layer_param.name());
84 LOG_IF(INFO, Caffe::root_solver())
85 << "Creating Layer " << layer_param.name();
86 bool need_backward = false;
87
88 // Figure out this layer's input and output
89 for (int bottom_id = 0; bottom_id < layer_param.bottom_size();
90 ++bottom_id) {
91 const int blob_id = AppendBottom(param, layer_id, bottom_id,
92 &available_blobs, &blob_name_to_idx);
93 // If a blob needs backward, this layer should provide it.
94 need_backward |= blob_need_backward_[blob_id];
95 }
96 int num_top = layer_param.top_size();
97 for (int top_id = 0; top_id < num_top; ++top_id) {
98 AppendTop(param, layer_id, top_id, &available_blobs, &blob_name_to_idx);
99 // Collect Input layer tops as Net inputs.
100 if (layer_param.type() == "Input") {
101 const int blob_id = blobs_.size() - 1;

Callers

nothing calls this directly

Calls 15

InsertSplitsFunction · 0.85
phaseMethod · 0.80
lossMethod · 0.80
shape_stringMethod · 0.80
countMethod · 0.80
typeMethod · 0.45
sizeMethod · 0.45
getMethod · 0.45
AutoTopBlobsMethod · 0.45
MinTopBlobsMethod · 0.45
ExactNumTopBlobsMethod · 0.45

Tested by

no test coverage detected