test case fix for Clip layer gradient
[platform/upstream/caffe.git] / tools / upgrade_net_proto_binary.cpp
1 // This is a script to upgrade "V0" network prototxts to the new format.
2 // Usage:
3 //    upgrade_net_proto_binary v0_net_proto_file_in net_proto_file_out
4
5 #include <cstring>
6 #include <fstream>  // NOLINT(readability/streams)
7 #include <iostream>  // NOLINT(readability/streams)
8 #include <string>
9
10 #include "caffe/caffe.hpp"
11 #include "caffe/util/io.hpp"
12 #include "caffe/util/upgrade_proto.hpp"
13
14 using std::ofstream;
15
16 using namespace caffe;  // NOLINT(build/namespaces)
17
18 int main(int argc, char** argv) {
19   FLAGS_alsologtostderr = 1;  // Print output to stderr (while still logging)
20   ::google::InitGoogleLogging(argv[0]);
21   if (argc != 3) {
22     LOG(ERROR) << "Usage: "
23         << "upgrade_net_proto_binary v0_net_proto_file_in net_proto_file_out";
24     return 1;
25   }
26
27   NetParameter net_param;
28   string input_filename(argv[1]);
29   if (!ReadProtoFromBinaryFile(input_filename, &net_param)) {
30     LOG(ERROR) << "Failed to parse input binary file as NetParameter: "
31                << input_filename;
32     return 2;
33   }
34   bool need_upgrade = NetNeedsUpgrade(net_param);
35   bool success = true;
36   if (need_upgrade) {
37     success = UpgradeNetAsNeeded(input_filename, &net_param);
38     if (!success) {
39       LOG(ERROR) << "Encountered error(s) while upgrading prototxt; "
40                  << "see details above.";
41     }
42   } else {
43     LOG(ERROR) << "File already in latest proto format: " << input_filename;
44   }
45
46   WriteProtoToBinaryFile(net_param, argv[2]);
47
48   LOG(INFO) << "Wrote upgraded NetParameter binary proto to " << argv[2];
49   return !success;
50 }