Created
March 7, 2019 03:46
-
-
Save Shubhra22/d0fcf6564dd7d34f5b0787796aed9e59 to your computer and use it in GitHub Desktop.
Freeze Existing ML Model to Unity 3d Python Code
This file contains 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
# IMPORTS | |
import tensorflow as tf | |
# freeze_graph "screenshots" the graph | |
from tensorflow.python.tools import freeze_graph | |
# optimize_for_inference lib optimizes this frozen graph | |
from tensorflow.python.tools import optimize_for_inference_lib | |
# os and os.path are used to create the output file where we save our frozen graphs | |
import os | |
import os.path as path | |
MODEL_NAME = '8_OCR' | |
input_graph_path = '/Users/shubhrasarker/Desktop/OCR/PBAR/OCRModel/'+ MODEL_NAME+'.pbtx' | |
checkpoint_path = '/Users/shubhrasarker/Desktop/OCR/PBAR/OCRModel/'+MODEL_NAME+'.ckpt' | |
# an arbitrary name for our graph | |
GRAPH_NAME = MODEL_NAME +'frozen_unity' | |
# GRAPH SAVING - '.bytes' | |
# freeze_graph.freeze_graph(input_graph_path, input_saver_def_path, | |
# input_binary, checkpoint_path, output_node_names, | |
# restore_op_name, filename_tensor_name, | |
# output_frozen_graph_name, clear_devices, "") | |
freeze_graph.freeze_graph(input_graph_path, None, False, checkpoint_path, "y_pred", | |
"save/restore_all", "save/Const:0", | |
'/Users/shubhrasarker/Desktop/OCR/PBAR/OCRModel/frozen_' + GRAPH_NAME + '.bytes', True, "") | |
print("graph saved!") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment