| 12 | |
| 13 | |
| 14 | class TestShuffleNet(unittest.TestCase): |
| 15 | source_dir = os.getenv("LITE_TEST_RESOURCE") |
| 16 | input_data_path = os.path.join(source_dir, "input_data.npy") |
| 17 | correct_data_path = os.path.join(source_dir, "output_data.npy") |
| 18 | correct_data = np.load(correct_data_path).flatten() |
| 19 | input_data = np.load(input_data_path) |
| 20 | |
| 21 | def check_correct(self, out_data, error=1e-4): |
| 22 | out_data = out_data.flatten() |
| 23 | assert np.isfinite(out_data.sum()) |
| 24 | assert self.correct_data.size == out_data.size |
| 25 | for i in range(out_data.size): |
| 26 | assert abs(out_data[i] - self.correct_data[i]) < error |
| 27 | |
| 28 | def do_forward(self, network, times=3): |
| 29 | input_name = network.get_input_name(0) |
| 30 | input_tensor = network.get_io_tensor(input_name) |
| 31 | output_name = network.get_output_name(0) |
| 32 | output_tensor = network.get_io_tensor(output_name) |
| 33 | |
| 34 | input_tensor.set_data_by_copy(self.input_data) |
| 35 | for i in range(times): |
| 36 | network.forward() |
| 37 | network.wait() |
| 38 | |
| 39 | output_data = output_tensor.to_numpy() |
| 40 | self.check_correct(output_data) |
| 41 | |
| 42 | |
| 43 | class TestGlobal(TestShuffleNet): |