Moritz Pflanzer | fc95ed2 | 2017-07-05 11:07:07 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017 ARM Limited. |
| 3 | * |
| 4 | * SPDX-License-Identifier: MIT |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | * of this software and associated documentation files (the "Software"), to |
| 8 | * deal in the Software without restriction, including without limitation the |
| 9 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 10 | * sell copies of the Software, and to permit persons to whom the Software is |
| 11 | * furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in all |
| 14 | * copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | * SOFTWARE. |
| 23 | */ |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 24 | #include "arm_compute/runtime/CL/functions/CLActivationLayer.h" |
| 25 | #include "arm_compute/runtime/CL/functions/CLConvolutionLayer.h" |
| 26 | #include "arm_compute/runtime/CL/functions/CLFullyConnectedLayer.h" |
| 27 | #include "arm_compute/runtime/CL/functions/CLPoolingLayer.h" |
| 28 | #include "arm_compute/runtime/CL/functions/CLSoftmaxLayer.h" |
SiCong Li | 86b5333 | 2017-08-23 11:02:43 +0100 | [diff] [blame] | 29 | #include "tests/CL/CLAccessor.h" |
| 30 | #include "tests/framework/Asserts.h" |
| 31 | #include "tests/framework/Macros.h" |
| 32 | #include "tests/networks/LeNet5Network.h" |
| 33 | #include "tests/validation/Validation.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 34 | |
SiCong Li | 86b5333 | 2017-08-23 11:02:43 +0100 | [diff] [blame] | 35 | #include <string> |
| 36 | #include <vector> |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 37 | |
SiCong Li | 86b5333 | 2017-08-23 11:02:43 +0100 | [diff] [blame] | 38 | namespace arm_compute |
| 39 | { |
| 40 | namespace test |
| 41 | { |
| 42 | namespace validation |
| 43 | { |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 44 | namespace |
| 45 | { |
SiCong Li | 86b5333 | 2017-08-23 11:02:43 +0100 | [diff] [blame] | 46 | using CLLeNet5Model = networks::LeNet5Network<CLTensor, |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 47 | CLAccessor, |
| 48 | CLActivationLayer, |
| 49 | CLConvolutionLayer, |
| 50 | CLFullyConnectedLayer, |
| 51 | CLPoolingLayer, |
| 52 | CLSoftmaxLayer>; |
| 53 | std::vector<unsigned int> compute_lenet5(unsigned int batches, std::string input_file) |
| 54 | { |
SiCong Li | 86b5333 | 2017-08-23 11:02:43 +0100 | [diff] [blame] | 55 | std::vector<std::string> weight_files = { "cnn_data/lenet_model/conv1_w.npy", |
| 56 | "cnn_data/lenet_model/conv2_w.npy", |
| 57 | "cnn_data/lenet_model/ip1_w.npy", |
| 58 | "cnn_data/lenet_model/ip2_w.npy" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 59 | }; |
| 60 | |
SiCong Li | 86b5333 | 2017-08-23 11:02:43 +0100 | [diff] [blame] | 61 | std::vector<std::string> bias_files = { "cnn_data/lenet_model/conv1_b.npy", |
| 62 | "cnn_data/lenet_model/conv2_b.npy", |
| 63 | "cnn_data/lenet_model/ip1_b.npy", |
| 64 | "cnn_data/lenet_model/ip2_b.npy" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 65 | }; |
| 66 | CLLeNet5Model network{}; |
SiCong Li | 86b5333 | 2017-08-23 11:02:43 +0100 | [diff] [blame] | 67 | network.init(batches); |
| 68 | network.build(); |
| 69 | network.allocate(); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 70 | network.fill(weight_files, bias_files); |
| 71 | network.feed(std::move(input_file)); |
| 72 | network.run(); |
| 73 | |
| 74 | return network.get_classifications(); |
| 75 | } |
| 76 | } // namespace |
| 77 | |
SiCong Li | 86b5333 | 2017-08-23 11:02:43 +0100 | [diff] [blame] | 78 | TEST_SUITE(CL) |
| 79 | TEST_SUITE(SYSTEM_TESTS) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 80 | |
SiCong Li | 86b5333 | 2017-08-23 11:02:43 +0100 | [diff] [blame] | 81 | TEST_CASE(LeNet5, framework::DatasetMode::PRECOMMIT) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 82 | { |
| 83 | // Compute alexnet |
SiCong Li | 86b5333 | 2017-08-23 11:02:43 +0100 | [diff] [blame] | 84 | std::vector<unsigned int> classified_labels = compute_lenet5(10, "cnn_data/mnist_data/input10.npy"); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 85 | |
| 86 | // Expected labels |
| 87 | std::vector<unsigned int> expected_labels = { 7, 2, 1, 0, 4, 1, 4, 9, 5, 9 }; |
| 88 | |
| 89 | // Validate labels |
| 90 | validate(classified_labels, expected_labels); |
| 91 | } |
| 92 | |
SiCong Li | 86b5333 | 2017-08-23 11:02:43 +0100 | [diff] [blame] | 93 | TEST_SUITE_END() |
| 94 | TEST_SUITE_END() |
| 95 | } // namespace validation |
| 96 | } // namespace test |
| 97 | } // namespace arm_compute |