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 | #ifdef INTERNAL_ONLY //FIXME Delete this file before the release |
| 25 | /* |
| 26 | * Copyright (c) 2017 ARM Limited. |
| 27 | * |
| 28 | * SPDX-License-Identifier: MIT |
| 29 | * |
| 30 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 31 | * of this software and associated documentation files (the "Software"), to |
| 32 | * deal in the Software without restriction, including without limitation the |
| 33 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 34 | * sell copies of the Software, and to permit persons to whom the Software is |
| 35 | * furnished to do so, subject to the following conditions: |
| 36 | * |
| 37 | * The above copyright notice and this permission notice shall be included in all |
| 38 | * copies or substantial portions of the Software. |
| 39 | * |
| 40 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 41 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 42 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 43 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 44 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 45 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 46 | * SOFTWARE. |
| 47 | */ |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 48 | #include "NEON/NEAccessor.h" |
| 49 | #include "validation/Validation.h" |
| 50 | |
| 51 | #include "arm_compute/runtime/NEON/functions/NEActivationLayer.h" |
| 52 | #include "arm_compute/runtime/NEON/functions/NEConvolutionLayer.h" |
| 53 | #include "arm_compute/runtime/NEON/functions/NEFullyConnectedLayer.h" |
| 54 | #include "arm_compute/runtime/NEON/functions/NEPoolingLayer.h" |
| 55 | #include "arm_compute/runtime/NEON/functions/NESoftmaxLayer.h" |
| 56 | |
| 57 | #include "model_objects/LeNet5.h" |
| 58 | |
| 59 | using namespace arm_compute; |
| 60 | using namespace arm_compute::test; |
| 61 | using namespace arm_compute::test::neon; |
| 62 | using namespace arm_compute::test::validation; |
| 63 | |
| 64 | namespace |
| 65 | { |
| 66 | using NELeNet5Model = model_objects::LeNet5<Tensor, |
| 67 | NEAccessor, |
| 68 | NEActivationLayer, |
| 69 | NEConvolutionLayer, |
| 70 | NEFullyConnectedLayer, |
| 71 | NEPoolingLayer, |
| 72 | NESoftmaxLayer>; |
| 73 | std::vector<unsigned int> compute_lenet5(unsigned int batches, std::string input_file) |
| 74 | { |
| 75 | std::vector<std::string> weight_files = { "cnn_data/lenet_model/conv1_w.dat", |
| 76 | "cnn_data/lenet_model/conv2_w.dat", |
| 77 | "cnn_data/lenet_model/ip1_w.dat", |
| 78 | "cnn_data/lenet_model/ip2_w.dat" |
| 79 | }; |
| 80 | |
| 81 | std::vector<std::string> bias_files = { "cnn_data/lenet_model/conv1_b.dat", |
| 82 | "cnn_data/lenet_model/conv2_b.dat", |
| 83 | "cnn_data/lenet_model/ip1_b.dat", |
| 84 | "cnn_data/lenet_model/ip2_b.dat" |
| 85 | }; |
| 86 | NELeNet5Model network{}; |
| 87 | network.build(batches); |
| 88 | network.fill(weight_files, bias_files); |
| 89 | network.feed(std::move(input_file)); |
| 90 | network.run(); |
| 91 | |
| 92 | return network.get_classifications(); |
| 93 | } |
| 94 | } // namespace |
| 95 | |
| 96 | #ifndef DOXYGEN_SKIP_THIS |
| 97 | BOOST_AUTO_TEST_SUITE(SYSTEM_TESTS) |
| 98 | BOOST_AUTO_TEST_SUITE(NEON) |
| 99 | |
| 100 | BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit")) |
| 101 | BOOST_AUTO_TEST_CASE(LeNet5) |
| 102 | { |
| 103 | // Compute alexnet |
| 104 | std::vector<unsigned int> classified_labels = compute_lenet5(10, "cnn_data/mnist_data/input100.dat"); |
| 105 | |
| 106 | // Expected labels |
| 107 | std::vector<unsigned int> expected_labels = { 7, 2, 1, 0, 4, 1, 4, 9, 5, 9 }; |
| 108 | |
| 109 | // Validate labels |
| 110 | validate(classified_labels, expected_labels); |
| 111 | } |
| 112 | |
| 113 | BOOST_AUTO_TEST_SUITE_END() |
| 114 | BOOST_AUTO_TEST_SUITE_END() |
Anthony Barbier | ac69aa1 | 2017-07-03 17:39:37 +0100 | [diff] [blame] | 115 | #endif /* DOXYGEN_SKIP_THIS */ |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 116 | #endif /* INTERNAL_ONLY */ |