Created
February 28, 2019 08:09
-
-
Save DibyaranjanSathua/abb9d04565e87e18ba5216a87ecc5480 to your computer and use it in GitHub Desktop.
Run different transformation on tensorflow model
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tensorflow as tf | |
from tensorflow.tools.graph_transforms import TransformGraph | |
def transform_graph(input_graph, output_graph): | |
""" Use to run different transform function on the input graph and generate a output graph. """ | |
with tf.gfile.GFile(input_graph, 'rb') as fid: | |
od_graph_def = tf.GraphDef() | |
serialized_graph = fid.read() | |
od_graph_def.ParseFromString(serialized_graph) | |
od_graph_def = TransformGraph(od_graph_def, ['input_placeholder/input_image'], ['predicated_output'], | |
['strip_unused_nodes(type=float, shape="1,28,28,1")', 'remove_nodes(op=Identity, op=CheckNumerics, op=Switch)', | |
'fold_constants(ignore_errors=true)', 'fold_batch_norms', 'fold_old_batch_norms', 'sort_by_execution_order']) | |
tf.io.write_graph(od_graph_def, "", output_graph, as_text=False) | |
if __name__ == '__main__': | |
frozen_graph = "/Users/dibyaranjan/Python/Projects/LicensePlate/OCR_Model/AlphaDigitAdam30Epochs36Classes_V2/frozen_inference_graph.pb" | |
output_transform_graph = "/Users/dibyaranjan/Python/Projects/LicensePlate/OCR_Model/AlphaDigitAdam30Epochs36Classes_V2/transformed_graph.pb" | |
transform_graph(frozen_graph, output_transform_graph) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment