upgrade_net_proto: allow input files already in new proto format
authorJeff Donahue <jeff.donahue@gmail.com>
Fri, 21 Mar 2014 23:05:41 +0000 (16:05 -0700)
committerJeff Donahue <jeff.donahue@gmail.com>
Fri, 28 Mar 2014 06:42:28 +0000 (23:42 -0700)
tools/upgrade_net_proto.cpp

index a416878..49c27b5 100644 (file)
@@ -24,14 +24,20 @@ int main(int argc, char** argv) {
     return 0;
   }
 
-  V0NetParameter v0_net_param;
-  CHECK(ReadProtoFromTextFile(argv[1], &v0_net_param))
-      << "Failed to parse input V0NetParameter file: " << argv[1];
+  bool success = true;
+  // First, check whether the input file is already in the new format.
   NetParameter upgraded_net_param;
-  bool success = UpgradeV0Net(v0_net_param, &upgraded_net_param);
-  if (!success) {
-    LOG(ERROR) << "Encountered one or more problems upgrading net param "
-        << "proto; see above.";
+  if (ReadProtoFromTextFile(argv[1], &upgraded_net_param)) {
+    LOG(ERROR) << "File already in new proto format: " << argv[1];
+  } else {
+    V0NetParameter v0_net_param;
+    CHECK(ReadProtoFromTextFile(argv[1], &v0_net_param))
+        << "Failed to parse input V0NetParameter file: " << argv[1];
+    success = UpgradeV0Net(v0_net_param, &upgraded_net_param);
+    if (!success) {
+      LOG(ERROR) << "Encountered one or more problems upgrading net param "
+          << "proto; see above.";
+    }
   }
   // TODO(jdonahue): figure out why WriteProtoToTextFile doesn't work
   // (no file is created).