bugfix regarding #100
authorYangqing Jia <jiayq84@gmail.com>
Thu, 13 Feb 2014 05:52:33 +0000 (21:52 -0800)
committerYangqing Jia <jiayq84@gmail.com>
Thu, 13 Feb 2014 05:52:33 +0000 (21:52 -0800)
src/caffe/net.cpp

index 351a7b9..f265cd3 100644 (file)
@@ -117,14 +117,18 @@ void Net<Dtype>::Init(const NetParameter& param) {
           << top_vecs_[i][topid]->height() << " "
           << top_vecs_[i][topid]->width();
     }
-    // catch: if a layer param does not specify blobs_lr, we should assume the
-    // learning rate to be 1. Thus we will need to perform backward.
-    if (layers_[i]->layer_param().blobs_lr_size()) {
+    int blobs_lr_size = layers_[i]->layer_param().blobs_lr_size();
+    CHECK(blobs_lr_size == layers_[i]->blobs().size() || blobs_lr_size == 0)
+        << "Incorrect blobs lr size: should be either 0 or the same as "
+           "the number of the layer's parameter blobs.";
+    if (blobs_lr_size) {
       // Check if this layer needs backward operation itself
-      for (int j = 0; j < layers_[i]->layer_param().blobs_lr_size(); ++j) {
+      for (int j = 0; j < blobs_lr_size; ++j) {
         need_backward |= (layers_[i]->layer_param().blobs_lr(j) > 0);
       }
-    } else {
+    } else if (layers_[i]->blobs().size()) {
+      // catch: if a layer param does not specify blobs_lr, we should assume the
+      // learning rate to be 1. Thus we will need to perform backward.
       need_backward = true;
     }
     // Finally, set the backward flag