MCPcopy Index your code
hub / github.com/tensorpack/tensorpack / InferenceOnlyModel

Class InferenceOnlyModel

examples/basics/export-model.py:83–102  ·  view source on GitHub ↗

Recreate a different inference graph to accept images encoded as png.

Source from the content-addressed store, hash-verified

81
82
83class 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
105def export_serving(model_path):

Callers 2

export_servingFunction · 0.85
apply_inference_graphFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected