Create a TensorFlow SavedModel for testing. Args: name_scope: Name scope to create the model under. This helps avoid op and variable name clashes between different test methods. save_path: The directory path in which to save the model.
(name_scope, save_path)
| 74 | return model |
| 75 | |
| 76 | def _createTensorFlowSavedModelV1(name_scope, save_path): |
| 77 | """Create a TensorFlow SavedModel for testing. |
| 78 | Args: |
| 79 | name_scope: Name scope to create the model under. This helps avoid |
| 80 | op and variable name clashes between different test methods. |
| 81 | save_path: The directory path in which to save the model. |
| 82 | """ |
| 83 | graph = tf.Graph() |
| 84 | with graph.as_default(): |
| 85 | with tf.compat.v1.name_scope(name_scope): |
| 86 | x = tf.compat.v1.constant([[37.0, -23.0], [1.0, 4.0]]) |
| 87 | w = tf.compat.v1.get_variable('w', shape=[2, 2]) |
| 88 | y = tf.compat.v1.matmul(x, w) |
| 89 | output = tf.compat.v1.nn.softmax(y) |
| 90 | init_op = w.initializer |
| 91 | |
| 92 | # Create a builder. |
| 93 | builder = saved_model.builder.SavedModelBuilder(save_path) |
| 94 | |
| 95 | with tf.compat.v1.Session() as sess: |
| 96 | # Run the initializer on `w`. |
| 97 | sess.run(init_op) |
| 98 | |
| 99 | builder.add_meta_graph_and_variables( |
| 100 | sess, [saved_model.tag_constants.SERVING], |
| 101 | signature_def_map={ |
| 102 | "serving_default": |
| 103 | saved_model.signature_def_utils.predict_signature_def( |
| 104 | inputs={"x": x}, |
| 105 | outputs={"output": output}) |
| 106 | }, |
| 107 | assets_collection=None) |
| 108 | |
| 109 | builder.save() |
| 110 | |
| 111 | def _createTensorFlowSavedModel(save_path): |
| 112 | """Create a TensorFlow SavedModel for testing. |
no test coverage detected
searching dependent graphs…