diff options
author | Evan Shelhamer <shelhamer@imaginarynumber.net> | 2015-08-25 19:05:57 -0300 |
---|---|---|
committer | Evan Shelhamer <shelhamer@imaginarynumber.net> | 2015-08-25 19:05:57 -0300 |
commit | 4092b700207e8946729d97a666e196944d4dec1e (patch) | |
tree | 81f238cd8ee53f2b417d7fc2a6b10ab091413b28 | |
parent | c54f2c4df141a69eed625de9893738b977a39fbb (diff) | |
parent | 7f4ffcd7c4d3896fd2a40cc4dd153ba04b1ba968 (diff) | |
download | caffeonacl-4092b700207e8946729d97a666e196944d4dec1e.tar.gz caffeonacl-4092b700207e8946729d97a666e196944d4dec1e.tar.bz2 caffeonacl-4092b700207e8946729d97a666e196944d4dec1e.zip |
Merge pull request #2927 from jeffdonahue/improve-net-init-error-msgs
improve net config and shape mismatch error messages
-rw-r--r-- | src/caffe/net.cpp | 37 | ||||
-rw-r--r-- | src/caffe/util/insert_splits.cpp | 3 |
2 files changed, 33 insertions, 7 deletions
diff --git a/src/caffe/net.cpp b/src/caffe/net.cpp index 7444b5bb..f1fc63ab 100644 --- a/src/caffe/net.cpp +++ b/src/caffe/net.cpp @@ -424,7 +424,8 @@ void Net<Dtype>::AppendTop(const NetParameter& param, const int layer_id, blob_name_to_idx->find(blob_name) != blob_name_to_idx->end()) { // If we are not doing in-place computation but have duplicated blobs, // raise an error. - LOG(FATAL) << "Duplicate blobs produced by multiple sources."; + LOG(FATAL) << "Top blob '" << blob_name + << "' produced by multiple sources."; } else { // Normal output. if (Caffe::root_solver()) { @@ -468,8 +469,8 @@ int Net<Dtype>::AppendBottom(const NetParameter& param, const int layer_id, const LayerParameter& layer_param = param.layer(layer_id); const string& blob_name = layer_param.bottom(bottom_id); if (available_blobs->find(blob_name) == available_blobs->end()) { - LOG(FATAL) << "Unknown blob input " << blob_name - << " (at index " << bottom_id << ") to layer " << layer_id; + LOG(FATAL) << "Unknown bottom blob '" << blob_name << "' (layer '" + << layer_param.name() << "', bottom index " << bottom_id << ")"; } const int blob_id = (*blob_name_to_idx)[blob_name]; if (Caffe::root_solver()) { @@ -545,10 +546,19 @@ void Net<Dtype>::AppendParam(const NetParameter& param, const int layer_id, ParamSpec_DimCheckMode_PERMISSIVE)) { // Permissive dimension checking -- only check counts are the same. CHECK_EQ(this_blob->count(), owner_blob->count()) - << "Shared parameter blobs must have the same count."; + << "Cannot share param '" << param_name << "' owned by layer '" + << layer_names_[owner_layer_id] << "' with layer '" + << layer_names_[layer_id] << "'; count mismatch. Owner layer param " + << "shape is " << owner_blob->shape_string() << "; sharing layer " + << "shape is " << this_blob->shape_string(); } else { // Strict dimension checking -- all dims must be the same. - CHECK(this_blob->shape() == owner_blob->shape()); + CHECK(this_blob->shape() == owner_blob->shape()) + << "Cannot share param '" << param_name << "' owned by layer '" + << layer_names_[owner_layer_id] << "' with layer '" + << layer_names_[layer_id] << "'; shape mismatch. Owner layer param " + << "shape is " << owner_blob->shape_string() << "; sharing layer " + << "expects shape " << this_blob->shape_string(); } const int learnable_param_id = learnable_param_ids_[owner_net_param_id]; learnable_param_ids_.push_back(learnable_param_id); @@ -775,7 +785,11 @@ void Net<Dtype>::ShareTrainedLayersWith(const Net* other) { << "Incompatible number of blobs for layer " << source_layer_name; for (int j = 0; j < target_blobs.size(); ++j) { Blob<Dtype>* source_blob = source_layer->blobs()[j].get(); - CHECK(target_blobs[j]->shape() == source_blob->shape()); + CHECK(target_blobs[j]->shape() == source_blob->shape()) + << "Cannot share param " << j << " weights from layer '" + << source_layer_name << "'; shape mismatch. Source param shape is " + << source_blob->shape_string() << "; target param shape is " + << target_blobs[j]->shape_string(); target_blobs[j]->ShareData(*source_blob); } } @@ -839,6 +853,17 @@ void Net<Dtype>::CopyTrainedLayersFrom(const NetParameter& param) { CHECK_EQ(target_blobs.size(), source_layer.blobs_size()) << "Incompatible number of blobs for layer " << source_layer_name; for (int j = 0; j < target_blobs.size(); ++j) { + if (!target_blobs[j]->ShapeEquals(source_layer.blobs(j))) { + Blob<Dtype> source_blob; + const bool kReshape = true; + source_blob.FromProto(source_layer.blobs(j), kReshape); + LOG(FATAL) << "Cannot copy param " << j << " weights from layer '" + << source_layer_name << "'; shape mismatch. Source param shape is " + << source_blob.shape_string() << "; target param shape is " + << target_blobs[j]->shape_string() << ". " + << "To learn this layer's parameters from scratch rather than " + << "copying from a saved net, rename the layer."; + } const bool kReshape = false; target_blobs[j]->FromProto(source_layer.blobs(j), kReshape); } diff --git a/src/caffe/util/insert_splits.cpp b/src/caffe/util/insert_splits.cpp index 416f80ab..475a2a9f 100644 --- a/src/caffe/util/insert_splits.cpp +++ b/src/caffe/util/insert_splits.cpp @@ -32,7 +32,8 @@ void InsertSplits(const NetParameter& param, NetParameter* param_split) { const string& blob_name = layer_param.bottom(j); if (blob_name_to_last_top_idx.find(blob_name) == blob_name_to_last_top_idx.end()) { - LOG(FATAL) << "Unknown blob input " << blob_name << " to layer " << j; + LOG(FATAL) << "Unknown bottom blob '" << blob_name << "' (layer '" + << layer_param.name() << "', bottom index " << j << ")"; } const pair<int, int>& bottom_idx = make_pair(i, j); const pair<int, int>& top_idx = blob_name_to_last_top_idx[blob_name]; |