blob: 15e16d327233ccbfa8636330893fe61cdb00a9e6 [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#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 */
48#include "CL/CLAccessor.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010049#include "validation/Validation.h"
50
51#include "arm_compute/runtime/CL/CLSubTensor.h"
52#include "arm_compute/runtime/CL/functions/CLActivationLayer.h"
53#include "arm_compute/runtime/CL/functions/CLConvolutionLayer.h"
54#include "arm_compute/runtime/CL/functions/CLFullyConnectedLayer.h"
55#include "arm_compute/runtime/CL/functions/CLNormalizationLayer.h"
56#include "arm_compute/runtime/CL/functions/CLPoolingLayer.h"
57#include "arm_compute/runtime/CL/functions/CLSoftmaxLayer.h"
58
59#include "model_objects/AlexNet.h"
60
61#include <array>
62
63using namespace arm_compute;
64using namespace arm_compute::test;
65using namespace arm_compute::test::cl;
66using namespace arm_compute::test::validation;
67
68namespace
69{
70using CLAlexNetModel = model_objects::AlexNet<ICLTensor,
71 CLTensor,
72 CLSubTensor,
73 CLAccessor,
74 CLActivationLayer,
75 CLConvolutionLayer,
76 CLFullyConnectedLayer,
77 CLNormalizationLayer,
78 CLPoolingLayer,
79 CLSoftmaxLayer>;
80std::vector<unsigned int> compute_alexnet(unsigned int batches, std::string input_file)
81{
82 std::vector<std::string> weight_files = { "cnn_data/alexnet_model/conv1_w.dat",
83 "cnn_data/alexnet_model/conv2_w.dat",
84 "cnn_data/alexnet_model/conv3_w.dat",
85 "cnn_data/alexnet_model/conv4_w.dat",
86 "cnn_data/alexnet_model/conv5_w.dat",
87 "cnn_data/alexnet_model/fc6_w.dat",
88 "cnn_data/alexnet_model/fc7_w.dat",
89 "cnn_data/alexnet_model/fc8_w.dat"
90 };
91
92 std::vector<std::string> bias_files = { "cnn_data/alexnet_model/conv1_b.dat",
93 "cnn_data/alexnet_model/conv2_b.dat",
94 "cnn_data/alexnet_model/conv3_b.dat",
95 "cnn_data/alexnet_model/conv4_b.dat",
96 "cnn_data/alexnet_model/conv5_b.dat",
97 "cnn_data/alexnet_model/fc6_b.dat",
98 "cnn_data/alexnet_model/fc7_b.dat",
99 "cnn_data/alexnet_model/fc8_b.dat"
100 };
101 CLAlexNetModel network{};
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
114BOOST_AUTO_TEST_SUITE(SYSTEM_TESTS)
115BOOST_AUTO_TEST_SUITE(CL)
116
117BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit"))
118BOOST_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
130BOOST_AUTO_TEST_SUITE_END()
131BOOST_AUTO_TEST_SUITE_END()
Anthony Barbierac69aa12017-07-03 17:39:37 +0100132#endif /* DOXYGEN_SKIP_THIS */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100133#endif /* INTERNAL_ONLY */