MCPcopy
hub / github.com/tensorflow/tfjs / _create_frozen_model

Function _create_frozen_model

tfjs-converter/python/test_pip_package.py:148–186  ·  view source on GitHub ↗
(save_path)

Source from the content-addressed store, hash-verified

146 m.export(save_path, sess)
147
148def _create_frozen_model(save_path):
149 graph = tf.Graph()
150 saved_model_dir = os.path.join(save_path)
151 with graph.as_default():
152 x = tf.constant([[37.0, -23.0], [1.0, 4.0]])
153 w = tf.Variable(tf.random.uniform([2, 2]))
154 y = tf.matmul(x, w)
155 tf.nn.softmax(y)
156 init_op = w.initializer
157
158 # Create a builder
159 builder = saved_model.builder.SavedModelBuilder(
160 saved_model_dir)
161
162 with tf.compat.v1.Session() as sess:
163 # Run the initializer on `w`.
164 sess.run(init_op)
165
166 builder.add_meta_graph_and_variables(
167 sess, [saved_model.tag_constants.SERVING],
168 signature_def_map=None,
169 assets_collection=None)
170
171 builder.save()
172
173 frozen_file = os.path.join(save_path, 'frozen.pb')
174 freeze_graph.freeze_graph(
175 '',
176 '',
177 True,
178 '',
179 "Softmax",
180 '',
181 '',
182 frozen_file,
183 True,
184 '',
185 saved_model_tags=saved_model.tag_constants.SERVING,
186 input_saved_model_dir=saved_model_dir)
187class APIAndShellTest(tf.test.TestCase):
188 """Tests for the Python API of the pip package."""
189

Callers 1

setUpClassMethod · 0.85

Calls 4

joinMethod · 0.80
softmaxMethod · 0.80
runMethod · 0.80
saveMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…