| 26 | |
| 27 | |
| 28 | class TestShuffleNetCuda(unittest.TestCase): |
| 29 | source_dir = os.getenv("LITE_TEST_RESOURCE") |
| 30 | input_data_path = os.path.join(source_dir, "input_data.npy") |
| 31 | correct_data_path = os.path.join(source_dir, "output_data.npy") |
| 32 | model_path = os.path.join(source_dir, "shufflenet.mge") |
| 33 | correct_data = np.load(correct_data_path).flatten() |
| 34 | input_data = np.load(input_data_path) |
| 35 | |
| 36 | def check_correct(self, out_data, error=1e-4): |
| 37 | out_data = out_data.flatten() |
| 38 | assert np.isfinite(out_data.sum()) |
| 39 | assert self.correct_data.size == out_data.size |
| 40 | for i in range(out_data.size): |
| 41 | assert abs(out_data[i] - self.correct_data[i]) < error |
| 42 | |
| 43 | def do_forward(self, network, times=3): |
| 44 | input_name = network.get_input_name(0) |
| 45 | input_tensor = network.get_io_tensor(input_name) |
| 46 | output_name = network.get_output_name(0) |
| 47 | output_tensor = network.get_io_tensor(output_name) |
| 48 | |
| 49 | input_tensor.set_data_by_copy(self.input_data) |
| 50 | for i in range(times): |
| 51 | network.forward() |
| 52 | network.wait() |
| 53 | |
| 54 | output_data = output_tensor.to_numpy() |
| 55 | self.check_correct(output_data) |
| 56 | |
| 57 | |
| 58 | class TestNetwork(TestShuffleNetCuda): |