MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / testConstantFolding

Method testConstantFolding

tensorflow/lite/python/lite_v2_test.py:487–510  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

485
486 @test_util.run_v2_only
487 def testConstantFolding(self):
488 # Constant folding handles the tf.broadcast_to operation which was not
489 # supported by the TFLite at the time this test was added.
490 input_data = constant_op.constant([1., 2., 3., 4., 5., 6., 7., 8., 9.],
491 shape=[3, 3])
492
493 @def_function.function
494 def func(x):
495 y_const = constant_op.constant([1., 2., 3.])
496 y_broadcast = gen_array_ops.broadcast_to(y_const, [3, 3])
497 return math_ops.matmul(x, y_broadcast)
498
499 root = tracking.AutoTrackable()
500 root.f = func
501 concrete_func = root.f.get_concrete_function(input_data)
502
503 # Convert model.
504 converter = lite.TFLiteConverterV2.from_concrete_functions([concrete_func])
505 tflite_model = converter.convert()
506
507 # Check values from converted model.
508 expected_value = root.f(input_data)
509 actual_value = self._evaluateTFLiteModel(tflite_model, [input_data])
510 np.testing.assert_array_equal(expected_value.numpy(), actual_value)
511
512
513if __name__ == '__main__':

Callers

nothing calls this directly

Calls 7

constantMethod · 0.45
get_concrete_functionMethod · 0.45
convertMethod · 0.45
fMethod · 0.45
_evaluateTFLiteModelMethod · 0.45
numpyMethod · 0.45

Tested by

no test coverage detected