@@ -0,0 +1,2715 @@
+# Copyright 2020 Google LLC%0A#%0A# Licensed under the Apache License, Version 2.0 (the %22License%22);%0A# you may not use this file except in compliance with the License.%0A# You may obtain a copy of the License at%0A#%0A#     https://www.apache.org/licenses/LICENSE-2.0%0A#%0A# Unless required by applicable law or agreed to in writing, software%0A# distributed under the License is distributed on an %22AS IS%22 BASIS,%0A# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A# See the License for the specific language governing permissions and%0A# limitations under the License.%0A%0A%22%22%22Re-export SavedModel for GCP deployment.%22%22%22%0A%0Aimport argparse%0Aimport tensorflow as tf%0Aimport os%0A%0Adef re_export_model_LaserTagger(saved_model_folder, output_folder):%0A    saved_model_folder = os.path.expanduser(saved_model_folder)%0A    output_folder = os.path.expanduser(output_folder)%0A    %0A    print(output_folder)%0A    builder = tf.saved_model.builder.SavedModelBuilder(output_folder)%0A%0A    with tf.compat.v1.Session(graph=tf.Graph()) as sess:%0A        tensor_info_input_ids = tf.saved_model.utils.build_tensor_info(tf.placeholder(tf.int64, %5BNone, None%5D, name=%22Placeholder%22))%0A        tensor_info_input_mask = tf.saved_model.utils.build_tensor_info(tf.placeholder(tf.int64, %5BNone, None%5D, name=%22Placeholder%22))%0A        tensor_info_segment_ids = tf.saved_model.utils.build_tensor_info(tf.placeholder(tf.int64, %5BNone, None%5D, name=%22Placeholder%22))%0A        tensor_info_outputs = tf.saved_model.utils.build_tensor_info(tf.placeholder(tf.int32, %5BNone, None%5D, name=%22loss/sub%22))%0A%0A    with tf.compat.v1.Session(graph=tf.Graph()) as sess:%0A        prediction_signature = (%0A      tf.saved_model.signature_def_utils.build_signature_def(%0A          inputs=%7B'input_ids': tensor_info_input_ids, 'input_mask': tensor_info_input_mask, %0A                 'segment_ids': tensor_info_segment_ids%7D,%0A          outputs=%7B'pred': tensor_info_outputs%7D,%0A          method_name=tf.saved_model.signature_constants.PREDICT_METHOD_NAME))%0A%0A        tf.compat.v1.saved_model.loader.load(sess, %5B%22serve%22%5D, saved_model_folder)%0A        builder.add_meta_graph_and_variables(%0A      sess, %5Btf.saved_model.tag_constants.SERVING%5D,%0A      signature_def_map=%7B%0A          tf.saved_model.signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY:%0A              prediction_signature %0A      %7D,%0A      )%0A        builder.save()%0A%0A%0Aif __name__ == '__main__':%0A    parser = argparse.ArgumentParser()%0A    parser.add_argument(%22saved_model_folder%22, help=%22Absolute path to the folder containing SavedModel.%22)%0A    parser.add_argument(%22output_folder%22, help=%22Absolute path to the folder to store re-exported model.%22)%0A    args = parser.parse_args()%0A    %0A    re_export_model(args.saved_model_folder, args.output_folder)%0A

Create export_model_for_gcp.py