@@ -56,22 +56,7 @@ void Net<Dtype>::Init(const NetParameter& in_param) {
5656 name_ = param.name ();
5757 map<string, int > blob_name_to_idx;
5858 set<string> available_blobs;
59- CHECK (param.input_dim_size () == 0 || param.input_shape_size () == 0 )
60- << " Must specify either input_shape OR deprecated input_dim, not both." ;
61- if (param.input_dim_size () > 0 ) {
62- // Deprecated 4D dimensions.
63- CHECK_EQ (param.input_size () * 4 , param.input_dim_size ())
64- << " Incorrect input blob dimension specifications." ;
65- } else {
66- CHECK_EQ (param.input_size (), param.input_shape_size ())
67- << " Exactly one input_shape must be specified per input." ;
68- }
6959 memory_used_ = 0 ;
70- // set the input blobs
71- for (int input_id = 0 ; input_id < param.input_size (); ++input_id) {
72- const int layer_id = -1 ; // inputs have fake layer ID -1
73- AppendTop (param, layer_id, input_id, &available_blobs, &blob_name_to_idx);
74- }
7560 // For each layer, set up its input and output
7661 bottom_vecs_.resize (param.layer_size ());
7762 top_vecs_.resize (param.layer_size ());
@@ -379,19 +364,17 @@ bool Net<Dtype>::StateMeetsRule(const NetState& state,
379364 return true ;
380365}
381366
382- // Helper for Net::Init: add a new input or top blob to the net. (Inputs have
383- // layer_id == -1, tops have layer_id >= 0.)
367+ // Helper for Net::Init: add a new top blob to the net.
384368template <typename Dtype>
385369void Net<Dtype>::AppendTop(const NetParameter& param, const int layer_id,
386370 const int top_id, set<string>* available_blobs,
387371 map<string, int >* blob_name_to_idx) {
388- shared_ptr<LayerParameter> layer_param ((layer_id >= 0 ) ?
389- (new LayerParameter (param.layer (layer_id))) : NULL );
390- const string& blob_name = layer_param ?
391- (layer_param->top_size () > top_id ?
392- layer_param->top (top_id) : " (automatic)" ) : param.input (top_id);
372+ shared_ptr<LayerParameter> layer_param (
373+ new LayerParameter (param.layer (layer_id)));
374+ const string& blob_name = (layer_param->top_size () > top_id) ?
375+ layer_param->top (top_id) : " (automatic)" ;
393376 // Check if we are doing in-place computation
394- if (blob_name_to_idx && layer_param && layer_param ->bottom_size () > top_id &&
377+ if (blob_name_to_idx && layer_param->bottom_size () > top_id &&
395378 blob_name == layer_param->bottom (top_id)) {
396379 // In-place computation
397380 LOG_IF (INFO, Caffe::root_solver ())
@@ -407,34 +390,16 @@ void Net<Dtype>::AppendTop(const NetParameter& param, const int layer_id,
407390 } else {
408391 // Normal output.
409392 if (Caffe::root_solver ()) {
410- if (layer_param) {
411- LOG (INFO) << layer_param->name () << " -> " << blob_name;
412- } else {
413- LOG (INFO) << " Input " << top_id << " -> " << blob_name;
414- }
393+ LOG (INFO) << layer_param->name () << " -> " << blob_name;
415394 }
416395 shared_ptr<Blob<Dtype> > blob_pointer (new Blob<Dtype>());
417396 const int blob_id = blobs_.size ();
418397 blobs_.push_back (blob_pointer);
419398 blob_names_.push_back (blob_name);
420399 blob_need_backward_.push_back (false );
421400 if (blob_name_to_idx) { (*blob_name_to_idx)[blob_name] = blob_id; }
422- if (layer_id == -1 ) {
423- // Set the (explicitly specified) dimensions of the input blob.
424- if (param.input_dim_size () > 0 ) {
425- blob_pointer->Reshape (param.input_dim (top_id * 4 ),
426- param.input_dim (top_id * 4 + 1 ),
427- param.input_dim (top_id * 4 + 2 ),
428- param.input_dim (top_id * 4 + 3 ));
429- } else {
430- blob_pointer->Reshape (param.input_shape (top_id));
431- }
432- net_input_blob_indices_.push_back (blob_id);
433- net_input_blobs_.push_back (blob_pointer.get ());
434- } else {
435- top_id_vecs_[layer_id].push_back (blob_id);
436- top_vecs_[layer_id].push_back (blob_pointer.get ());
437- }
401+ top_id_vecs_[layer_id].push_back (blob_id);
402+ top_vecs_[layer_id].push_back (blob_pointer.get ());
438403 }
439404 if (available_blobs) { available_blobs->insert (blob_name); }
440405}
@@ -566,11 +531,6 @@ Dtype Net<Dtype>::ForwardFromTo(int start, int end) {
566531 CHECK_GE (start, 0 );
567532 CHECK_LT (end, layers_.size ());
568533 Dtype loss = 0 ;
569- if (debug_info_) {
570- for (int i = 0 ; i < net_input_blobs_.size (); ++i) {
571- InputDebugInfo (i);
572- }
573- }
574534 for (int i = start; i <= end; ++i) {
575535 // LOG(ERROR) << "Forwarding " << layer_names_[i];
576536 Dtype layer_loss = layers_[i]->Forward (bottom_vecs_[i], top_vecs_[i]);
@@ -591,7 +551,7 @@ Dtype Net<Dtype>::ForwardTo(int end) {
591551}
592552
593553template <typename Dtype>
594- const vector<Blob<Dtype>*>& Net<Dtype>::ForwardPrefilled (Dtype* loss) {
554+ const vector<Blob<Dtype>*>& Net<Dtype>::Forward (Dtype* loss) {
595555 if (loss != NULL ) {
596556 *loss = ForwardFromTo (0 , layers_.size () - 1 );
597557 } else {
@@ -600,37 +560,6 @@ const vector<Blob<Dtype>*>& Net<Dtype>::ForwardPrefilled(Dtype* loss) {
600560 return net_output_blobs_;
601561}
602562
603- template <typename Dtype>
604- const vector<Blob<Dtype>*>& Net<Dtype>::Forward(
605- const vector<Blob<Dtype>*> & bottom, Dtype* loss) {
606- // Copy bottom to internal bottom
607- for (int i = 0 ; i < bottom.size (); ++i) {
608- net_input_blobs_[i]->CopyFrom (*bottom[i]);
609- }
610- return ForwardPrefilled (loss);
611- }
612-
613- template <typename Dtype>
614- string Net<Dtype>::Forward(const string& input_blob_protos, Dtype* loss) {
615- BlobProtoVector blob_proto_vec;
616- if (net_input_blobs_.size ()) {
617- blob_proto_vec.ParseFromString (input_blob_protos);
618- CHECK_EQ (blob_proto_vec.blobs_size (), net_input_blobs_.size ())
619- << " Incorrect input size." ;
620- for (int i = 0 ; i < blob_proto_vec.blobs_size (); ++i) {
621- net_input_blobs_[i]->FromProto (blob_proto_vec.blobs (i));
622- }
623- }
624- ForwardPrefilled (loss);
625- blob_proto_vec.Clear ();
626- for (int i = 0 ; i < net_output_blobs_.size (); ++i) {
627- net_output_blobs_[i]->ToProto (blob_proto_vec.add_blobs ());
628- }
629- string output;
630- blob_proto_vec.SerializeToString (&output);
631- return output;
632- }
633-
634563template <typename Dtype>
635564void Net<Dtype>::BackwardFromTo(int start, int end) {
636565 CHECK_GE (end, 0 );
@@ -644,16 +573,6 @@ void Net<Dtype>::BackwardFromTo(int start, int end) {
644573 }
645574}
646575
647- template <typename Dtype>
648- void Net<Dtype>::InputDebugInfo(const int input_id) {
649- const Blob<Dtype>& blob = *net_input_blobs_[input_id];
650- const string& blob_name = blob_names_[net_input_blob_indices_[input_id]];
651- const Dtype data_abs_val_mean = blob.asum_data () / blob.count ();
652- LOG_IF (INFO, Caffe::root_solver ())
653- << " [Forward] "
654- << " Input " << blob_name << " data: " << data_abs_val_mean;
655- }
656-
657576template <typename Dtype>
658577void Net<Dtype>::ForwardDebugInfo(const int layer_id) {
659578 for (int top_id = 0 ; top_id < top_vecs_[layer_id].size (); ++top_id) {
@@ -912,9 +831,6 @@ void Net<Dtype>::ToProto(NetParameter* param, bool write_diff) const {
912831 param->Clear ();
913832 param->set_name (name_);
914833 // Add bottom and top
915- for (int i = 0 ; i < net_input_blob_indices_.size (); ++i) {
916- param->add_input (blob_names_[net_input_blob_indices_[i]]);
917- }
918834 DLOG (INFO) << " Serializing " << layers_.size () << " layers" ;
919835 for (int i = 0 ; i < layers_.size (); ++i) {
920836 LayerParameter* layer_param = param->add_layer ();
0 commit comments