Isabella Gottardi | 9f20bda | 2017-11-03 17:16:20 +0000 | [diff] [blame] | 1 | /* |
Michele Di Giorgio | e3fba0a | 2018-02-14 14:18:01 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2018 ARM Limited. |
Isabella Gottardi | 9f20bda | 2017-11-03 17:16:20 +0000 | [diff] [blame] | 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 | */ |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 24 | #include "arm_compute/graph.h" |
Isabella Gottardi | 9f20bda | 2017-11-03 17:16:20 +0000 | [diff] [blame] | 25 | #include "support/ToolchainSupport.h" |
| 26 | #include "utils/GraphUtils.h" |
| 27 | #include "utils/Utils.h" |
| 28 | |
| 29 | #include <cstdlib> |
| 30 | |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 31 | using namespace arm_compute::utils; |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 32 | using namespace arm_compute::graph::frontend; |
Isabella Gottardi | 9f20bda | 2017-11-03 17:16:20 +0000 | [diff] [blame] | 33 | using namespace arm_compute::graph_utils; |
Isabella Gottardi | 9f20bda | 2017-11-03 17:16:20 +0000 | [diff] [blame] | 34 | |
| 35 | /** Example demonstrating how to implement VGG19's network using the Compute Library's graph API |
| 36 | * |
| 37 | * @param[in] argc Number of arguments |
Isabella Gottardi | 88d5b22 | 2018-04-06 12:24:55 +0100 | [diff] [blame] | 38 | * @param[in] argv Arguments ( [optional] Target (0 = NEON, 1 = OpenCL, 2 = OpenCL with Tuner), [optional] Path to the weights folder, [optional] image, [optional] labels, [optional] Fast math for convolution layer (0 = DISABLED, 1 = ENABLED) ) |
Isabella Gottardi | 9f20bda | 2017-11-03 17:16:20 +0000 | [diff] [blame] | 39 | */ |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 40 | class GraphVGG19Example : public Example |
Isabella Gottardi | 9f20bda | 2017-11-03 17:16:20 +0000 | [diff] [blame] | 41 | { |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 42 | public: |
| 43 | void do_setup(int argc, char **argv) override |
| 44 | { |
| 45 | std::string data_path; /* Path to the trainable data */ |
| 46 | std::string image; /* Image data */ |
| 47 | std::string label; /* Label data */ |
Isabella Gottardi | 9f20bda | 2017-11-03 17:16:20 +0000 | [diff] [blame] | 48 | |
Georgios Pinitas | 140fdc7 | 2018-02-16 11:42:38 +0000 | [diff] [blame] | 49 | // Create a preprocessor object |
| 50 | const std::array<float, 3> mean_rgb{ { 123.68f, 116.779f, 103.939f } }; |
| 51 | std::unique_ptr<IPreprocessor> preprocessor = arm_compute::support::cpp14::make_unique<CaffePreproccessor>(mean_rgb); |
Isabella Gottardi | 9f20bda | 2017-11-03 17:16:20 +0000 | [diff] [blame] | 52 | |
Michele Di Giorgio | e3fba0a | 2018-02-14 14:18:01 +0000 | [diff] [blame] | 53 | // Set target. 0 (NEON), 1 (OpenCL), 2 (OpenCL with Tuner). By default it is NEON |
Giorgio Arena | 59631a1 | 2018-05-02 13:59:04 +0100 | [diff] [blame] | 54 | const int target = argc > 1 ? std::strtol(argv[1], nullptr, 10) : 0; |
| 55 | Target target_hint = set_target_hint(target); |
| 56 | FastMathHint fast_math_hint = FastMathHint::DISABLED; |
| 57 | const bool is_opencl = target_hint == Target::CL; |
Gian Marco Iodice | 1ed442a | 2018-04-11 10:58:31 +0100 | [diff] [blame] | 58 | |
| 59 | ConvolutionMethod first_convolution3x3_hint = is_opencl ? ConvolutionMethod::DIRECT : ConvolutionMethod::GEMM; |
| 60 | ConvolutionMethod convolution3x3_hint = ConvolutionMethod::DEFAULT; |
Gian Marco | bfa3b52 | 2017-12-12 10:08:38 +0000 | [diff] [blame] | 61 | |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 62 | // Parse arguments |
| 63 | if(argc < 2) |
| 64 | { |
| 65 | // Print help |
Giorgio Arena | 59631a1 | 2018-05-02 13:59:04 +0100 | [diff] [blame] | 66 | std::cout << "Usage: " << argv[0] << " [target] [path_to_data] [image] [labels] [fast_math_hint]\n\n"; |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 67 | std::cout << "No data folder provided: using random values\n\n"; |
| 68 | } |
| 69 | else if(argc == 2) |
| 70 | { |
Giorgio Arena | 59631a1 | 2018-05-02 13:59:04 +0100 | [diff] [blame] | 71 | std::cout << "Usage: " << argv[0] << " " << argv[1] << " [path_to_data] [image] [labels] [fast_math_hint]\n\n"; |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 72 | std::cout << "No data folder provided: using random values\n\n"; |
| 73 | } |
| 74 | else if(argc == 3) |
| 75 | { |
| 76 | data_path = argv[2]; |
Giorgio Arena | 59631a1 | 2018-05-02 13:59:04 +0100 | [diff] [blame] | 77 | std::cout << "Usage: " << argv[0] << " " << argv[1] << " " << argv[2] << " [image] [labels] [fast_math_hint]\n\n"; |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 78 | std::cout << "No image provided: using random values\n\n"; |
| 79 | } |
| 80 | else if(argc == 4) |
| 81 | { |
| 82 | data_path = argv[2]; |
| 83 | image = argv[3]; |
Giorgio Arena | 59631a1 | 2018-05-02 13:59:04 +0100 | [diff] [blame] | 84 | std::cout << "Usage: " << argv[0] << " " << argv[1] << " " << argv[2] << " " << argv[3] << " [labels] [fast_math_hint]\n\n"; |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 85 | std::cout << "No text file with labels provided: skipping output accessor\n\n"; |
| 86 | } |
Giorgio Arena | 59631a1 | 2018-05-02 13:59:04 +0100 | [diff] [blame] | 87 | else if(argc == 5) |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 88 | { |
| 89 | data_path = argv[2]; |
| 90 | image = argv[3]; |
| 91 | label = argv[4]; |
Giorgio Arena | 59631a1 | 2018-05-02 13:59:04 +0100 | [diff] [blame] | 92 | std::cout << "Usage: " << argv[0] << " " << argv[1] << " " << argv[2] << " " << argv[3] << " " << argv[4] << " [fast_math_hint]\n\n"; |
| 93 | std::cout << "No fast math info provided: disabling fast math\n\n"; |
| 94 | } |
| 95 | else |
| 96 | { |
| 97 | data_path = argv[2]; |
| 98 | image = argv[3]; |
| 99 | label = argv[4]; |
| 100 | fast_math_hint = (std::strtol(argv[5], nullptr, 1) == 0) ? FastMathHint::DISABLED : FastMathHint::ENABLED; |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | graph << target_hint |
Gian Marco Iodice | 1ed442a | 2018-04-11 10:58:31 +0100 | [diff] [blame] | 104 | << first_convolution3x3_hint |
Giorgio Arena | 59631a1 | 2018-05-02 13:59:04 +0100 | [diff] [blame] | 105 | << fast_math_hint |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 106 | << InputLayer(TensorDescriptor(TensorShape(224U, 224U, 3U, 1U), DataType::F32), |
| 107 | get_input_accessor(image, std::move(preprocessor))) |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 108 | // Layer 1 |
| 109 | << ConvolutionLayer( |
| 110 | 3U, 3U, 64U, |
| 111 | get_weights_accessor(data_path, "/cnn_data/vgg19_model/conv1_1_w.npy"), |
| 112 | get_weights_accessor(data_path, "/cnn_data/vgg19_model/conv1_1_b.npy"), |
| 113 | PadStrideInfo(1, 1, 1, 1)) |
Georgios Pinitas | 5c2fb3f | 2018-05-01 15:26:20 +0100 | [diff] [blame] | 114 | .set_name("conv1_1") |
| 115 | << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name("conv1_1/Relu") |
Gian Marco Iodice | 1ed442a | 2018-04-11 10:58:31 +0100 | [diff] [blame] | 116 | << convolution3x3_hint |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 117 | << ConvolutionLayer( |
| 118 | 3U, 3U, 64U, |
| 119 | get_weights_accessor(data_path, "/cnn_data/vgg19_model/conv1_2_w.npy"), |
| 120 | get_weights_accessor(data_path, "/cnn_data/vgg19_model/conv1_2_b.npy"), |
| 121 | PadStrideInfo(1, 1, 1, 1)) |
Georgios Pinitas | 5c2fb3f | 2018-05-01 15:26:20 +0100 | [diff] [blame] | 122 | .set_name("conv1_2") |
| 123 | << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name("conv1_2/Relu") |
| 124 | << PoolingLayer(PoolingLayerInfo(PoolingType::MAX, 2, PadStrideInfo(2, 2, 0, 0))).set_name("pool1") |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 125 | // Layer 2 |
| 126 | << ConvolutionLayer( |
| 127 | 3U, 3U, 128U, |
| 128 | get_weights_accessor(data_path, "/cnn_data/vgg19_model/conv2_1_w.npy"), |
| 129 | get_weights_accessor(data_path, "/cnn_data/vgg19_model/conv2_1_b.npy"), |
| 130 | PadStrideInfo(1, 1, 1, 1)) |
Georgios Pinitas | 5c2fb3f | 2018-05-01 15:26:20 +0100 | [diff] [blame] | 131 | .set_name("conv2_1") |
| 132 | << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name("conv2_1/Relu") |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 133 | << ConvolutionLayer( |
| 134 | 3U, 3U, 128U, |
| 135 | get_weights_accessor(data_path, "/cnn_data/vgg19_model/conv2_2_w.npy"), |
| 136 | get_weights_accessor(data_path, "/cnn_data/vgg19_model/conv2_2_b.npy"), |
| 137 | PadStrideInfo(1, 1, 1, 1)) |
Georgios Pinitas | 5c2fb3f | 2018-05-01 15:26:20 +0100 | [diff] [blame] | 138 | .set_name("conv2_2") |
| 139 | << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name("conv2_2/Relu") |
| 140 | << PoolingLayer(PoolingLayerInfo(PoolingType::MAX, 2, PadStrideInfo(2, 2, 0, 0))).set_name("pool2") |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 141 | // Layer 3 |
| 142 | << ConvolutionLayer( |
| 143 | 3U, 3U, 256U, |
| 144 | get_weights_accessor(data_path, "/cnn_data/vgg19_model/conv3_1_w.npy"), |
| 145 | get_weights_accessor(data_path, "/cnn_data/vgg19_model/conv3_1_b.npy"), |
| 146 | PadStrideInfo(1, 1, 1, 1)) |
Georgios Pinitas | 5c2fb3f | 2018-05-01 15:26:20 +0100 | [diff] [blame] | 147 | .set_name("conv3_1") |
| 148 | << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name("conv3_1/Relu") |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 149 | << ConvolutionLayer( |
| 150 | 3U, 3U, 256U, |
| 151 | get_weights_accessor(data_path, "/cnn_data/vgg19_model/conv3_2_w.npy"), |
| 152 | get_weights_accessor(data_path, "/cnn_data/vgg19_model/conv3_2_b.npy"), |
| 153 | PadStrideInfo(1, 1, 1, 1)) |
Georgios Pinitas | 5c2fb3f | 2018-05-01 15:26:20 +0100 | [diff] [blame] | 154 | .set_name("conv3_2") |
| 155 | << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name("conv3_2/Relu") |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 156 | << ConvolutionLayer( |
| 157 | 3U, 3U, 256U, |
| 158 | get_weights_accessor(data_path, "/cnn_data/vgg19_model/conv3_3_w.npy"), |
| 159 | get_weights_accessor(data_path, "/cnn_data/vgg19_model/conv3_3_b.npy"), |
| 160 | PadStrideInfo(1, 1, 1, 1)) |
Georgios Pinitas | 5c2fb3f | 2018-05-01 15:26:20 +0100 | [diff] [blame] | 161 | .set_name("conv3_3") |
| 162 | << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name("conv3_3/Relu") |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 163 | << ConvolutionLayer( |
| 164 | 3U, 3U, 256U, |
| 165 | get_weights_accessor(data_path, "/cnn_data/vgg19_model/conv3_4_w.npy"), |
| 166 | get_weights_accessor(data_path, "/cnn_data/vgg19_model/conv3_4_b.npy"), |
| 167 | PadStrideInfo(1, 1, 1, 1)) |
Georgios Pinitas | 5c2fb3f | 2018-05-01 15:26:20 +0100 | [diff] [blame] | 168 | .set_name("conv3_4") |
| 169 | << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name("conv3_4/Relu") |
| 170 | << PoolingLayer(PoolingLayerInfo(PoolingType::MAX, 2, PadStrideInfo(2, 2, 0, 0))).set_name("pool3") |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 171 | // Layer 4 |
| 172 | << ConvolutionLayer( |
| 173 | 3U, 3U, 512U, |
| 174 | get_weights_accessor(data_path, "/cnn_data/vgg19_model/conv4_1_w.npy"), |
| 175 | get_weights_accessor(data_path, "/cnn_data/vgg19_model/conv4_1_b.npy"), |
| 176 | PadStrideInfo(1, 1, 1, 1)) |
Georgios Pinitas | 5c2fb3f | 2018-05-01 15:26:20 +0100 | [diff] [blame] | 177 | .set_name("conv4_1") |
| 178 | << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name("conv4_1/Relu") |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 179 | << ConvolutionLayer( |
| 180 | 3U, 3U, 512U, |
| 181 | get_weights_accessor(data_path, "/cnn_data/vgg19_model/conv4_2_w.npy"), |
| 182 | get_weights_accessor(data_path, "/cnn_data/vgg19_model/conv4_2_b.npy"), |
| 183 | PadStrideInfo(1, 1, 1, 1)) |
Georgios Pinitas | 5c2fb3f | 2018-05-01 15:26:20 +0100 | [diff] [blame] | 184 | .set_name("conv4_2") |
| 185 | << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name("conv4_2/Relu") |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 186 | << ConvolutionLayer( |
| 187 | 3U, 3U, 512U, |
| 188 | get_weights_accessor(data_path, "/cnn_data/vgg19_model/conv4_3_w.npy"), |
| 189 | get_weights_accessor(data_path, "/cnn_data/vgg19_model/conv4_3_b.npy"), |
| 190 | PadStrideInfo(1, 1, 1, 1)) |
Georgios Pinitas | 5c2fb3f | 2018-05-01 15:26:20 +0100 | [diff] [blame] | 191 | .set_name("conv4_3") |
| 192 | << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name("conv4_3/Relu") |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 193 | << ConvolutionLayer( |
| 194 | 3U, 3U, 512U, |
| 195 | get_weights_accessor(data_path, "/cnn_data/vgg19_model/conv4_4_w.npy"), |
| 196 | get_weights_accessor(data_path, "/cnn_data/vgg19_model/conv4_4_b.npy"), |
| 197 | PadStrideInfo(1, 1, 1, 1)) |
Georgios Pinitas | 5c2fb3f | 2018-05-01 15:26:20 +0100 | [diff] [blame] | 198 | .set_name("conv4_4") |
| 199 | << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name("conv4_4/Relu") |
| 200 | << PoolingLayer(PoolingLayerInfo(PoolingType::MAX, 2, PadStrideInfo(2, 2, 0, 0))).set_name("pool4") |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 201 | // Layer 5 |
| 202 | << ConvolutionLayer( |
| 203 | 3U, 3U, 512U, |
| 204 | get_weights_accessor(data_path, "/cnn_data/vgg19_model/conv5_1_w.npy"), |
| 205 | get_weights_accessor(data_path, "/cnn_data/vgg19_model/conv5_1_b.npy"), |
| 206 | PadStrideInfo(1, 1, 1, 1)) |
Georgios Pinitas | 5c2fb3f | 2018-05-01 15:26:20 +0100 | [diff] [blame] | 207 | .set_name("conv5_1") |
| 208 | << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name("conv5_1/Relu") |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 209 | << ConvolutionLayer( |
| 210 | 3U, 3U, 512U, |
| 211 | get_weights_accessor(data_path, "/cnn_data/vgg19_model/conv5_2_w.npy"), |
| 212 | get_weights_accessor(data_path, "/cnn_data/vgg19_model/conv5_2_b.npy"), |
| 213 | PadStrideInfo(1, 1, 1, 1)) |
Georgios Pinitas | 5c2fb3f | 2018-05-01 15:26:20 +0100 | [diff] [blame] | 214 | .set_name("conv5_2") |
| 215 | << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name("conv5_2/Relu") |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 216 | << ConvolutionLayer( |
| 217 | 3U, 3U, 512U, |
| 218 | get_weights_accessor(data_path, "/cnn_data/vgg19_model/conv5_3_w.npy"), |
| 219 | get_weights_accessor(data_path, "/cnn_data/vgg19_model/conv5_3_b.npy"), |
| 220 | PadStrideInfo(1, 1, 1, 1)) |
Georgios Pinitas | 5c2fb3f | 2018-05-01 15:26:20 +0100 | [diff] [blame] | 221 | .set_name("conv5_3") |
| 222 | << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name("conv5_3/Relu") |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 223 | << ConvolutionLayer( |
| 224 | 3U, 3U, 512U, |
| 225 | get_weights_accessor(data_path, "/cnn_data/vgg19_model/conv5_4_w.npy"), |
| 226 | get_weights_accessor(data_path, "/cnn_data/vgg19_model/conv5_4_b.npy"), |
| 227 | PadStrideInfo(1, 1, 1, 1)) |
Georgios Pinitas | 5c2fb3f | 2018-05-01 15:26:20 +0100 | [diff] [blame] | 228 | .set_name("conv5_4") |
| 229 | << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name("conv5_4/Relu") |
| 230 | << PoolingLayer(PoolingLayerInfo(PoolingType::MAX, 2, PadStrideInfo(2, 2, 0, 0))).set_name("pool5") |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 231 | // Layer 6 |
| 232 | << FullyConnectedLayer( |
| 233 | 4096U, |
| 234 | get_weights_accessor(data_path, "/cnn_data/vgg19_model/fc6_w.npy"), |
| 235 | get_weights_accessor(data_path, "/cnn_data/vgg19_model/fc6_b.npy")) |
Georgios Pinitas | 5c2fb3f | 2018-05-01 15:26:20 +0100 | [diff] [blame] | 236 | .set_name("fc6") |
| 237 | << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name("Relu") |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 238 | // Layer 7 |
| 239 | << FullyConnectedLayer( |
| 240 | 4096U, |
| 241 | get_weights_accessor(data_path, "/cnn_data/vgg19_model/fc7_w.npy"), |
| 242 | get_weights_accessor(data_path, "/cnn_data/vgg19_model/fc7_b.npy")) |
Georgios Pinitas | 5c2fb3f | 2018-05-01 15:26:20 +0100 | [diff] [blame] | 243 | .set_name("fc7") |
| 244 | << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name("Relu_1") |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 245 | // Layer 8 |
| 246 | << FullyConnectedLayer( |
| 247 | 1000U, |
| 248 | get_weights_accessor(data_path, "/cnn_data/vgg19_model/fc8_w.npy"), |
| 249 | get_weights_accessor(data_path, "/cnn_data/vgg19_model/fc8_b.npy")) |
Georgios Pinitas | 5c2fb3f | 2018-05-01 15:26:20 +0100 | [diff] [blame] | 250 | .set_name("fc8") |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 251 | // Softmax |
Georgios Pinitas | 5c2fb3f | 2018-05-01 15:26:20 +0100 | [diff] [blame] | 252 | << SoftmaxLayer().set_name("prob") |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 253 | << OutputLayer(get_output_accessor(label, 5)); |
Gian Marco | c1b6e37 | 2018-02-21 18:03:26 +0000 | [diff] [blame] | 254 | |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 255 | // Finalize graph |
Georgios Pinitas | 9a8c672 | 2018-03-21 17:52:35 +0000 | [diff] [blame] | 256 | GraphConfig config; |
Georgios Pinitas | 3d1489d | 2018-05-03 20:47:16 +0100 | [diff] [blame] | 257 | config.use_tuner = (target == 2); |
Georgios Pinitas | 9a8c672 | 2018-03-21 17:52:35 +0000 | [diff] [blame] | 258 | graph.finalize(target_hint, config); |
Isabella Gottardi | 9f20bda | 2017-11-03 17:16:20 +0000 | [diff] [blame] | 259 | } |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 260 | void do_run() override |
Isabella Gottardi | 9f20bda | 2017-11-03 17:16:20 +0000 | [diff] [blame] | 261 | { |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 262 | // Run graph |
| 263 | graph.run(); |
Isabella Gottardi | 9f20bda | 2017-11-03 17:16:20 +0000 | [diff] [blame] | 264 | } |
| 265 | |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 266 | private: |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 267 | Stream graph{ 0, "VGG19" }; |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 268 | }; |
Isabella Gottardi | 9f20bda | 2017-11-03 17:16:20 +0000 | [diff] [blame] | 269 | |
| 270 | /** Main program for VGG19 |
| 271 | * |
| 272 | * @param[in] argc Number of arguments |
Isabella Gottardi | 88d5b22 | 2018-04-06 12:24:55 +0100 | [diff] [blame] | 273 | * @param[in] argv Arguments ( [optional] Target (0 = NEON, 1 = OpenCL, 2 = OpenCL with Tuner), [optional] Path to the weights folder, [optional] image, [optional] labels, [optional] Fast math for convolution layer (0 = DISABLED, 1 = ENABLED) ) |
Isabella Gottardi | 9f20bda | 2017-11-03 17:16:20 +0000 | [diff] [blame] | 274 | */ |
Anthony Barbier | 6db0ff5 | 2018-01-05 10:59:12 +0000 | [diff] [blame] | 275 | int main(int argc, char **argv) |
Isabella Gottardi | 9f20bda | 2017-11-03 17:16:20 +0000 | [diff] [blame] | 276 | { |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 277 | return arm_compute::utils::run_example<GraphVGG19Example>(argc, argv); |
Isabella Gottardi | 9f20bda | 2017-11-03 17:16:20 +0000 | [diff] [blame] | 278 | } |