Project import generated by Copybara.
GitOrigin-RevId: 6e4aff1cc351be3ae4537b677f36d139ee50ce09
This commit is contained in:
@@ -19,6 +19,7 @@ load(
|
||||
"data_as_c_string",
|
||||
"mediapipe_binary_graph",
|
||||
)
|
||||
load("//mediapipe/framework:mediapipe_cc_test.bzl", "mediapipe_cc_test")
|
||||
|
||||
licenses(["notice"])
|
||||
|
||||
@@ -35,9 +36,10 @@ cc_library(
|
||||
deps = [
|
||||
"//mediapipe/framework:calculator_cc_proto",
|
||||
"//mediapipe/framework/port:advanced_proto",
|
||||
"//mediapipe/framework/port:commandlineflags",
|
||||
"//mediapipe/framework/port:ret_check",
|
||||
"//mediapipe/framework/port:status",
|
||||
"@com_google_absl//absl/flags:flag",
|
||||
"@com_google_absl//absl/flags:parse",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -150,6 +152,28 @@ cc_library(
|
||||
],
|
||||
)
|
||||
|
||||
mediapipe_cc_test(
|
||||
name = "options_util_test",
|
||||
size = "small",
|
||||
srcs = ["options_util_test.cc"],
|
||||
data = [":node_chain_subgraph.proto"],
|
||||
requires_full_emulation = False,
|
||||
deps = [
|
||||
":options_util",
|
||||
"//mediapipe/calculators/core:flow_limiter_calculator",
|
||||
"//mediapipe/calculators/core:flow_limiter_calculator_cc_proto",
|
||||
"//mediapipe/framework:basic_types_registration",
|
||||
"//mediapipe/framework:calculator_framework",
|
||||
"//mediapipe/framework:calculator_runner",
|
||||
"//mediapipe/framework:validated_graph_config",
|
||||
"//mediapipe/framework/port:gtest_main",
|
||||
"//mediapipe/framework/port:parse_text_proto",
|
||||
"//mediapipe/framework/port:status",
|
||||
"//mediapipe/framework/testdata:night_light_calculator_cc_proto",
|
||||
"//mediapipe/util:header_util",
|
||||
],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "packet_util",
|
||||
hdrs = ["packet_util.h"],
|
||||
@@ -227,6 +251,7 @@ cc_library(
|
||||
":name_util",
|
||||
":tag_map",
|
||||
"//mediapipe/framework:calculator_cc_proto",
|
||||
"//mediapipe/framework:graph_service_manager",
|
||||
"//mediapipe/framework:packet_generator",
|
||||
"//mediapipe/framework:packet_generator_cc_proto",
|
||||
"//mediapipe/framework:port",
|
||||
@@ -560,7 +585,9 @@ cc_test(
|
||||
":subgraph_expansion",
|
||||
"//mediapipe/framework:calculator_cc_proto",
|
||||
"//mediapipe/framework:calculator_framework",
|
||||
"//mediapipe/framework:graph_service_manager",
|
||||
"//mediapipe/framework:mediapipe_options_cc_proto",
|
||||
"//mediapipe/framework:packet",
|
||||
"//mediapipe/framework:packet_generator_cc_proto",
|
||||
"//mediapipe/framework:packet_set",
|
||||
"//mediapipe/framework:packet_type",
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
|
||||
#include "absl/memory/memory.h"
|
||||
#include "absl/strings/str_cat.h"
|
||||
#include "mediapipe/framework/graph_service_manager.h"
|
||||
#include "mediapipe/framework/packet_generator.pb.h"
|
||||
#include "mediapipe/framework/port.h"
|
||||
#include "mediapipe/framework/port/core_proto_inc.h"
|
||||
@@ -273,7 +274,8 @@ absl::Status ConnectSubgraphStreams(
|
||||
}
|
||||
|
||||
absl::Status ExpandSubgraphs(CalculatorGraphConfig* config,
|
||||
const GraphRegistry* graph_registry) {
|
||||
const GraphRegistry* graph_registry,
|
||||
const GraphServiceManager* service_manager) {
|
||||
graph_registry =
|
||||
graph_registry ? graph_registry : &GraphRegistry::global_graph_registry;
|
||||
RET_CHECK(config);
|
||||
@@ -292,9 +294,10 @@ absl::Status ExpandSubgraphs(CalculatorGraphConfig* config,
|
||||
int node_id = it - nodes->begin();
|
||||
std::string node_name = CanonicalNodeName(*config, node_id);
|
||||
MP_RETURN_IF_ERROR(ValidateSubgraphFields(node));
|
||||
ASSIGN_OR_RETURN(auto subgraph,
|
||||
graph_registry->CreateByName(config->package(),
|
||||
node.calculator(), &node));
|
||||
SubgraphContext subgraph_context(&node, service_manager);
|
||||
ASSIGN_OR_RETURN(auto subgraph, graph_registry->CreateByName(
|
||||
config->package(), node.calculator(),
|
||||
&subgraph_context));
|
||||
MP_RETURN_IF_ERROR(PrefixNames(node_name, &subgraph));
|
||||
MP_RETURN_IF_ERROR(ConnectSubgraphStreams(node, &subgraph));
|
||||
subgraphs.push_back(subgraph);
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "mediapipe/framework/calculator.pb.h"
|
||||
#include "mediapipe/framework/graph_service_manager.h"
|
||||
#include "mediapipe/framework/port/proto_ns.h"
|
||||
#include "mediapipe/framework/port/status.h"
|
||||
#include "mediapipe/framework/subgraph.h"
|
||||
@@ -68,8 +69,10 @@ absl::Status ConnectSubgraphStreams(
|
||||
// Replaces subgraph nodes in the given config with the contents of the
|
||||
// corresponding subgraphs. Nested subgraphs are retrieved from the
|
||||
// graph registry and expanded recursively.
|
||||
absl::Status ExpandSubgraphs(CalculatorGraphConfig* config,
|
||||
const GraphRegistry* graph_registry = nullptr);
|
||||
absl::Status ExpandSubgraphs(
|
||||
CalculatorGraphConfig* config,
|
||||
const GraphRegistry* graph_registry = nullptr,
|
||||
const GraphServiceManager* service_manager = nullptr);
|
||||
|
||||
// Creates a graph wrapping the provided node and exposing all of its
|
||||
// connections
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
#include "mediapipe/framework/calculator.pb.h"
|
||||
#include "mediapipe/framework/calculator_framework.h"
|
||||
#include "mediapipe/framework/deps/message_matchers.h"
|
||||
#include "mediapipe/framework/graph_service_manager.h"
|
||||
#include "mediapipe/framework/packet.h"
|
||||
#include "mediapipe/framework/packet_set.h"
|
||||
#include "mediapipe/framework/packet_type.h"
|
||||
#include "mediapipe/framework/port/gmock.h"
|
||||
@@ -526,5 +528,41 @@ TEST(SubgraphExpansionTest, ExecutorFieldOfNodeInSubgraphPreserved) {
|
||||
EXPECT_THAT(supergraph, mediapipe::EqualsProto(expected_graph));
|
||||
}
|
||||
|
||||
const mediapipe::GraphService<std::string> kStringTestService{
|
||||
"mediapipe::StringTestService"};
|
||||
class GraphServicesClientTestSubgraph : public Subgraph {
|
||||
public:
|
||||
absl::StatusOr<CalculatorGraphConfig> GetConfig(
|
||||
SubgraphContext* sc) override {
|
||||
auto string_service = sc->Service(kStringTestService);
|
||||
RET_CHECK(string_service.IsAvailable()) << "Service not available";
|
||||
CalculatorGraphConfig config;
|
||||
config.add_node()->set_calculator(string_service.GetObject());
|
||||
return config;
|
||||
}
|
||||
};
|
||||
REGISTER_MEDIAPIPE_GRAPH(GraphServicesClientTestSubgraph);
|
||||
|
||||
TEST(SubgraphExpansionTest, GraphServicesUsage) {
|
||||
CalculatorGraphConfig supergraph =
|
||||
mediapipe::ParseTextProtoOrDie<CalculatorGraphConfig>(R"(
|
||||
node { calculator: "GraphServicesClientTestSubgraph" }
|
||||
)");
|
||||
|
||||
CalculatorGraphConfig expected_graph =
|
||||
mediapipe::ParseTextProtoOrDie<CalculatorGraphConfig>(R"(
|
||||
node {
|
||||
name: "graphservicesclienttestsubgraph__ExpectedNode"
|
||||
calculator: "ExpectedNode"
|
||||
}
|
||||
)");
|
||||
GraphServiceManager service_manager;
|
||||
MP_ASSERT_OK(service_manager.SetServiceObject(
|
||||
kStringTestService, std::make_shared<std::string>("ExpectedNode")));
|
||||
MP_EXPECT_OK(tool::ExpandSubgraphs(&supergraph, /*graph_registry=*/nullptr,
|
||||
&service_manager));
|
||||
EXPECT_THAT(supergraph, mediapipe::EqualsProto(expected_graph));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace mediapipe
|
||||
|
||||
@@ -19,19 +19,19 @@
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
|
||||
#include "absl/flags/flag.h"
|
||||
#include "absl/flags/parse.h"
|
||||
#include "mediapipe/framework/calculator.pb.h"
|
||||
#include "mediapipe/framework/port/advanced_proto_inc.h"
|
||||
#include "mediapipe/framework/port/canonical_errors.h"
|
||||
#include "mediapipe/framework/port/commandlineflags.h"
|
||||
#include "mediapipe/framework/port/ret_check.h"
|
||||
#include "mediapipe/framework/port/status.h"
|
||||
|
||||
DEFINE_string(proto_source, "",
|
||||
"The template source file containing CalculatorGraphConfig "
|
||||
"protobuf text with inline template params.");
|
||||
DEFINE_string(
|
||||
proto_output, "",
|
||||
"An output template file in binary CalculatorGraphTemplate form.");
|
||||
ABSL_FLAG(std::string, proto_source, "",
|
||||
"The template source file containing CalculatorGraphConfig "
|
||||
"protobuf text with inline template params.");
|
||||
ABSL_FLAG(std::string, proto_output, "",
|
||||
"An output template file in binary CalculatorGraphTemplate form.");
|
||||
|
||||
#define EXIT_IF_ERROR(status) \
|
||||
if (!status.ok()) { \
|
||||
@@ -92,7 +92,7 @@ absl::Status WriteFile(const std::string& proto_output, bool write_text,
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
google::InitGoogleLogging(argv[0]);
|
||||
gflags::ParseCommandLineFlags(&argc, &argv, true);
|
||||
absl::ParseCommandLine(argc, argv);
|
||||
|
||||
// Validate command line options.
|
||||
absl::Status status;
|
||||
|
||||
Reference in New Issue
Block a user