blob: 92dcdea5009c0a26f7e7c0b8ab7db6ebd807ac2c [file] [log] [blame]
Kaizen8938bd32017-09-28 14:38:23 +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 */
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"
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"
34
35#include <string>
36#include <vector>
37
38namespace arm_compute
39{
40namespace test
41{
42namespace validation
43{
44namespace
45{
46using CLLeNet5Model = networks::LeNet5Network<CLTensor,
47 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{
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"
59 };
60
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"
65 };
66 CLLeNet5Model network{};
67 network.init(batches);
68 network.build();
69 network.allocate();
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
78TEST_SUITE(CL)
79TEST_SUITE(SYSTEM_TESTS)
80
81TEST_CASE(LeNet5, framework::DatasetMode::PRECOMMIT)
82{
83 // Compute alexnet
84 std::vector<unsigned int> classified_labels = compute_lenet5(10, "cnn_data/mnist_data/input10.npy");
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
93TEST_SUITE_END()
94TEST_SUITE_END()
95} // namespace validation
96} // namespace test
97} // namespace arm_compute