1 | /* Copyright 2022 The TensorFlow Authors. All Rights Reserved. |
2 | |
3 | Licensed under the Apache License, Version 2.0 (the "License");; |
4 | you may not use this file except in compliance with the License. |
5 | You may obtain a copy of the License at |
6 | |
7 | http://www.apache.org/licenses/LICENSE-2.0 |
8 | |
9 | Unless required by applicable law or agreed to in writing, software |
10 | distributed under the License is distributed on an "AS IS" BASIS, |
11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | See the License for the specific language governing permissions and |
13 | limitations under the License. |
14 | ==============================================================================*/ |
15 | |
16 | #include <string> |
17 | |
18 | #include "absl/strings/string_view.h" |
19 | #include "pybind11/pybind11.h" |
20 | #include "tensorflow/cc/saved_model/fingerprinting.h" |
21 | #include "tensorflow/core/protobuf/saved_model.pb.h" |
22 | |
23 | namespace tensorflow { |
24 | namespace saved_model { |
25 | namespace python { |
26 | |
27 | namespace py = pybind11; |
28 | |
29 | void DefineFingerprintingModule(py::module main_module) { |
30 | auto m = main_module.def_submodule("fingerprinting" ); |
31 | |
32 | m.doc() = "Python bindings for TensorFlow SavedModel Fingerprinting." ; |
33 | |
34 | m.def( |
35 | "CreateFingerprintDef" , |
36 | [](std::string serialized_saved_model, std::string export_dir) { |
37 | // Deserialize the SavedModel. |
38 | SavedModel saved_model_pb; |
39 | saved_model_pb.ParseFromString(serialized_saved_model); |
40 | |
41 | return py::bytes(fingerprinting::CreateFingerprintDef( |
42 | saved_model_pb.meta_graphs(0), export_dir) |
43 | .SerializeAsString()); |
44 | }, |
45 | py::arg("saved_model" ), py::arg("export_dir" ), |
46 | py::doc( |
47 | "Returns the serialized FingerprintDef of a serialized SavedModel." )); |
48 | } |
49 | |
50 | } // namespace python |
51 | } // namespace saved_model |
52 | } // namespace tensorflow |
53 | |