blob: 92dcdea5009c0a26f7e7c0b8ab7db6ebd807ac2c [file] [log] [blame]
Moritz Pflanzerfc95ed22017-07-05 11:07:07 +01001/*
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 Barbier6ff3b192017-09-04 18:44:23 +010024#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 Li86b53332017-08-23 11:02:43 +010029#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 Barbier6ff3b192017-09-04 18:44:23 +010034
SiCong Li86b53332017-08-23 11:02:43 +010035#include <string>
36#include <vector>
Anthony Barbier6ff3b192017-09-04 18:44:23 +010037
SiCong Li86b53332017-08-23 11:02:43 +010038namespace arm_compute
39{
40namespace test
41{
42namespace validation
43{
Anthony Barbier6ff3b192017-09-04 18:44:23 +010044namespace
45{
SiCong Li86b53332017-08-23 11:02:43 +010046using CLLeNet5Model = networks::LeNet5Network<CLTensor,
Anthony Barbier6ff3b192017-09-04 18:44:23 +010047 CLAccessor,
48 CLActivationLayer,
49 CLConvolutionLayer,
50 CLFullyConnectedLayer,
51 CLPoolingLayer,
52 CLSoftmaxLayer>;
53std::vector<unsigned int> compute_lenet5(unsigned int batches, std::string input_file)
54{
SiCong Li86b53332017-08-23 11:02:43 +010055 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 Barbier6ff3b192017-09-04 18:44:23 +010059 };
60
SiCong Li86b53332017-08-23 11:02:43 +010061 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 Barbier6ff3b192017-09-04 18:44:23 +010065 };
66 CLLeNet5Model network{};
SiCong Li86b53332017-08-23 11:02:43 +010067 network.init(batches);
68 network.build();
69 network.allocate();
Anthony Barbier6ff3b192017-09-04 18:44:23 +010070 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 Li86b53332017-08-23 11:02:43 +010078TEST_SUITE(CL)
79TEST_SUITE(SYSTEM_TESTS)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010080
SiCong Li86b53332017-08-23 11:02:43 +010081TEST_CASE(LeNet5, framework::DatasetMode::PRECOMMIT)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010082{
83 // Compute alexnet
SiCong Li86b53332017-08-23 11:02:43 +010084 std::vector<unsigned int> classified_labels = compute_lenet5(10, "cnn_data/mnist_data/input10.npy");
Anthony Barbier6ff3b192017-09-04 18:44:23 +010085
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 Li86b53332017-08-23 11:02:43 +010093TEST_SUITE_END()
94TEST_SUITE_END()
95} // namespace validation
96} // namespace test
97} // namespace arm_compute