Skip to content

Commit

Permalink
Support multiple files in the Model Explorer Mediapipe Adapter
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 705688677
  • Loading branch information
Google AI Edge authored and copybara-github committed Dec 16, 2024
1 parent 2da380f commit be0fbc5
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/builtin-adapter/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ cc_library(
"@com_google_absl//absl/status:statusor",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/strings:string_view",
"//mediapipe_adapter:mediapipe_to_json",
"@org_tensorflow//tensorflow/core:lib",
],
)
Expand Down
1 change: 1 addition & 0 deletions src/builtin-adapter/python/convert_wrapper/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ pybind_extension(
"//:direct_saved_model_to_json_graph_convert",
"//:model_json_graph_convert",
"//:visualize_config",
"//mediapipe_adapter:mediapipe_to_json",
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class VisualizeConfig:
def ConvertFlatbufferDirectlyToJson(arg0: VisualizeConfig, arg1: str) -> str: ...
def ConvertFlatbufferToJson(arg0: VisualizeConfig, arg1: str, arg2: bool) -> str: ...
def ConvertGraphDefDirectlyToJson(arg0: VisualizeConfig, arg1: str) -> str: ...
def ConvertMediapipeToJson(arg0: VisualizeConfig, arg1: str) -> str: ...
def ConvertMlirToJson(arg0: VisualizeConfig, arg1: str) -> str: ...
def ConvertSavedModelDirectlyToJson(arg0: VisualizeConfig, arg1: str) -> str: ...
def ConvertSavedModelToJson(arg0: VisualizeConfig, arg1: str) -> str: ...
17 changes: 17 additions & 0 deletions src/builtin-adapter/python/convert_wrapper/convert_wrapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "pybind11/pybind11.h"
#include "direct_flatbuffer_to_json_graph_convert.h"
#include "direct_saved_model_to_json_graph_convert.h"
#include "mediapipe_adapter/mediapipe_to_json.h"
#include "model_json_graph_convert.h"
#include "visualize_config.h"

Expand Down Expand Up @@ -134,6 +135,22 @@ PYBIND11_MODULE(_pywrap_convert_wrapper, m) {
Converts a MLIR textual/bytecode file to visualizer JSON string.
Raises `RuntimeError` exception if failed.
)pbdoc");
m.def(
"ConvertMediapipeToJson",
[](const VisualizeConfig& config,
absl::string_view model_path) -> std::string {
const absl::StatusOr<std::string> json_or_status =
::tooling::visualization_client::ConvertMediapipeToJson(config,
model_path);
if (!json_or_status.ok()) {
throw std::runtime_error(json_or_status.status().ToString());
}
return json_or_status.value();
},
R"pbdoc(
Converts a Mediapipe pipeline to visualizer JSON string.
Raises `RuntimeError` exception if failed.
)pbdoc");
}

} // namespace pybind11

0 comments on commit be0fbc5

Please sign in to comment.