(self)
| 60 | self.assertTrue((expected_output == output_data).all()) |
| 61 | |
| 62 | def testUint8(self): |
| 63 | model_path = resource_loader.get_path_to_datafile( |
| 64 | 'testdata/permute_uint8.tflite') |
| 65 | with io.open(model_path, 'rb') as model_file: |
| 66 | data = model_file.read() |
| 67 | |
| 68 | interpreter = interpreter_wrapper.Interpreter(model_content=data) |
| 69 | interpreter.allocate_tensors() |
| 70 | |
| 71 | input_details = interpreter.get_input_details() |
| 72 | self.assertEqual(1, len(input_details)) |
| 73 | self.assertEqual('input', input_details[0]['name']) |
| 74 | self.assertEqual(np.uint8, input_details[0]['dtype']) |
| 75 | self.assertTrue(([1, 4] == input_details[0]['shape']).all()) |
| 76 | self.assertEqual((1.0, 0), input_details[0]['quantization']) |
| 77 | |
| 78 | output_details = interpreter.get_output_details() |
| 79 | self.assertEqual(1, len(output_details)) |
| 80 | self.assertEqual('output', output_details[0]['name']) |
| 81 | self.assertEqual(np.uint8, output_details[0]['dtype']) |
| 82 | self.assertTrue(([1, 4] == output_details[0]['shape']).all()) |
| 83 | self.assertEqual((1.0, 0), output_details[0]['quantization']) |
| 84 | |
| 85 | test_input = np.array([[1, 2, 3, 4]], dtype=np.uint8) |
| 86 | expected_output = np.array([[4, 3, 2, 1]], dtype=np.uint8) |
| 87 | interpreter.resize_tensor_input(input_details[0]['index'], |
| 88 | test_input.shape) |
| 89 | interpreter.allocate_tensors() |
| 90 | interpreter.set_tensor(input_details[0]['index'], test_input) |
| 91 | interpreter.invoke() |
| 92 | |
| 93 | output_data = interpreter.get_tensor(output_details[0]['index']) |
| 94 | self.assertTrue((expected_output == output_data).all()) |
| 95 | |
| 96 | def testString(self): |
| 97 | interpreter = interpreter_wrapper.Interpreter( |
nothing calls this directly
no test coverage detected