Recreate a different inference graph to accept images encoded as png.
| 81 | |
| 82 | |
| 83 | class InferenceOnlyModel(Model): |
| 84 | """Recreate a different inference graph to accept images encoded as png. """ |
| 85 | |
| 86 | def inputs(self): |
| 87 | # The inference graph only accepts a single image, which is different to the training model. |
| 88 | return [tf.TensorSpec((None,), tf.string, 'input_img_bytes')] |
| 89 | |
| 90 | def build_graph(self, input_img_bytes): |
| 91 | # prepare input (png encoded strings to images) |
| 92 | input_img = tf.map_fn(lambda x: tf.image.decode_png(x, channels=3), input_img_bytes, dtype=tf.uint8) |
| 93 | |
| 94 | # just copy the relevant parts to this graph. |
| 95 | prediction_img = self.make_prediction(input_img) |
| 96 | |
| 97 | # outputs should be png encoded strings agains |
| 98 | prediction_img = tf.clip_by_value(prediction_img, 0, 255) |
| 99 | prediction_img = tf.cast(prediction_img, tf.uint8) |
| 100 | prediction_img_bytes = tf.map_fn(tf.image.encode_png, prediction_img, dtype=tf.string) |
| 101 | |
| 102 | tf.identity(prediction_img_bytes, name='prediction_img_bytes') |
| 103 | |
| 104 | |
| 105 | def export_serving(model_path): |
no outgoing calls
no test coverage detected