<commit_before>// Copyright 2014 <NAME>
//
// This is a script to upgrade "V0" network prototxts to the new format.
// Usage:
//    upgrade_net_proto v0_net_proto_file_in net_proto_file_out

#include <cstring>
#include <iostream>  // NOLINT(readability/streams)
#include <fstream>  // NOLINT(readability/streams)

#include "caffe/caffe.hpp"
#include "caffe/util/io.hpp"
#include "caffe/util/upgrade_proto.hpp"

using std::ofstream;

using namespace caffe;  // NOLINT(build/namespaces)

int main(int argc, char** argv) {
  ::google::InitGoogleLogging(argv[0]);
  if (argc != 3) {
    LOG(ERROR) << "Usage: "
        << "upgrade_net_proto v0_net_proto_file_in net_proto_file_out";
    return 0;
  }

  V0NetParameter v0_net_param;
  CHECK(ReadProtoFromTextFile(argv[1], &v0_net_param))
      << "Failed to parse input V0NetParameter file: " << argv[1];
  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.";
  }
  // TODO(jdonahue): figure out why WriteProtoToTextFile doesn't work
  // (no file is created).
  // WriteProtoToTextFile(upgraded_net_param, argv[2]);
  ofstream output_proto;
  output_proto.open(argv[2]);
  output_proto << upgraded_net_param.DebugString();
  output_proto.close();
  LOG(ERROR) << "Wrote upgraded NetParameter proto to " << argv[2];
  return !success;
}<commit_msg>upgrade_net_proto: allow input files already in new proto format<commit_after>// Copyright 2014 <NAME>
//
// This is a script to upgrade "V0" network prototxts to the new format.
// Usage:
//    upgrade_net_proto v0_net_proto_file_in net_proto_file_out

#include <cstring>
#include <iostream>  // NOLINT(readability/streams)
#include <fstream>  // NOLINT(readability/streams)

#include "caffe/caffe.hpp"
#include "caffe/util/io.hpp"
#include "caffe/util/upgrade_proto.hpp"

using std::ofstream;

using namespace caffe;  // NOLINT(build/namespaces)

int main(int argc, char** argv) {
  ::google::InitGoogleLogging(argv[0]);
  if (argc != 3) {
    LOG(ERROR) << "Usage: "
        << "upgrade_net_proto v0_net_proto_file_in net_proto_file_out";
    return 0;
  }

  bool success = true;
  // First, check whether the input file is already in the new format.
  NetParameter upgraded_net_param;
  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).
  // WriteProtoToTextFile(upgraded_net_param, argv[2]);
  ofstream output_proto;
  output_proto.open(argv[2]);
  output_proto << upgraded_net_param.DebugString();
  output_proto.close();
  LOG(ERROR) << "Wrote upgraded NetParameter proto to " << argv[2];
  return !success;
}
{'fraction_non_alphanumeric': 0.1286024171056709, 'fraction_numerical': 0.013634955066625348, 'mean_word_length': 4.283142389525368, 'pattern_counts': {'":': 0, '<': 51, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3716096', 'n_tokens_mistral': 1148, 'n_tokens_neox': 1113, 'n_words': 266}