add deprecated protos to PROTO_OBJS in makefile so things compile; other
authorJeff Donahue <jeff.donahue@gmail.com>
Sat, 15 Mar 2014 11:04:18 +0000 (04:04 -0700)
committerJeff Donahue <jeff.donahue@gmail.com>
Fri, 28 Mar 2014 06:42:28 +0000 (23:42 -0700)
minor cleanup of includes etc

Makefile
include/caffe/util/upgrade_proto.hpp
src/caffe/net.cpp
src/caffe/util/upgrade_proto.cpp

index ecde1dc..b54e317 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -73,6 +73,7 @@ DEPRECATED_PROTO_GEN_PY := ${DEPRECATED_PROTO_SRCS:.proto=_pb2.py}
 CXX_OBJS := $(addprefix $(BUILD_DIR)/, ${CXX_SRCS:.cpp=.o})
 CU_OBJS := $(addprefix $(BUILD_DIR)/, ${CU_SRCS:.cu=.cuo})
 PROTO_OBJS := $(addprefix $(BUILD_DIR)/, ${PROTO_GEN_CC:.cc=.o})
+PROTO_OBJS += $(addprefix $(BUILD_DIR)/, ${DEPRECATED_PROTO_GEN_CC:.cc=.o})
 OBJS := $(PROTO_OBJS) $(CXX_OBJS) $(CU_OBJS)
 # tool, example, and test objects
 TOOL_OBJS := $(addprefix $(BUILD_DIR)/, ${TOOL_SRCS:.cpp=.o})
@@ -264,7 +265,6 @@ $(PROTO_GEN_CC): $(PROTO_SRCS) $(DEPRECATED_PROTO_SRCS)
 clean:
        @- $(RM) $(NAME) $(STATIC_NAME)
        @- $(RM) $(PROTO_GEN_HEADER) $(PROTO_GEN_CC) $(PROTO_GEN_PY)
-       @- $(RM) $(DEPRECATED_PROTO_GEN_HEADER) $(DEPRECATED_PROTO_GEN_CC)
        @- $(RM) include/$(PROJECT)/proto/$(PROJECT).pb.h
        @- $(RM) python/$(PROJECT)/proto/$(PROJECT)_pb2.py
        @- $(RM) python/$(PROJECT)/*.so
index ed9a829..35de736 100644 (file)
@@ -3,17 +3,9 @@
 #ifndef CAFFE_UTIL_UPGRADE_PROTO_H_
 #define CAFFE_UTIL_UPGRADE_PROTO_H_
 
-#include <string>
-
-#include "google/protobuf/message.h"
 #include "caffe/proto/caffe.pb.h"
 #include "caffe/proto/deprecated/caffe_v0_to_v1_bridge.pb.h"
 
-#include "boost/scoped_ptr.hpp"
-#include "caffe/blob.hpp"
-
-using std::string;
-
 namespace caffe {
 
 bool UpgradeV0Net(const V0NetParameter& v0_net_param, NetParameter* net_param);
index 7310a1a..a16afdc 100644 (file)
@@ -5,11 +5,14 @@
 #include <string>
 #include <vector>
 
+#include "caffe/common.hpp"
 #include "caffe/proto/caffe.pb.h"
+#include "caffe/proto/deprecated/caffe_v0_to_v1_bridge.pb.h"
 #include "caffe/layer.hpp"
 #include "caffe/net.hpp"
 #include "caffe/util/io.hpp"
 #include "caffe/util/insert_splits.hpp"
+#include "caffe/util/upgrade_proto.hpp"
 
 using std::pair;
 using std::map;
@@ -25,7 +28,21 @@ Net<Dtype>::Net(const NetParameter& param) {
 template <typename Dtype>
 Net<Dtype>::Net(const string& param_file) {
   NetParameter param;
-  ReadProtoFromTextFileOrDie(param_file, &param);
+  if (!ReadProtoFromTextFile(param_file, &param)) {
+    // Failed to parse file as NetParameter; try to parse as a V0NetParameter
+    // instead.
+    V0NetParameter v0_param;
+    CHECK(ReadProtoFromTextFile(param_file, &v0_param))
+        << "Failed to parse NetParameter file: " << param_file;
+    LOG(ERROR) << "Parsed file as V0NetParameter: " << param_file;
+    LOG(ERROR) << "Note that future Caffe releases will not support "
+        << "V0NetParameter; use tools/upgrade_net_param.testbin to upgrade "
+        << "this and any other network proto files to the new format.";
+    if (!UpgradeV0Net(v0_param, &param)) {
+      LOG(ERROR) << "Warning: had one or more problems upgrading "
+          << "V0NetParameter to NetParameter (see above); continuing anyway.";
+    }
+  }
   Init(param);
 }
 
index 4bd54dd..7f72135 100644 (file)
@@ -1,43 +1,43 @@
 // Copyright 2014 Jeff Donahue
 
-#include <stdint.h>
-#include <fcntl.h>
 #include <google/protobuf/text_format.h>
 #include <google/protobuf/io/zero_copy_stream_impl.h>
 #include <google/protobuf/io/coded_stream.h>
 
-#include <algorithm>
 #include <string>
-#include <fstream>  // NOLINT(readability/streams)
 
 #include "caffe/common.hpp"
 #include "caffe/util/upgrade_proto.hpp"
 #include "caffe/proto/caffe.pb.h"
 #include "caffe/proto/deprecated/caffe_v0_to_v1_bridge.pb.h"
 
-using std::fstream;
-using std::ios;
-using std::max;
 using std::string;
 
 namespace caffe {
 
 bool UpgradeV0Net(const V0NetParameter& v0_net_param,
                   NetParameter* net_param) {
-  bool full_compatibility = true;
+  bool is_fully_compatible = true;
   net_param->Clear();
   if (v0_net_param.has_name()) {
     net_param->set_name(v0_net_param.name());
   }
   for (int i = 0; i < v0_net_param.layers_size(); ++i) {
-    full_compatibility &= UpgradeV0LayerConnection(v0_net_param.layers(i),
+    is_fully_compatible &= UpgradeV0LayerConnection(v0_net_param.layers(i),
                                                     net_param->add_layers());
   }
+  for (int i = 0; i < v0_net_param.input_dim_size(); ++i) {
+    net_param->add_input_dim(v0_net_param.input_dim(i));
+  }
+  if (v0_net_param.has_force_backward()) {
+    net_param->set_force_backward(v0_net_param.force_backward());
+  }
+  return is_fully_compatible;
 }
 
 bool UpgradeV0LayerConnection(const V0LayerConnection& v0_layer_connection,
                               LayerParameter* layer_param) {
-  bool full_compatibility = true;
+  bool is_fully_compatible = true;
   layer_param->Clear();
   for (int i = 0; i < v0_layer_connection.bottom_size(); ++i) {
     layer_param->add_bottom(v0_layer_connection.bottom(i));
@@ -60,7 +60,7 @@ bool UpgradeV0LayerConnection(const V0LayerConnection& v0_layer_connection,
             v0_layer_param.num_output());
       } else {
         LOG(ERROR) << "Unknown parameter num_output for layer type " << type;
-        full_compatibility = false;
+        is_fully_compatible = false;
       }
     }
     if (v0_layer_param.has_biasterm()) {
@@ -72,7 +72,7 @@ bool UpgradeV0LayerConnection(const V0LayerConnection& v0_layer_connection,
             v0_layer_param.biasterm());
       } else {
         LOG(ERROR) << "Unknown parameter biasterm for layer type " << type;
-        full_compatibility = false;
+        is_fully_compatible = false;
       }
     }
     if (v0_layer_param.has_weight_filler()) {
@@ -84,7 +84,7 @@ bool UpgradeV0LayerConnection(const V0LayerConnection& v0_layer_connection,
             mutable_weight_filler()->CopyFrom(v0_layer_param.weight_filler());
       } else {
         LOG(ERROR) << "Unknown parameter weight_filler for layer type " << type;
-        full_compatibility = false;
+        is_fully_compatible = false;
       }
     }
     if (v0_layer_param.has_bias_filler()) {
@@ -96,7 +96,7 @@ bool UpgradeV0LayerConnection(const V0LayerConnection& v0_layer_connection,
             mutable_bias_filler()->CopyFrom(v0_layer_param.bias_filler());
       } else {
         LOG(ERROR) << "Unknown parameter bias_filler for layer type " << type;
-        full_compatibility = false;
+        is_fully_compatible = false;
       }
     }
     if (v0_layer_param.has_pad()) {
@@ -104,7 +104,7 @@ bool UpgradeV0LayerConnection(const V0LayerConnection& v0_layer_connection,
         layer_param->mutable_convolution_param()->set_pad(v0_layer_param.pad());
       } else {
         LOG(ERROR) << "Unknown parameter pad for layer type " << type;
-        full_compatibility = false;
+        is_fully_compatible = false;
       }
     }
     if (v0_layer_param.has_kernelsize()) {
@@ -116,7 +116,7 @@ bool UpgradeV0LayerConnection(const V0LayerConnection& v0_layer_connection,
             v0_layer_param.kernelsize());
       } else {
         LOG(ERROR) << "Unknown parameter kernelsize for layer type " << type;
-        full_compatibility = false;
+        is_fully_compatible = false;
       }
     }
     if (v0_layer_param.has_stride()) {
@@ -128,7 +128,7 @@ bool UpgradeV0LayerConnection(const V0LayerConnection& v0_layer_connection,
             v0_layer_param.stride());
       } else {
         LOG(ERROR) << "Unknown parameter stride for layer type " << type;
-        full_compatibility = false;
+        is_fully_compatible = false;
       }
     }
     if (v0_layer_param.has_pool()) {
@@ -149,11 +149,11 @@ bool UpgradeV0LayerConnection(const V0LayerConnection& v0_layer_connection,
           break;
         default:
           LOG(ERROR) << "Unknown pool method " << pool;
-          full_compatibility = false;
+          is_fully_compatible = false;
         }
       } else {
         LOG(ERROR) << "Unknown parameter pool for layer type " << type;
-        full_compatibility = false;
+        is_fully_compatible = false;
       }
     }
     if (v0_layer_param.has_dropout_ratio()) {
@@ -162,7 +162,7 @@ bool UpgradeV0LayerConnection(const V0LayerConnection& v0_layer_connection,
             v0_layer_param.dropout_ratio());
       } else {
         LOG(ERROR) << "Unknown parameter dropout_ratio for layer type " << type;
-        full_compatibility = false;
+        is_fully_compatible = false;
       }
     }
     if (v0_layer_param.has_local_size()) {
@@ -171,7 +171,7 @@ bool UpgradeV0LayerConnection(const V0LayerConnection& v0_layer_connection,
             v0_layer_param.local_size());
       } else {
         LOG(ERROR) << "Unknown parameter local_size for layer type " << type;
-        full_compatibility = false;
+        is_fully_compatible = false;
       }
     }
     if (v0_layer_param.has_alpha()) {
@@ -179,7 +179,7 @@ bool UpgradeV0LayerConnection(const V0LayerConnection& v0_layer_connection,
         layer_param->mutable_lrn_param()->set_alpha(v0_layer_param.alpha());
       } else {
         LOG(ERROR) << "Unknown parameter alpha for layer type " << type;
-        full_compatibility = false;
+        is_fully_compatible = false;
       }
     }
     if (v0_layer_param.has_beta()) {
@@ -187,7 +187,7 @@ bool UpgradeV0LayerConnection(const V0LayerConnection& v0_layer_connection,
         layer_param->mutable_lrn_param()->set_beta(v0_layer_param.beta());
       } else {
         LOG(ERROR) << "Unknown parameter beta for layer type " << type;
-        full_compatibility = false;
+        is_fully_compatible = false;
       }
     }
     if (v0_layer_param.has_source()) {
@@ -201,7 +201,7 @@ bool UpgradeV0LayerConnection(const V0LayerConnection& v0_layer_connection,
             v0_layer_param.source());
       } else {
         LOG(ERROR) << "Unknown parameter source for layer type " << type;
-        full_compatibility = false;
+        is_fully_compatible = false;
       }
     }
     if (v0_layer_param.has_scale()) {
@@ -209,7 +209,7 @@ bool UpgradeV0LayerConnection(const V0LayerConnection& v0_layer_connection,
         layer_param->mutable_data_param()->set_scale(v0_layer_param.scale());
       } else {
         LOG(ERROR) << "Unknown parameter scale for layer type " << type;
-        full_compatibility = false;
+        is_fully_compatible = false;
       }
     }
     if (v0_layer_param.has_meanfile()) {
@@ -217,7 +217,7 @@ bool UpgradeV0LayerConnection(const V0LayerConnection& v0_layer_connection,
         layer_param->mutable_data_param()->set_mean_file(v0_layer_param.meanfile());
       } else {
         LOG(ERROR) << "Unknown parameter meanfile for layer type " << type;
-        full_compatibility = false;
+        is_fully_compatible = false;
       }
     }
     if (v0_layer_param.has_batchsize()) {
@@ -226,7 +226,7 @@ bool UpgradeV0LayerConnection(const V0LayerConnection& v0_layer_connection,
             v0_layer_param.batchsize());
       } else {
         LOG(ERROR) << "Unknown parameter batchsize for layer type " << type;
-        full_compatibility = false;
+        is_fully_compatible = false;
       }
     }
     if (v0_layer_param.has_cropsize()) {
@@ -235,7 +235,7 @@ bool UpgradeV0LayerConnection(const V0LayerConnection& v0_layer_connection,
             v0_layer_param.cropsize());
       } else {
         LOG(ERROR) << "Unknown parameter cropsize for layer type " << type;
-        full_compatibility = false;
+        is_fully_compatible = false;
       }
     }
     if (v0_layer_param.has_mirror()) {
@@ -243,7 +243,7 @@ bool UpgradeV0LayerConnection(const V0LayerConnection& v0_layer_connection,
         layer_param->mutable_data_param()->set_mirror(v0_layer_param.mirror());
       } else {
         LOG(ERROR) << "Unknown parameter mirror for layer type " << type;
-        full_compatibility = false;
+        is_fully_compatible = false;
       }
     }
     for (int i = 0; i < v0_layer_param.blobs_size(); ++i) {
@@ -261,7 +261,7 @@ bool UpgradeV0LayerConnection(const V0LayerConnection& v0_layer_connection,
             v0_layer_param.rand_skip());
       } else {
         LOG(ERROR) << "Unknown parameter rand_skip for layer type " << type;
-        full_compatibility = false;
+        is_fully_compatible = false;
       }
     }
     if (v0_layer_param.has_concat_dim()) {
@@ -270,11 +270,11 @@ bool UpgradeV0LayerConnection(const V0LayerConnection& v0_layer_connection,
             v0_layer_param.concat_dim());
       } else {
         LOG(ERROR) << "Unknown parameter concat_dim for layer type " << type;
-        full_compatibility = false;
+        is_fully_compatible = false;
       }
     }
   }
-  return full_compatibility;
+  return is_fully_compatible;
 }
 
 }  // namespace caffe