Run the pruned and frozen inference graph.
(graph_path)
| 153 | |
| 154 | |
| 155 | def apply_compact(graph_path): |
| 156 | """Run the pruned and frozen inference graph. """ |
| 157 | with tf.Session(config=tf.ConfigProto(allow_soft_placement=True)) as sess: |
| 158 | # Note, we just load the graph and do *not* need to initialize anything. |
| 159 | with tf.gfile.GFile(graph_path, "rb") as f: |
| 160 | graph_def = tf.GraphDef() |
| 161 | graph_def.ParseFromString(f.read()) |
| 162 | tf.import_graph_def(graph_def) |
| 163 | |
| 164 | input_img = sess.graph.get_tensor_by_name('import/input_img:0') |
| 165 | prediction_img = sess.graph.get_tensor_by_name('import/prediction_img:0') |
| 166 | |
| 167 | prediction = sess.run(prediction_img, {input_img: cv2.imread('lena.png')[None, ...]}) |
| 168 | cv2.imwrite('applied_compact.png', prediction[0]) |
| 169 | |
| 170 | |
| 171 | if __name__ == '__main__': |
no test coverage detected