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/NEON/functions/NEActivationLayer.h" |
| 25 | #include "arm_compute/runtime/NEON/functions/NEConvolutionLayer.h" |
SiCong Li | 86b5333 | 2017-08-23 11:02:43 +0100 | [diff] [blame] | 26 | #include "arm_compute/runtime/NEON/functions/NEDirectConvolutionLayer.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 27 | #include "arm_compute/runtime/NEON/functions/NEFullyConnectedLayer.h" |
| 28 | #include "arm_compute/runtime/NEON/functions/NENormalizationLayer.h" |
| 29 | #include "arm_compute/runtime/NEON/functions/NEPoolingLayer.h" |
| 30 | #include "arm_compute/runtime/NEON/functions/NESoftmaxLayer.h" |
| 31 | #include "arm_compute/runtime/SubTensor.h" |
SiCong Li | 86b5333 | 2017-08-23 11:02:43 +0100 | [diff] [blame] | 32 | #include "tests/NEON/Accessor.h" |
| 33 | #include "tests/framework/Asserts.h" |
| 34 | #include "tests/framework/Macros.h" |
| 35 | #include "tests/networks/AlexNetNetwork.h" |
| 36 | #include "tests/validation/Validation.h" |
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 | #include <string> |
| 39 | #include <vector> |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 40 | |
SiCong Li | 86b5333 | 2017-08-23 11:02:43 +0100 | [diff] [blame] | 41 | namespace arm_compute |
| 42 | { |
| 43 | namespace test |
| 44 | { |
| 45 | namespace validation |
| 46 | { |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 47 | namespace |
| 48 | { |
SiCong Li | 86b5333 | 2017-08-23 11:02:43 +0100 | [diff] [blame] | 49 | using NEAlexNetModel = networks::AlexNetNetwork<ITensor, |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 50 | Tensor, |
| 51 | SubTensor, |
Moritz Pflanzer | d58cec0 | 2017-07-18 15:44:21 +0100 | [diff] [blame] | 52 | Accessor, |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 53 | NEActivationLayer, |
| 54 | NEConvolutionLayer, |
SiCong Li | 86b5333 | 2017-08-23 11:02:43 +0100 | [diff] [blame] | 55 | NEDirectConvolutionLayer, |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 56 | NEFullyConnectedLayer, |
| 57 | NENormalizationLayer, |
| 58 | NEPoolingLayer, |
| 59 | NESoftmaxLayer>; |
SiCong Li | 86b5333 | 2017-08-23 11:02:43 +0100 | [diff] [blame] | 60 | std::vector<unsigned int> compute_alexnet(DataType dt, unsigned int batches, std::string input_file) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 61 | { |
SiCong Li | 86b5333 | 2017-08-23 11:02:43 +0100 | [diff] [blame] | 62 | std::vector<std::string> weight_files = { "cnn_data/alexnet_model/conv1_w.npy", |
| 63 | "cnn_data/alexnet_model/conv2_w.npy", |
| 64 | "cnn_data/alexnet_model/conv3_w.npy", |
| 65 | "cnn_data/alexnet_model/conv4_w.npy", |
| 66 | "cnn_data/alexnet_model/conv5_w.npy", |
| 67 | "cnn_data/alexnet_model/fc6_w.npy", |
| 68 | "cnn_data/alexnet_model/fc7_w.npy", |
| 69 | "cnn_data/alexnet_model/fc8_w.npy" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 70 | }; |
| 71 | |
SiCong Li | 86b5333 | 2017-08-23 11:02:43 +0100 | [diff] [blame] | 72 | std::vector<std::string> bias_files = { "cnn_data/alexnet_model/conv1_b.npy", |
| 73 | "cnn_data/alexnet_model/conv2_b.npy", |
| 74 | "cnn_data/alexnet_model/conv3_b.npy", |
| 75 | "cnn_data/alexnet_model/conv4_b.npy", |
| 76 | "cnn_data/alexnet_model/conv5_b.npy", |
| 77 | "cnn_data/alexnet_model/fc6_b.npy", |
| 78 | "cnn_data/alexnet_model/fc7_b.npy", |
| 79 | "cnn_data/alexnet_model/fc8_b.npy" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 80 | }; |
| 81 | NEAlexNetModel network{}; |
| 82 | |
SiCong Li | 86b5333 | 2017-08-23 11:02:43 +0100 | [diff] [blame] | 83 | network.init(dt, 4, batches); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 84 | network.build(); |
| 85 | network.allocate(); |
| 86 | network.fill(weight_files, bias_files); |
| 87 | network.feed(std::move(input_file)); |
| 88 | network.run(); |
| 89 | |
| 90 | return network.get_classifications(); |
| 91 | } |
| 92 | } // namespace |
| 93 | |
SiCong Li | 86b5333 | 2017-08-23 11:02:43 +0100 | [diff] [blame] | 94 | TEST_SUITE(NEON) |
| 95 | TEST_SUITE(SYSTEM_TESTS) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 96 | |
Georgios Pinitas | 898a806 | 2017-09-12 19:19:12 +0100 | [diff] [blame] | 97 | TEST_CASE(AlexNet, framework::DatasetMode::PRECOMMIT) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 98 | { |
| 99 | // Compute alexnet |
SiCong Li | 86b5333 | 2017-08-23 11:02:43 +0100 | [diff] [blame] | 100 | std::vector<unsigned int> classified_labels = compute_alexnet(DataType::F32, 1, "cnn_data/imagenet_data/cat.npy"); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 101 | |
| 102 | // Expected labels |
SiCong Li | 86b5333 | 2017-08-23 11:02:43 +0100 | [diff] [blame] | 103 | std::vector<unsigned int> expected_labels = { 281 }; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 104 | |
| 105 | // Validate labels |
| 106 | validate(classified_labels, expected_labels); |
| 107 | } |
| 108 | |
SiCong Li | 86b5333 | 2017-08-23 11:02:43 +0100 | [diff] [blame] | 109 | TEST_SUITE_END() |
| 110 | TEST_SUITE_END() |
| 111 | } // namespace validation |
| 112 | } // namespace test |
| 113 | } // namespace arm_compute |