chore: import upstream snapshot with attribution
cffconvert / validate (push) Has been skipped
License Check / license-check (push) Failing after 2s

This commit is contained in:
wehub-resource-sync
2026-07-13 12:14:16 +08:00
commit 8a852e4b4e
36502 changed files with 9277225 additions and 0 deletions
+35
View File
@@ -0,0 +1,35 @@
# Description:
# This package provides binaries that convert between multi-line and standard
# pbtxt (text-serialization of protocol message) files.
load("//tensorflow:tensorflow.bzl", "tf_cc_binary")
package(
# copybara:uncomment default_applicable_licenses = ["//tensorflow:license"],
default_visibility = ["//visibility:private"],
licenses = ["notice"],
)
exports_files(["placeholder.txt"])
tf_cc_binary(
name = "tomlpbtxt",
srcs = ["tomlpbtxt.cc"],
deps = [
"//tensorflow/core:framework_internal",
"//tensorflow/core:lib",
"//tensorflow/core:op_gen_lib",
"@com_google_absl//absl/status",
],
)
tf_cc_binary(
name = "frommlpbtxt",
srcs = ["frommlpbtxt.cc"],
deps = [
"//tensorflow/core:framework_internal",
"//tensorflow/core:lib",
"//tensorflow/core:op_gen_lib",
"@com_google_absl//absl/status",
],
)
+74
View File
@@ -0,0 +1,74 @@
/* Copyright 2017 The TensorFlow Authors All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#include <stdio.h>
#include <string>
#include <vector>
#include "absl/status/status.h"
#include "tensorflow/core/framework/op_gen_lib.h"
#include "tensorflow/core/platform/env.h"
#include "tensorflow/core/platform/init_main.h"
#include "tensorflow/core/platform/status.h"
#include "tensorflow/core/platform/types.h"
#include "tensorflow/core/util/command_line_flags.h"
namespace tensorflow {
namespace {
int Run(int argc, char** argv) {
std::string FLAGS_in = "";
std::string FLAGS_out = "";
std::vector<Flag> flag_list = {
Flag("in", &FLAGS_in, "Input multi-line proto text (.mlpbtxt) file name"),
Flag("out", &FLAGS_out, "Output proto text (.pbtxt) file name")};
// Parse the command-line.
const std::string usage = Flags::Usage(argv[0], flag_list);
const bool parse_ok = Flags::Parse(&argc, argv, flag_list);
if (argc != 1 || !parse_ok) {
printf("%s", usage.c_str());
return 2;
}
port::InitMain(argv[0], &argc, &argv);
// Read the input file --in.
std::string in_contents;
absl::Status s = ReadFileToString(Env::Default(), FLAGS_in, &in_contents);
if (!s.ok()) {
printf("Error reading file %s: %s\n", FLAGS_in.c_str(),
s.ToString().c_str());
return 1;
}
// Write the output file --out.
const std::string out_contents = PBTxtFromMultiline(in_contents);
s = WriteStringToFile(Env::Default(), FLAGS_out, out_contents);
if (!s.ok()) {
printf("Error writing file %s: %s\n", FLAGS_out.c_str(),
s.ToString().c_str());
return 1;
}
return 0;
}
} // namespace
} // namespace tensorflow
int main(int argc, char** argv) { return tensorflow::Run(argc, argv); }
+86
View File
@@ -0,0 +1,86 @@
/* Copyright 2017 The TensorFlow Authors All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#include <stdio.h>
#include <string>
#include <vector>
#include "absl/status/status.h"
#include "tensorflow/core/framework/op_gen_lib.h"
#include "tensorflow/core/lib/strings/str_util.h"
#include "tensorflow/core/platform/env.h"
#include "tensorflow/core/platform/init_main.h"
#include "tensorflow/core/platform/status.h"
#include "tensorflow/core/platform/types.h"
#include "tensorflow/core/util/command_line_flags.h"
namespace tensorflow {
namespace {
int Run(int argc, char** argv) {
std::string FLAGS_in = "";
std::string FLAGS_out = "";
std::string FLAGS_fields = "description";
std::vector<Flag> flag_list = {
Flag("in", &FLAGS_in, "Input proto text (.pbtxt) file name"),
Flag("out", &FLAGS_out,
"Output multi-line proto text (.mlpbtxt) file name"),
Flag("fields", &FLAGS_fields, "Comma-separated list of field names")};
// Parse the command-line.
const std::string usage = Flags::Usage(argv[0], flag_list);
const bool parse_ok = Flags::Parse(&argc, argv, flag_list);
if (argc != 1 || !parse_ok) {
printf("%s", usage.c_str());
return 2;
}
// Parse the --fields option.
std::vector<std::string> fields =
str_util::Split(FLAGS_fields, ',', str_util::SkipEmpty());
if (fields.empty()) {
printf("--fields must be non-empty.\n%s", usage.c_str());
return 2;
}
port::InitMain(argv[0], &argc, &argv);
// Read the input file --in.
std::string in_contents;
absl::Status s = ReadFileToString(Env::Default(), FLAGS_in, &in_contents);
if (!s.ok()) {
printf("Error reading file %s: %s\n", FLAGS_in.c_str(),
s.ToString().c_str());
return 1;
}
// Write the output file --out.
const std::string out_contents = PBTxtToMultiline(in_contents, fields);
s = WriteStringToFile(Env::Default(), FLAGS_out, out_contents);
if (!s.ok()) {
printf("Error writing file %s: %s\n", FLAGS_out.c_str(),
s.ToString().c_str());
return 1;
}
return 0;
}
} // namespace
} // namespace tensorflow
int main(int argc, char** argv) { return tensorflow::Run(argc, argv); }