aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManu Mathew2018-06-11 04:51:03 -0500
committerManu Mathew2018-07-05 03:29:18 -0500
commit2149e60dffa6095b7534e4228cb41c4e340c3b45 (patch)
treea95f9d0a738507bdf1de3879a96f016e38125e86
parent34bd7023f4e50cecc5c23e98e97cd8249ce14781 (diff)
downloadcaffe-jacinto-2149e60dffa6095b7534e4228cb41c4e340c3b45.tar.gz
caffe-jacinto-2149e60dffa6095b7534e4228cb41c4e340c3b45.tar.xz
caffe-jacinto-2149e60dffa6095b7534e4228cb41c4e340c3b45.zip
Issue 512 - Difference with BVLC caffe
-rw-r--r--src/caffe/net.cpp15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/caffe/net.cpp b/src/caffe/net.cpp
index a51715e7..a4bab339 100644
--- a/src/caffe/net.cpp
+++ b/src/caffe/net.cpp
@@ -1154,13 +1154,13 @@ void Net::CopyTrainedLayersFrom(const NetParameter& param) {
1154 << source_layer_type << " #blobs=" << source_layer.blobs_size(); 1154 << source_layer_type << " #blobs=" << source_layer.blobs_size();
1155 int num_blobs_to_copy = std::min<int>(target_blobs.size(), source_layer.blobs_size()); 1155 int num_blobs_to_copy = std::min<int>(target_blobs.size(), source_layer.blobs_size());
1156 // check if BN is in legacy DIGITS format? 1156 // check if BN is in legacy DIGITS format?
1157 if (source_layer_type == "BatchNorm" && source_layer.blobs_size() == 5) { 1157 if (source_layer_type == "BatchNorm") {
1158 for (int j = 0; j < num_blobs_to_copy; ++j) { 1158 for (int j = 0; j < num_blobs_to_copy; ++j) {
1159 const bool kReshape = true; 1159 const bool kReshape = true;
1160 target_blobs[j]->FromProto(source_layer.blobs(j), kReshape); 1160 target_blobs[j]->FromProto(source_layer.blobs(j), kReshape);
1161 DLOG(INFO) << target_blobs[j]->count(); 1161 DLOG(INFO) << target_blobs[j]->count();
1162 } 1162 }
1163 if (target_blobs[4]->count() == 1) { 1163 if (source_layer.blobs_size() == 5 && target_blobs[4]->count() == 1) {
1164 // old format: 0 - scale , 1 - bias, 2 - mean , 3 - var, 4 - reserved 1164 // old format: 0 - scale , 1 - bias, 2 - mean , 3 - var, 4 - reserved
1165 // new format: 0 - mean , 1 - var, 2 - reserved , 3- scale, 4 - bias 1165 // new format: 0 - mean , 1 - var, 2 - reserved , 3- scale, 4 - bias
1166 LOG(INFO) << "BN legacy DIGITS format detected ... "; 1166 LOG(INFO) << "BN legacy DIGITS format detected ... ";
@@ -1171,6 +1171,17 @@ void Net::CopyTrainedLayersFrom(const NetParameter& param) {
1171 std::swap(target_blobs[3], target_blobs[4]); 1171 std::swap(target_blobs[3], target_blobs[4]);
1172 LOG(INFO) << "BN Transforming to new format completed."; 1172 LOG(INFO) << "BN Transforming to new format completed.";
1173 } 1173 }
1174 if (source_layer.blobs_size() == 3) {
1175 const float scale_factor = target_blobs[2]->cpu_data<float>()[0] == 0.F ?
1176 0.F : 1.F / target_blobs[2]->cpu_data<float>()[0];
1177 caffe_cpu_scale(target_blobs[0]->count(), scale_factor,
1178 target_blobs[0]->cpu_data<float>(),
1179 target_blobs[0]->mutable_cpu_data<float>());
1180 caffe_cpu_scale(target_blobs[1]->count(), scale_factor,
1181 target_blobs[1]->cpu_data<float>(),
1182 target_blobs[1]->mutable_cpu_data<float>());
1183 target_blobs[2]->mutable_cpu_data<float>()[0] = 1.F;
1184 }
1174 for (int j = 0; j < target_blobs.size(); ++j) { 1185 for (int j = 0; j < target_blobs.size(); ++j) {
1175 DLOG(INFO) << target_blobs[j]->count(); 1186 DLOG(INFO) << target_blobs[j]->count();
1176 } 1187 }