compact net parameter upgrade
authorEvan Shelhamer <shelhamer@imaginarynumber.net>
Fri, 22 Aug 2014 02:02:41 +0000 (19:02 -0700)
committerEvan Shelhamer <shelhamer@imaginarynumber.net>
Fri, 22 Aug 2014 05:20:21 +0000 (22:20 -0700)
include/caffe/util/upgrade_proto.hpp
src/caffe/util/upgrade_proto.cpp

index 1ee184a..3b10624 100644 (file)
@@ -34,6 +34,9 @@ LayerParameter_LayerType UpgradeV0LayerType(const string& type);
 void NetParameterToPrettyPrint(const NetParameter& param,
                                NetParameterPrettyPrint* pretty_param);
 
+// Check for deprecations and upgrade the NetParameter as needed.
+void UpgradeNetAsNeeded(NetParameter* param);
+
 // Read parameters from a file into a NetParameter proto message.
 void ReadNetParamsFromTextFileOrDie(const string& param_file,
                                     NetParameter* param);
index 21fc038..c9c57a2 100644 (file)
@@ -567,10 +567,7 @@ void NetParameterToPrettyPrint(const NetParameter& param,
   }
 }
 
-void ReadNetParamsFromTextFileOrDie(const string& param_file,
-                                    NetParameter* param) {
-  CHECK(ReadProtoFromTextFile(param_file, param))
-      << "Failed to parse NetParameter file: " << param_file;
+void UpgradeNetAsNeeded(const string& param_file, NetParameter* param) {
   if (NetNeedsUpgrade(*param)) {
     // NetParameter was specified using the old style (V0LayerParameter); try to
     // upgrade it.
@@ -585,32 +582,24 @@ void ReadNetParamsFromTextFileOrDie(const string& param_file,
                 << "V0LayerParameter";
     }
     LOG(ERROR) << "Note that future Caffe releases will not support "
-        << "V0NetParameter; use ./build/tools/upgrade_net_proto_text.bin to "
-        << "upgrade this and any other network proto files to the new format.";
+        << "V0NetParameter; use ./build/tools/upgrade_net_proto_text for "
+        << "prototxt and ./build/tools/upgrade_net_proto_binary for model "
+        << "weights upgrade this and any other net protos to the new format.";
   }
 }
 
+void ReadNetParamsFromTextFileOrDie(const string& param_file,
+                                    NetParameter* param) {
+  CHECK(ReadProtoFromTextFile(param_file, param))
+      << "Failed to parse NetParameter file: " << param_file;
+  UpgradeNetAsNeeded(param_file, param);
+}
+
 void ReadNetParamsFromBinaryFileOrDie(const string& param_file,
                                       NetParameter* param) {
   CHECK(ReadProtoFromBinaryFile(param_file, param))
       << "Failed to parse NetParameter file: " << param_file;
-  if (NetNeedsUpgrade(*param)) {
-    // NetParameter was specified using the old style (V0LayerParameter); try to
-    // upgrade it.
-    LOG(ERROR) << "Attempting to upgrade input file specified using deprecated "
-               << "V0LayerParameter: " << param_file;
-    NetParameter original_param(*param);
-    if (!UpgradeV0Net(original_param, param)) {
-      LOG(ERROR) << "Warning: had one or more problems upgrading "
-          << "V0NetParameter to NetParameter (see above); continuing anyway.";
-    } else {
-      LOG(INFO) << "Successfully upgraded file specified using deprecated "
-                << "V0LayerParameter";
-    }
-    LOG(ERROR) << "Note that future Caffe releases will not support "
-        << "V0NetParameter; use ./build/tools/upgrade_net_proto_binary.bin to "
-        << "upgrade this and any other network proto files to the new format.";
-  }
+  UpgradeNetAsNeeded(param_file, param);
 }
 
 }  // namespace caffe