Gian Marco Iodice | e10bddb | 2017-10-11 15:03:26 +0100 | [diff] [blame] | 1 | /* |
Michele Di Giorgio | d9eaf61 | 2020-07-08 11:12:57 +0100 | [diff] [blame] | 2 | * Copyright (c) 2017-2020 Arm Limited. |
Gian Marco Iodice | e10bddb | 2017-10-11 15:03:26 +0100 | [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" |
Gian Marco Iodice | e10bddb | 2017-10-11 15:03:26 +0100 | [diff] [blame] | 25 | #include "support/ToolchainSupport.h" |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 26 | #include "utils/CommonGraphOptions.h" |
Gian Marco Iodice | e10bddb | 2017-10-11 15:03:26 +0100 | [diff] [blame] | 27 | #include "utils/GraphUtils.h" |
| 28 | #include "utils/Utils.h" |
| 29 | |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 30 | using namespace arm_compute::utils; |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 31 | using namespace arm_compute::graph::frontend; |
Gian Marco Iodice | e10bddb | 2017-10-11 15:03:26 +0100 | [diff] [blame] | 32 | using namespace arm_compute::graph_utils; |
| 33 | |
Georgios Pinitas | 108ab0b | 2018-09-14 18:35:11 +0100 | [diff] [blame] | 34 | /** Example demonstrating how to implement VGG16's network using the Compute Library's graph API */ |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 35 | class GraphVGG16Example : public Example |
Gian Marco Iodice | e10bddb | 2017-10-11 15:03:26 +0100 | [diff] [blame] | 36 | { |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 37 | public: |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 38 | GraphVGG16Example() |
| 39 | : cmd_parser(), common_opts(cmd_parser), common_params(), graph(0, "VGG16") |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 40 | { |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 41 | } |
| 42 | bool do_setup(int argc, char **argv) override |
| 43 | { |
| 44 | // Parse arguments |
| 45 | cmd_parser.parse(argc, argv); |
Georgios Pinitas | cd60a5f | 2019-08-21 17:06:54 +0100 | [diff] [blame] | 46 | cmd_parser.validate(); |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 47 | |
| 48 | // Consume common parameters |
| 49 | common_params = consume_common_graph_parameters(common_opts); |
| 50 | |
| 51 | // Return when help menu is requested |
| 52 | if(common_params.help) |
| 53 | { |
| 54 | cmd_parser.print_help(argv[0]); |
| 55 | return false; |
| 56 | } |
| 57 | |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 58 | // Print parameter values |
| 59 | std::cout << common_params << std::endl; |
| 60 | |
| 61 | // Get trainable parameters data path |
| 62 | std::string data_path = common_params.data_path; |
Gian Marco Iodice | e10bddb | 2017-10-11 15:03:26 +0100 | [diff] [blame] | 63 | |
Georgios Pinitas | 140fdc7 | 2018-02-16 11:42:38 +0000 | [diff] [blame] | 64 | // Create a preprocessor object |
| 65 | const std::array<float, 3> mean_rgb{ { 123.68f, 116.779f, 103.939f } }; |
| 66 | std::unique_ptr<IPreprocessor> preprocessor = arm_compute::support::cpp14::make_unique<CaffePreproccessor>(mean_rgb); |
Gian Marco Iodice | e10bddb | 2017-10-11 15:03:26 +0100 | [diff] [blame] | 67 | |
Georgios Pinitas | 7d66a8e | 2018-07-17 12:28:42 +0100 | [diff] [blame] | 68 | // Create input descriptor |
Sang-Hoon Park | 11fedda | 2020-01-15 14:44:04 +0000 | [diff] [blame] | 69 | const auto operation_layout = common_params.data_layout; |
| 70 | const TensorShape tensor_shape = permute_shape(TensorShape(224U, 224U, 3U, 1U), DataLayout::NCHW, operation_layout); |
| 71 | TensorDescriptor input_descriptor = TensorDescriptor(tensor_shape, common_params.data_type).set_layout(operation_layout); |
Georgios Pinitas | 7d66a8e | 2018-07-17 12:28:42 +0100 | [diff] [blame] | 72 | |
| 73 | // Set weights trained layout |
| 74 | const DataLayout weights_layout = DataLayout::NCHW; |
| 75 | |
| 76 | // Create graph |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 77 | graph << common_params.target |
| 78 | << common_params.fast_math_hint |
Georgios Pinitas | 7d66a8e | 2018-07-17 12:28:42 +0100 | [diff] [blame] | 79 | << InputLayer(input_descriptor, get_input_accessor(common_params, std::move(preprocessor))) |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 80 | // Layer 1 |
| 81 | << ConvolutionLayer( |
| 82 | 3U, 3U, 64U, |
Georgios Pinitas | 7d66a8e | 2018-07-17 12:28:42 +0100 | [diff] [blame] | 83 | get_weights_accessor(data_path, "/cnn_data/vgg16_model/conv1_1_w.npy", weights_layout), |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 84 | get_weights_accessor(data_path, "/cnn_data/vgg16_model/conv1_1_b.npy"), |
| 85 | PadStrideInfo(1, 1, 1, 1)) |
Georgios Pinitas | 5c2fb3f | 2018-05-01 15:26:20 +0100 | [diff] [blame] | 86 | .set_name("conv1_1") |
| 87 | << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name("conv1_1/Relu") |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 88 | // Layer 2 |
| 89 | << ConvolutionLayer( |
| 90 | 3U, 3U, 64U, |
Georgios Pinitas | 7d66a8e | 2018-07-17 12:28:42 +0100 | [diff] [blame] | 91 | get_weights_accessor(data_path, "/cnn_data/vgg16_model/conv1_2_w.npy", weights_layout), |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 92 | get_weights_accessor(data_path, "/cnn_data/vgg16_model/conv1_2_b.npy"), |
| 93 | PadStrideInfo(1, 1, 1, 1)) |
Georgios Pinitas | 5c2fb3f | 2018-05-01 15:26:20 +0100 | [diff] [blame] | 94 | .set_name("conv1_2") |
| 95 | << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name("conv1_2/Relu") |
Sang-Hoon Park | 11fedda | 2020-01-15 14:44:04 +0000 | [diff] [blame] | 96 | << PoolingLayer(PoolingLayerInfo(PoolingType::MAX, 2, operation_layout, PadStrideInfo(2, 2, 0, 0))).set_name("pool1") |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 97 | // Layer 3 |
| 98 | << ConvolutionLayer( |
| 99 | 3U, 3U, 128U, |
Georgios Pinitas | 7d66a8e | 2018-07-17 12:28:42 +0100 | [diff] [blame] | 100 | get_weights_accessor(data_path, "/cnn_data/vgg16_model/conv2_1_w.npy", weights_layout), |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 101 | get_weights_accessor(data_path, "/cnn_data/vgg16_model/conv2_1_b.npy"), |
| 102 | PadStrideInfo(1, 1, 1, 1)) |
Georgios Pinitas | 5c2fb3f | 2018-05-01 15:26:20 +0100 | [diff] [blame] | 103 | .set_name("conv2_1") |
| 104 | << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name("conv2_1/Relu") |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 105 | // Layer 4 |
| 106 | << ConvolutionLayer( |
| 107 | 3U, 3U, 128U, |
Georgios Pinitas | 7d66a8e | 2018-07-17 12:28:42 +0100 | [diff] [blame] | 108 | get_weights_accessor(data_path, "/cnn_data/vgg16_model/conv2_2_w.npy", weights_layout), |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 109 | get_weights_accessor(data_path, "/cnn_data/vgg16_model/conv2_2_b.npy"), |
| 110 | PadStrideInfo(1, 1, 1, 1)) |
Georgios Pinitas | 5c2fb3f | 2018-05-01 15:26:20 +0100 | [diff] [blame] | 111 | .set_name("conv2_2") |
| 112 | << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name("conv2_2/Relu") |
Sang-Hoon Park | 11fedda | 2020-01-15 14:44:04 +0000 | [diff] [blame] | 113 | << PoolingLayer(PoolingLayerInfo(PoolingType::MAX, 2, operation_layout, PadStrideInfo(2, 2, 0, 0))).set_name("pool2") |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 114 | // Layer 5 |
| 115 | << ConvolutionLayer( |
| 116 | 3U, 3U, 256U, |
Georgios Pinitas | 7d66a8e | 2018-07-17 12:28:42 +0100 | [diff] [blame] | 117 | get_weights_accessor(data_path, "/cnn_data/vgg16_model/conv3_1_w.npy", weights_layout), |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 118 | get_weights_accessor(data_path, "/cnn_data/vgg16_model/conv3_1_b.npy"), |
| 119 | PadStrideInfo(1, 1, 1, 1)) |
Georgios Pinitas | 5c2fb3f | 2018-05-01 15:26:20 +0100 | [diff] [blame] | 120 | .set_name("conv3_1") |
| 121 | << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name("conv3_1/Relu") |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 122 | // Layer 6 |
| 123 | << ConvolutionLayer( |
| 124 | 3U, 3U, 256U, |
Georgios Pinitas | 7d66a8e | 2018-07-17 12:28:42 +0100 | [diff] [blame] | 125 | get_weights_accessor(data_path, "/cnn_data/vgg16_model/conv3_2_w.npy", weights_layout), |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 126 | get_weights_accessor(data_path, "/cnn_data/vgg16_model/conv3_2_b.npy"), |
| 127 | PadStrideInfo(1, 1, 1, 1)) |
Georgios Pinitas | 5c2fb3f | 2018-05-01 15:26:20 +0100 | [diff] [blame] | 128 | .set_name("conv3_2") |
| 129 | << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name("conv3_2/Relu") |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 130 | // Layer 7 |
| 131 | << ConvolutionLayer( |
| 132 | 3U, 3U, 256U, |
Georgios Pinitas | 7d66a8e | 2018-07-17 12:28:42 +0100 | [diff] [blame] | 133 | get_weights_accessor(data_path, "/cnn_data/vgg16_model/conv3_3_w.npy", weights_layout), |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 134 | get_weights_accessor(data_path, "/cnn_data/vgg16_model/conv3_3_b.npy"), |
| 135 | PadStrideInfo(1, 1, 1, 1)) |
Georgios Pinitas | 5c2fb3f | 2018-05-01 15:26:20 +0100 | [diff] [blame] | 136 | .set_name("conv3_3") |
| 137 | << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name("conv3_3/Relu") |
Sang-Hoon Park | 11fedda | 2020-01-15 14:44:04 +0000 | [diff] [blame] | 138 | << PoolingLayer(PoolingLayerInfo(PoolingType::MAX, 2, operation_layout, PadStrideInfo(2, 2, 0, 0))).set_name("pool3") |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 139 | // Layer 8 |
| 140 | << ConvolutionLayer( |
| 141 | 3U, 3U, 512U, |
Georgios Pinitas | 7d66a8e | 2018-07-17 12:28:42 +0100 | [diff] [blame] | 142 | get_weights_accessor(data_path, "/cnn_data/vgg16_model/conv4_1_w.npy", weights_layout), |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 143 | get_weights_accessor(data_path, "/cnn_data/vgg16_model/conv4_1_b.npy"), |
| 144 | PadStrideInfo(1, 1, 1, 1)) |
Georgios Pinitas | 5c2fb3f | 2018-05-01 15:26:20 +0100 | [diff] [blame] | 145 | .set_name("conv4_1") |
| 146 | << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name("conv4_1/Relu") |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 147 | // Layer 9 |
| 148 | << ConvolutionLayer( |
| 149 | 3U, 3U, 512U, |
Georgios Pinitas | 7d66a8e | 2018-07-17 12:28:42 +0100 | [diff] [blame] | 150 | get_weights_accessor(data_path, "/cnn_data/vgg16_model/conv4_2_w.npy", weights_layout), |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 151 | get_weights_accessor(data_path, "/cnn_data/vgg16_model/conv4_2_b.npy"), |
| 152 | PadStrideInfo(1, 1, 1, 1)) |
Georgios Pinitas | 5c2fb3f | 2018-05-01 15:26:20 +0100 | [diff] [blame] | 153 | .set_name("conv4_2") |
| 154 | << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name("conv4_2/Relu") |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 155 | // Layer 10 |
| 156 | << ConvolutionLayer( |
| 157 | 3U, 3U, 512U, |
Georgios Pinitas | 7d66a8e | 2018-07-17 12:28:42 +0100 | [diff] [blame] | 158 | get_weights_accessor(data_path, "/cnn_data/vgg16_model/conv4_3_w.npy", weights_layout), |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 159 | get_weights_accessor(data_path, "/cnn_data/vgg16_model/conv4_3_b.npy"), |
| 160 | PadStrideInfo(1, 1, 1, 1)) |
Georgios Pinitas | 5c2fb3f | 2018-05-01 15:26:20 +0100 | [diff] [blame] | 161 | .set_name("conv4_3") |
| 162 | << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name("conv4_3/Relu") |
Sang-Hoon Park | 11fedda | 2020-01-15 14:44:04 +0000 | [diff] [blame] | 163 | << PoolingLayer(PoolingLayerInfo(PoolingType::MAX, 2, operation_layout, PadStrideInfo(2, 2, 0, 0))).set_name("pool4") |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 164 | // Layer 11 |
| 165 | << ConvolutionLayer( |
| 166 | 3U, 3U, 512U, |
Georgios Pinitas | 7d66a8e | 2018-07-17 12:28:42 +0100 | [diff] [blame] | 167 | get_weights_accessor(data_path, "/cnn_data/vgg16_model/conv5_1_w.npy", weights_layout), |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 168 | get_weights_accessor(data_path, "/cnn_data/vgg16_model/conv5_1_b.npy"), |
| 169 | PadStrideInfo(1, 1, 1, 1)) |
Georgios Pinitas | 5c2fb3f | 2018-05-01 15:26:20 +0100 | [diff] [blame] | 170 | .set_name("conv5_1") |
| 171 | << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name("conv5_1/Relu") |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 172 | // Layer 12 |
| 173 | << ConvolutionLayer( |
| 174 | 3U, 3U, 512U, |
Georgios Pinitas | 7d66a8e | 2018-07-17 12:28:42 +0100 | [diff] [blame] | 175 | get_weights_accessor(data_path, "/cnn_data/vgg16_model/conv5_2_w.npy", weights_layout), |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 176 | get_weights_accessor(data_path, "/cnn_data/vgg16_model/conv5_2_b.npy"), |
| 177 | PadStrideInfo(1, 1, 1, 1)) |
Georgios Pinitas | 5c2fb3f | 2018-05-01 15:26:20 +0100 | [diff] [blame] | 178 | .set_name("conv5_2") |
| 179 | << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name("conv5_2/Relu") |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 180 | // Layer 13 |
| 181 | << ConvolutionLayer( |
| 182 | 3U, 3U, 512U, |
Georgios Pinitas | 7d66a8e | 2018-07-17 12:28:42 +0100 | [diff] [blame] | 183 | get_weights_accessor(data_path, "/cnn_data/vgg16_model/conv5_3_w.npy", weights_layout), |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 184 | get_weights_accessor(data_path, "/cnn_data/vgg16_model/conv5_3_b.npy"), |
| 185 | PadStrideInfo(1, 1, 1, 1)) |
Georgios Pinitas | 5c2fb3f | 2018-05-01 15:26:20 +0100 | [diff] [blame] | 186 | .set_name("conv5_3") |
| 187 | << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name("conv5_3/Relu") |
Sang-Hoon Park | 11fedda | 2020-01-15 14:44:04 +0000 | [diff] [blame] | 188 | << PoolingLayer(PoolingLayerInfo(PoolingType::MAX, 2, operation_layout, PadStrideInfo(2, 2, 0, 0))).set_name("pool5") |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 189 | // Layer 14 |
| 190 | << FullyConnectedLayer( |
| 191 | 4096U, |
Georgios Pinitas | 7d66a8e | 2018-07-17 12:28:42 +0100 | [diff] [blame] | 192 | get_weights_accessor(data_path, "/cnn_data/vgg16_model/fc6_w.npy", weights_layout), |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 193 | get_weights_accessor(data_path, "/cnn_data/vgg16_model/fc6_b.npy")) |
Georgios Pinitas | 5c2fb3f | 2018-05-01 15:26:20 +0100 | [diff] [blame] | 194 | .set_name("fc6") |
| 195 | << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name("Relu") |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 196 | // Layer 15 |
| 197 | << FullyConnectedLayer( |
| 198 | 4096U, |
Georgios Pinitas | 7d66a8e | 2018-07-17 12:28:42 +0100 | [diff] [blame] | 199 | get_weights_accessor(data_path, "/cnn_data/vgg16_model/fc7_w.npy", weights_layout), |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 200 | get_weights_accessor(data_path, "/cnn_data/vgg16_model/fc7_b.npy")) |
Georgios Pinitas | 5c2fb3f | 2018-05-01 15:26:20 +0100 | [diff] [blame] | 201 | .set_name("fc7") |
| 202 | << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)).set_name("Relu_1") |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 203 | // Layer 16 |
| 204 | << FullyConnectedLayer( |
| 205 | 1000U, |
Georgios Pinitas | 7d66a8e | 2018-07-17 12:28:42 +0100 | [diff] [blame] | 206 | get_weights_accessor(data_path, "/cnn_data/vgg16_model/fc8_w.npy", weights_layout), |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 207 | get_weights_accessor(data_path, "/cnn_data/vgg16_model/fc8_b.npy")) |
Georgios Pinitas | 5c2fb3f | 2018-05-01 15:26:20 +0100 | [diff] [blame] | 208 | .set_name("fc8") |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 209 | // Softmax |
Georgios Pinitas | 5c2fb3f | 2018-05-01 15:26:20 +0100 | [diff] [blame] | 210 | << SoftmaxLayer().set_name("prob") |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 211 | << OutputLayer(get_output_accessor(common_params, 5)); |
Gian Marco | c1b6e37 | 2018-02-21 18:03:26 +0000 | [diff] [blame] | 212 | |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 213 | // Finalize graph |
Georgios Pinitas | 9a8c672 | 2018-03-21 17:52:35 +0000 | [diff] [blame] | 214 | GraphConfig config; |
Georgios Pinitas | f4261ad | 2019-12-02 11:58:19 +0000 | [diff] [blame] | 215 | config.num_threads = common_params.threads; |
| 216 | config.use_tuner = common_params.enable_tuner; |
| 217 | config.tuner_mode = common_params.tuner_mode; |
| 218 | config.tuner_file = common_params.tuner_file; |
| 219 | config.convert_to_uint8 = (common_params.data_type == DataType::QASYMM8); |
Anthony Barbier | 7b607dc | 2018-07-13 15:55:24 +0100 | [diff] [blame] | 220 | |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 221 | graph.finalize(common_params.target, config); |
| 222 | |
| 223 | return true; |
Gian Marco Iodice | e10bddb | 2017-10-11 15:03:26 +0100 | [diff] [blame] | 224 | } |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 225 | void do_run() override |
Gian Marco Iodice | e10bddb | 2017-10-11 15:03:26 +0100 | [diff] [blame] | 226 | { |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 227 | // Run graph |
| 228 | graph.run(); |
Gian Marco Iodice | e10bddb | 2017-10-11 15:03:26 +0100 | [diff] [blame] | 229 | } |
| 230 | |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 231 | private: |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 232 | CommandLineParser cmd_parser; |
| 233 | CommonGraphOptions common_opts; |
| 234 | CommonGraphParams common_params; |
| 235 | Stream graph; |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 236 | }; |
Gian Marco Iodice | e10bddb | 2017-10-11 15:03:26 +0100 | [diff] [blame] | 237 | |
| 238 | /** Main program for VGG16 |
| 239 | * |
Georgios Pinitas | bdbbbe8 | 2018-11-07 16:06:47 +0000 | [diff] [blame] | 240 | * Model is based on: |
| 241 | * https://arxiv.org/abs/1409.1556 |
| 242 | * "Very Deep Convolutional Networks for Large-Scale Image Recognition" |
| 243 | * Karen Simonyan, Andrew Zisserman |
| 244 | * |
Georgios Pinitas | 588ebc5 | 2018-12-21 13:39:07 +0000 | [diff] [blame] | 245 | * Provenance: www.robots.ox.ac.uk/~vgg/software/very_deep/caffe/VGG_ILSVRC_16_layers.caffemodel |
| 246 | * |
Georgios Pinitas | 9f28b39 | 2018-07-18 20:01:53 +0100 | [diff] [blame] | 247 | * @note To list all the possible arguments execute the binary appended with the --help option |
| 248 | * |
Gian Marco Iodice | e10bddb | 2017-10-11 15:03:26 +0100 | [diff] [blame] | 249 | * @param[in] argc Number of arguments |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 250 | * @param[in] argv Arguments |
Gian Marco Iodice | e10bddb | 2017-10-11 15:03:26 +0100 | [diff] [blame] | 251 | */ |
Anthony Barbier | 6db0ff5 | 2018-01-05 10:59:12 +0000 | [diff] [blame] | 252 | int main(int argc, char **argv) |
Gian Marco Iodice | e10bddb | 2017-10-11 15:03:26 +0100 | [diff] [blame] | 253 | { |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 254 | return arm_compute::utils::run_example<GraphVGG16Example>(argc, argv); |
Gian Marco Iodice | e10bddb | 2017-10-11 15:03:26 +0100 | [diff] [blame] | 255 | } |