Test a Sequential tf.keras model with default inputs.
(self, test_context)
| 1607 | @parameterized.named_parameters(('_graph', context.graph_mode), |
| 1608 | ('_eager', context.eager_mode)) |
| 1609 | def testCustomLayer(self, test_context): |
| 1610 | """Test a Sequential tf.keras model with default inputs.""" |
| 1611 | with test_context(): |
| 1612 | self._getSequentialModel(include_custom_layer=True) |
| 1613 | |
| 1614 | converter = lite.TFLiteConverter.from_keras_model_file( |
| 1615 | self._keras_file, custom_objects=self._custom_objects) |
| 1616 | tflite_model = converter.convert() |
| 1617 | self.assertTrue(tflite_model) |
| 1618 | |
| 1619 | # Check tensor details of converted model. |
| 1620 | interpreter = Interpreter(model_content=tflite_model) |
| 1621 | interpreter.allocate_tensors() |
| 1622 | |
| 1623 | input_details = interpreter.get_input_details() |
| 1624 | output_details = interpreter.get_output_details() |
| 1625 | |
| 1626 | # Check inference of converted model. |
| 1627 | input_data = np.array([[1, 2, 3]], dtype=np.float32) |
| 1628 | interpreter.set_tensor(input_details[0]['index'], input_data) |
| 1629 | interpreter.invoke() |
| 1630 | tflite_result = interpreter.get_tensor(output_details[0]['index']) |
| 1631 | |
| 1632 | keras_model = keras.models.load_model( |
| 1633 | self._keras_file, custom_objects=self._custom_objects) |
| 1634 | keras_result = keras_model.predict(input_data) |
| 1635 | |
| 1636 | np.testing.assert_almost_equal(tflite_result, keras_result, 5) |
| 1637 | |
| 1638 | def testSequentialModelInputArray(self): |
| 1639 | """Test a Sequential tf.keras model testing input arrays argument.""" |
nothing calls this directly
no test coverage detected