| 68 | |
| 69 | |
| 70 | class TestShuffleNet(unittest.TestCase): |
| 71 | source_dir = os.getenv("LITE_TEST_RESOURCE") |
| 72 | input_data_path = os.path.join(source_dir, "input_data.npy") |
| 73 | correct_data_path = os.path.join(source_dir, "output_data.npy") |
| 74 | model_path = os.path.join(source_dir, "shufflenet.mge") |
| 75 | correct_data = np.load(correct_data_path).flatten() |
| 76 | input_data = np.load(input_data_path) |
| 77 | |
| 78 | def check_correct(self, out_data, error=1e-4): |
| 79 | out_data = out_data.flatten() |
| 80 | assert np.isfinite(out_data.sum()) |
| 81 | assert self.correct_data.size == out_data.size |
| 82 | for i in range(out_data.size): |
| 83 | assert abs(out_data[i] - self.correct_data[i]) < error |
| 84 | |
| 85 | def do_forward(self, network, times=3): |
| 86 | input_name = network.get_input_name(0) |
| 87 | input_tensor = network.get_io_tensor(input_name) |
| 88 | output_name = network.get_output_name(0) |
| 89 | output_tensor = network.get_io_tensor(output_name) |
| 90 | |
| 91 | input_tensor.set_data_by_copy(self.input_data) |
| 92 | for i in range(times): |
| 93 | network.forward() |
| 94 | network.wait() |
| 95 | |
| 96 | output_data = output_tensor.to_numpy() |
| 97 | self.check_correct(output_data) |
| 98 | |
| 99 | |
| 100 | class TestNetwork(TestShuffleNet): |