Skip to content

Instantly share code, notes, and snippets.

@dkurt
Created May 6, 2020 10:52
Show Gist options
  • Save dkurt/3486f09fafe568ee20e500310dedcb9f to your computer and use it in GitHub Desktop.
Save dkurt/3486f09fafe568ee20e500310dedcb9f to your computer and use it in GitHub Desktop.
import tensorflow as tf
from tensorflow.python.tools import optimize_for_inference_lib
pb_file = 'resnet_v2_101_299_frozen.pb'
graph_def = tf.compat.v1.GraphDef()
try:
with tf.io.gfile.GFile(pb_file, 'rb') as f:
graph_def.ParseFromString(f.read())
except:
with tf.gfile.FastGFile(pb_file, 'rb') as f:
graph_def.ParseFromString(f.read())
graph_def = optimize_for_inference_lib.optimize_for_inference(graph_def, ['input'], ['output'], tf.float32.as_datatype_enum)
with tf.gfile.FastGFile('resnet_v2_101_299_opt.pb', 'wb') as f:
f.write(graph_def.SerializeToString())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment