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 | */ |
Moritz Pflanzer | d58cec0 | 2017-07-18 15:44:21 +0100 | [diff] [blame^] | 48 | #include "NEON/Accessor.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 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/NENormalizationLayer.h" |
| 55 | #include "arm_compute/runtime/NEON/functions/NEPoolingLayer.h" |
| 56 | #include "arm_compute/runtime/NEON/functions/NESoftmaxLayer.h" |
| 57 | #include "arm_compute/runtime/SubTensor.h" |
| 58 | |
| 59 | #include "model_objects/AlexNet.h" |
| 60 | |
| 61 | #include <array> |
| 62 | |
| 63 | using namespace arm_compute; |
| 64 | using namespace arm_compute::test; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 65 | using namespace arm_compute::test::validation; |
| 66 | |
| 67 | namespace |
| 68 | { |
| 69 | using NEAlexNetModel = model_objects::AlexNet<ITensor, |
| 70 | Tensor, |
| 71 | SubTensor, |
Moritz Pflanzer | d58cec0 | 2017-07-18 15:44:21 +0100 | [diff] [blame^] | 72 | Accessor, |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 73 | NEActivationLayer, |
| 74 | NEConvolutionLayer, |
| 75 | NEFullyConnectedLayer, |
| 76 | NENormalizationLayer, |
| 77 | NEPoolingLayer, |
| 78 | NESoftmaxLayer>; |
| 79 | std::vector<unsigned int> compute_alexnet(unsigned int batches, std::string input_file) |
| 80 | { |
| 81 | std::vector<std::string> weight_files = { "cnn_data/alexnet_model/conv1_w.dat", |
| 82 | "cnn_data/alexnet_model/conv2_w.dat", |
| 83 | "cnn_data/alexnet_model/conv3_w.dat", |
| 84 | "cnn_data/alexnet_model/conv4_w.dat", |
| 85 | "cnn_data/alexnet_model/conv5_w.dat", |
| 86 | "cnn_data/alexnet_model/fc6_w.dat", |
| 87 | "cnn_data/alexnet_model/fc7_w.dat", |
| 88 | "cnn_data/alexnet_model/fc8_w.dat" |
| 89 | }; |
| 90 | |
| 91 | std::vector<std::string> bias_files = { "cnn_data/alexnet_model/conv1_b.dat", |
| 92 | "cnn_data/alexnet_model/conv2_b.dat", |
| 93 | "cnn_data/alexnet_model/conv3_b.dat", |
| 94 | "cnn_data/alexnet_model/conv4_b.dat", |
| 95 | "cnn_data/alexnet_model/conv5_b.dat", |
| 96 | "cnn_data/alexnet_model/fc6_b.dat", |
| 97 | "cnn_data/alexnet_model/fc7_b.dat", |
| 98 | "cnn_data/alexnet_model/fc8_b.dat" |
| 99 | }; |
| 100 | NEAlexNetModel network{}; |
| 101 | |
| 102 | network.init_weights(batches); |
| 103 | network.build(); |
| 104 | network.allocate(); |
| 105 | network.fill(weight_files, bias_files); |
| 106 | network.feed(std::move(input_file)); |
| 107 | network.run(); |
| 108 | |
| 109 | return network.get_classifications(); |
| 110 | } |
| 111 | } // namespace |
| 112 | |
| 113 | #ifndef DOXYGEN_SKIP_THIS |
| 114 | BOOST_AUTO_TEST_SUITE(SYSTEM_TESTS) |
| 115 | BOOST_AUTO_TEST_SUITE(NEON) |
| 116 | |
| 117 | BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit")) |
| 118 | BOOST_AUTO_TEST_CASE(AlexNet) |
| 119 | { |
| 120 | // Compute alexnet |
| 121 | std::vector<unsigned int> classified_labels = compute_alexnet(1, "cnn_data/imagenet_data/shark.dat"); |
| 122 | |
| 123 | // Expected labels |
| 124 | std::vector<unsigned int> expected_labels = { 2 }; |
| 125 | |
| 126 | // Validate labels |
| 127 | validate(classified_labels, expected_labels); |
| 128 | } |
| 129 | |
| 130 | BOOST_AUTO_TEST_SUITE_END() |
| 131 | BOOST_AUTO_TEST_SUITE_END() |
Anthony Barbier | ac69aa1 | 2017-07-03 17:39:37 +0100 | [diff] [blame] | 132 | #endif /* DOXYGEN_SKIP_THIS */ |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 133 | #endif /* INTERNAL_ONLY */ |