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

Method testSequentialModel

tensorflow/lite/python/lite_test.py:1570–1605  ·  view source on GitHub ↗

Test a Sequential tf.keras model with default inputs.

(self, test_context)

Source from the content-addressed store, hash-verified

1568 @parameterized.named_parameters(('_graph', context.graph_mode),
1569 ('_eager', context.eager_mode))
1570 def testSequentialModel(self, test_context):
1571 """Test a Sequential tf.keras model with default inputs."""
1572 with test_context():
1573 self._getSequentialModel()
1574
1575 converter = lite.TFLiteConverter.from_keras_model_file(self._keras_file)
1576 tflite_model = converter.convert()
1577 self.assertTrue(tflite_model)
1578
1579 # Check tensor details of converted model.
1580 interpreter = Interpreter(model_content=tflite_model)
1581 interpreter.allocate_tensors()
1582
1583 input_details = interpreter.get_input_details()
1584 self.assertLen(input_details, 1)
1585 self.assertEqual('dense_input', input_details[0]['name'])
1586 self.assertEqual(np.float32, input_details[0]['dtype'])
1587 self.assertTrue(([1, 3] == input_details[0]['shape']).all())
1588 self.assertEqual((0., 0.), input_details[0]['quantization'])
1589
1590 output_details = interpreter.get_output_details()
1591 self.assertLen(output_details, 1)
1592 self.assertEqual(np.float32, output_details[0]['dtype'])
1593 self.assertTrue(([1, 3, 3] == output_details[0]['shape']).all())
1594 self.assertEqual((0., 0.), output_details[0]['quantization'])
1595
1596 # Check inference of converted model.
1597 input_data = np.array([[1, 2, 3]], dtype=np.float32)
1598 interpreter.set_tensor(input_details[0]['index'], input_data)
1599 interpreter.invoke()
1600 tflite_result = interpreter.get_tensor(output_details[0]['index'])
1601
1602 keras_model = keras.models.load_model(self._keras_file)
1603 keras_result = keras_model.predict(input_data)
1604
1605 np.testing.assert_almost_equal(tflite_result, keras_result, 5)
1606
1607 @parameterized.named_parameters(('_graph', context.graph_mode),
1608 ('_eager', context.eager_mode))

Callers

nothing calls this directly

Calls 12

_getSequentialModelMethod · 0.95
allocate_tensorsMethod · 0.95
get_input_detailsMethod · 0.95
get_output_detailsMethod · 0.95
set_tensorMethod · 0.95
invokeMethod · 0.95
get_tensorMethod · 0.95
InterpreterClass · 0.90
from_keras_model_fileMethod · 0.45
convertMethod · 0.45
allMethod · 0.45
predictMethod · 0.45

Tested by

no test coverage detected