(self)
| 281 | str(error.exception)) |
| 282 | |
| 283 | def testScalarValid(self): |
| 284 | # Construct a graph using a scalar (empty shape) input. |
| 285 | with ops.Graph().as_default(): |
| 286 | in_tensor = array_ops.placeholder(dtype=dtypes.float32, shape=[]) |
| 287 | out_tensor = in_tensor + in_tensor |
| 288 | sess = session.Session() |
| 289 | |
| 290 | # Test conversion with the scalar input shape. |
| 291 | converter = lite.TFLiteConverter.from_session(sess, [in_tensor], |
| 292 | [out_tensor]) |
| 293 | tflite_model = converter.convert() |
| 294 | self.assertTrue(tflite_model) |
| 295 | |
| 296 | # Check values from converted model. |
| 297 | interpreter = Interpreter(model_content=tflite_model) |
| 298 | interpreter.allocate_tensors() |
| 299 | |
| 300 | input_details = interpreter.get_input_details() |
| 301 | self.assertEqual(1, len(input_details)) |
| 302 | self.assertEqual('Placeholder', input_details[0]['name']) |
| 303 | self.assertEqual(np.float32, input_details[0]['dtype']) |
| 304 | self.assertTrue(([] == input_details[0]['shape']).all()) |
| 305 | |
| 306 | output_details = interpreter.get_output_details() |
| 307 | self.assertEqual(1, len(output_details)) |
| 308 | self.assertEqual('add', output_details[0]['name']) |
| 309 | self.assertEqual(np.float32, output_details[0]['dtype']) |
| 310 | self.assertTrue(([] == input_details[0]['shape']).all()) |
| 311 | |
| 312 | # Validate inference using the scalar inputs/outputs. |
| 313 | test_input = np.array(4.0, dtype=np.float32) |
| 314 | expected_output = np.array(8.0, dtype=np.float32) |
| 315 | interpreter.set_tensor(input_details[0]['index'], test_input) |
| 316 | interpreter.invoke() |
| 317 | |
| 318 | output_data = interpreter.get_tensor(output_details[0]['index']) |
| 319 | self.assertTrue((expected_output == output_data).all()) |
| 320 | |
| 321 | def testSizeInvalid(self): |
| 322 | with ops.Graph().as_default(): |
nothing calls this directly
no test coverage detected