Convenience function to export a saved_model using provided arguments The caller specifies the saved_model signatures in a simplified python dictionary form, as follows:: signatures = { 'signature_def_key': { 'inputs': { 'input_tensor_alias': input_tensor_name }, 'outpu
(sess, export_dir, tag_set, signatures)
| 160 | |
| 161 | |
| 162 | def export_saved_model(sess, export_dir, tag_set, signatures): |
| 163 | """Convenience function to export a saved_model using provided arguments |
| 164 | |
| 165 | The caller specifies the saved_model signatures in a simplified python dictionary form, as follows:: |
| 166 | |
| 167 | signatures = { |
| 168 | 'signature_def_key': { |
| 169 | 'inputs': { 'input_tensor_alias': input_tensor_name }, |
| 170 | 'outputs': { 'output_tensor_alias': output_tensor_name }, |
| 171 | 'method_name': 'method' |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | And this function will generate the `signature_def_map` and export the saved_model. |
| 176 | |
| 177 | DEPRECATED for TensorFlow 2.x+. |
| 178 | |
| 179 | Args: |
| 180 | :sess: a tf.Session instance |
| 181 | :export_dir: path to save exported saved_model |
| 182 | :tag_set: string tag_set to identify the exported graph |
| 183 | :signatures: simplified dictionary representation of a TensorFlow signature_def_map |
| 184 | |
| 185 | Returns: |
| 186 | A saved_model exported to disk at ``export_dir``. |
| 187 | """ |
| 188 | import tensorflow as tf |
| 189 | |
| 190 | if version.parse(tf.__version__) >= version.parse("2.0.0"): |
| 191 | raise Exception("DEPRECATED: Use TF provided APIs instead.") |
| 192 | |
| 193 | g = sess.graph |
| 194 | g._unsafe_unfinalize() # https://github.com/tensorflow/serving/issues/363 |
| 195 | builder = tf.saved_model.builder.SavedModelBuilder(export_dir) |
| 196 | |
| 197 | logging.info("===== signatures: {}".format(signatures)) |
| 198 | signature_def_map = {} |
| 199 | for key, sig in signatures.items(): |
| 200 | signature_def_map[key] = tf.saved_model.signature_def_utils.build_signature_def( |
| 201 | inputs={name: tf.saved_model.utils.build_tensor_info(tensor) for name, tensor in sig['inputs'].items()}, |
| 202 | outputs={name: tf.saved_model.utils.build_tensor_info(tensor) for name, tensor in sig['outputs'].items()}, |
| 203 | method_name=sig['method_name'] if 'method_name' in sig else key) |
| 204 | logging.info("===== signature_def_map: {}".format(signature_def_map)) |
| 205 | builder.add_meta_graph_and_variables( |
| 206 | sess, |
| 207 | tag_set.split(','), |
| 208 | signature_def_map=signature_def_map, |
| 209 | clear_devices=True) |
| 210 | g.finalize() |
| 211 | builder.save() |
| 212 | |
| 213 | |
| 214 | def release_port(ctx): |
nothing calls this directly
no outgoing calls
no test coverage detected