#include <string>
#include "caffe/proto/caffe.pb.h"
-#include "caffe/proto/caffe_pretty_print.pb.h"
namespace caffe {
const char* UpgradeV1LayerType(const V1LayerParameter_LayerType type);
-// Convert a NetParameter to NetParameterPrettyPrint used for dumping to
-// proto text files.
-void NetParameterToPrettyPrint(const NetParameter& param,
- NetParameterPrettyPrint* pretty_param);
-
// Check for deprecations and upgrade the NetParameter as needed.
bool UpgradeNetAsNeeded(const string& param_file, NetParameter* param);
+++ /dev/null
-syntax = "proto2";
-
-package caffe;
-
-import "caffe.proto";
-
-// A near-duplicate of NetParameter with fields re-numbered to beautify
-// automatic prototext dumps. The main practical purpose is to print inputs
-// before layers, because having inputs at the end looks weird.
-// NetParameterPrettyPrint should never be used in code except for conversion
-// FROM NetParameter and subsequent dumping to proto text file.
-message NetParameterPrettyPrint {
- optional string name = 1;
- optional bool force_backward = 2 [default = false];
- repeated string input = 3;
- repeated int32 input_dim = 4;
- repeated LayerParameter layer = 5;
-}
}
}
-void NetParameterToPrettyPrint(const NetParameter& param,
- NetParameterPrettyPrint* pretty_param) {
- pretty_param->Clear();
- if (param.has_name()) {
- pretty_param->set_name(param.name());
- }
- if (param.has_force_backward()) {
- pretty_param->set_force_backward(param.force_backward());
- }
- for (int i = 0; i < param.input_size(); ++i) {
- pretty_param->add_input(param.input(i));
- }
- for (int i = 0; i < param.input_dim_size(); ++i) {
- pretty_param->add_input_dim(param.input_dim(i));
- }
- for (int i = 0; i < param.layer_size(); ++i) {
- pretty_param->add_layer()->CopyFrom(param.layer(i));
- }
-}
-
bool UpgradeNetAsNeeded(const string& param_file, NetParameter* param) {
bool success = true;
if (NetNeedsV0ToV1Upgrade(*param)) {
UpgradeNetDataTransformation(&net_param);
}
- // Convert to a NetParameterPrettyPrint to print fields in desired
- // order.
- NetParameterPrettyPrint net_param_pretty;
- NetParameterToPrettyPrint(net_param, &net_param_pretty);
-
// Save new format prototxt.
- WriteProtoToTextFile(net_param_pretty, argv[2]);
+ WriteProtoToTextFile(net_param, argv[2]);
LOG(ERROR) << "Wrote upgraded NetParameter text proto to " << argv[2];
return !success;