Georgios Pinitas | 652bde5 | 2018-01-10 15:33:28 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017-2018 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/graph/Graph.h" |
| 25 | #include "arm_compute/graph/Nodes.h" |
| 26 | #include "arm_compute/graph/SubGraph.h" |
| 27 | #include "support/ToolchainSupport.h" |
| 28 | #include "utils/GraphUtils.h" |
| 29 | #include "utils/Utils.h" |
| 30 | |
| 31 | #include <cstdlib> |
| 32 | #include <tuple> |
| 33 | |
| 34 | using namespace arm_compute::utils; |
| 35 | using namespace arm_compute::graph; |
| 36 | using namespace arm_compute::graph_utils; |
| 37 | |
| 38 | /** Example demonstrating how to implement InceptionV3's network using the Compute Library's graph API |
| 39 | * |
| 40 | * @param[in] argc Number of arguments |
| 41 | * @param[in] argv Arguments ( [optional] Path to the weights folder, [optional] image, [optional] labels ) |
| 42 | */ |
| 43 | class InceptionV3Example : public Example |
| 44 | { |
| 45 | public: |
| 46 | void do_setup(int argc, char **argv) override |
| 47 | { |
| 48 | std::string data_path; /* Path to the trainable data */ |
| 49 | std::string image; /* Image data */ |
| 50 | std::string label; /* Label data */ |
| 51 | |
| 52 | constexpr float mean = 0.f; /* Mean value to subtract from the channels */ |
| 53 | constexpr float std = 255.f; /* Standard deviation value to divide from the channels */ |
| 54 | |
| 55 | // Set target. 0 (NEON), 1 (OpenCL). By default it is NEON |
Gian Marco | 2d40555 | 2018-02-05 08:54:54 +0000 | [diff] [blame] | 56 | TargetHint target_hint = set_target_hint(argc > 1 ? std::strtol(argv[1], nullptr, 10) : 0); |
Georgios Pinitas | 652bde5 | 2018-01-10 15:33:28 +0000 | [diff] [blame] | 57 | |
| 58 | // Parse arguments |
| 59 | if(argc < 2) |
| 60 | { |
| 61 | // Print help |
| 62 | std::cout << "Usage: " << argv[0] << " [target] [path_to_data] [image] [labels]\n\n"; |
| 63 | std::cout << "No data folder provided: using random values\n\n"; |
| 64 | } |
| 65 | else if(argc == 2) |
| 66 | { |
| 67 | std::cout << "Usage: " << argv[0] << " " << argv[1] << " [path_to_data] [image] [labels]\n\n"; |
| 68 | std::cout << "No data folder provided: using random values\n\n"; |
| 69 | } |
| 70 | else if(argc == 3) |
| 71 | { |
| 72 | data_path = argv[2]; |
| 73 | std::cout << "Usage: " << argv[0] << " " << argv[1] << " " << argv[2] << " [image] [labels]\n\n"; |
| 74 | std::cout << "No image provided: using random values\n\n"; |
| 75 | } |
| 76 | else if(argc == 4) |
| 77 | { |
| 78 | data_path = argv[2]; |
| 79 | image = argv[3]; |
| 80 | std::cout << "Usage: " << argv[0] << " " << argv[1] << " " << argv[2] << " " << argv[3] << " [labels]\n\n"; |
| 81 | std::cout << "No text file with labels provided: skipping output accessor\n\n"; |
| 82 | } |
| 83 | else |
| 84 | { |
| 85 | data_path = argv[2]; |
| 86 | image = argv[3]; |
| 87 | label = argv[4]; |
| 88 | } |
| 89 | |
Gian Marco | 2d40555 | 2018-02-05 08:54:54 +0000 | [diff] [blame] | 90 | graph << target_hint << Tensor(TensorInfo(TensorShape(299U, 299U, 3U, 1U), 1, DataType::F32), |
| 91 | get_input_accessor(image, |
| 92 | mean, mean, mean, |
| 93 | std, std, std, false /* Do not convert to BGR */)) |
Georgios Pinitas | 652bde5 | 2018-01-10 15:33:28 +0000 | [diff] [blame] | 94 | |
| 95 | << ConvolutionLayer(3U, 3U, 32U, |
| 96 | get_weights_accessor(data_path, "/cnn_data/inceptionv3_model/Conv2d_1a_3x3_weights.npy"), |
| 97 | std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(2, 2, 0, 0)) |
| 98 | << BatchNormalizationLayer(get_weights_accessor(data_path, |
| 99 | "/cnn_data/inceptionv3_model/Conv2d_1a_3x3_BatchNorm_moving_mean.npy"), |
| 100 | get_weights_accessor(data_path, |
| 101 | "/cnn_data/inceptionv3_model/Conv2d_1a_3x3_BatchNorm_moving_variance.npy"), |
| 102 | get_random_accessor(1.f, 1.f), get_weights_accessor(data_path, |
| 103 | "/cnn_data/inceptionv3_model/Conv2d_1a_3x3_BatchNorm_beta.npy"), |
Giorgio Arena | 1167487 | 2018-02-07 15:38:12 +0000 | [diff] [blame] | 104 | 0.001f, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)) |
Georgios Pinitas | 652bde5 | 2018-01-10 15:33:28 +0000 | [diff] [blame] | 105 | |
| 106 | << ConvolutionLayer(3U, 3U, 32U, |
| 107 | get_weights_accessor(data_path, "/cnn_data/inceptionv3_model/Conv2d_2a_3x3_weights.npy"), |
| 108 | std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 0, 0)) |
| 109 | << BatchNormalizationLayer(get_weights_accessor(data_path, |
| 110 | "/cnn_data/inceptionv3_model/Conv2d_2a_3x3_BatchNorm_moving_mean.npy"), |
| 111 | get_weights_accessor(data_path, |
| 112 | "/cnn_data/inceptionv3_model/Conv2d_2a_3x3_BatchNorm_moving_variance.npy"), |
| 113 | get_random_accessor(1.f, 1.f), get_weights_accessor(data_path, |
| 114 | "/cnn_data/inceptionv3_model/Conv2d_2a_3x3_BatchNorm_beta.npy"), |
Giorgio Arena | 1167487 | 2018-02-07 15:38:12 +0000 | [diff] [blame] | 115 | 0.001f, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)) |
Georgios Pinitas | 652bde5 | 2018-01-10 15:33:28 +0000 | [diff] [blame] | 116 | |
| 117 | << ConvolutionLayer(3U, 3U, 64U, |
| 118 | get_weights_accessor(data_path, "/cnn_data/inceptionv3_model/Conv2d_2b_3x3_weights.npy"), |
| 119 | std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 1, 1)) |
| 120 | << BatchNormalizationLayer(get_weights_accessor(data_path, |
| 121 | "/cnn_data/inceptionv3_model/Conv2d_2b_3x3_BatchNorm_moving_mean.npy"), |
| 122 | get_weights_accessor(data_path, |
| 123 | "/cnn_data/inceptionv3_model/Conv2d_2b_3x3_BatchNorm_moving_variance.npy"), |
| 124 | get_random_accessor(1.f, 1.f), get_weights_accessor(data_path, |
| 125 | "/cnn_data/inceptionv3_model/Conv2d_2b_3x3_BatchNorm_beta.npy"), |
Giorgio Arena | 1167487 | 2018-02-07 15:38:12 +0000 | [diff] [blame] | 126 | 0.001f, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)) |
Georgios Pinitas | 652bde5 | 2018-01-10 15:33:28 +0000 | [diff] [blame] | 127 | |
| 128 | << PoolingLayer(PoolingLayerInfo(PoolingType::MAX, 3, PadStrideInfo(2, 2, 0, 0, DimensionRoundingType::CEIL))) |
| 129 | |
| 130 | << ConvolutionLayer(1U, 1U, 80U, |
| 131 | get_weights_accessor(data_path, "/cnn_data/inceptionv3_model/Conv2d_3b_1x1_weights.npy"), |
| 132 | std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 0, 0)) |
| 133 | << BatchNormalizationLayer(get_weights_accessor(data_path, |
| 134 | "/cnn_data/inceptionv3_model/Conv2d_3b_1x1_BatchNorm_moving_mean.npy"), |
| 135 | get_weights_accessor(data_path, |
| 136 | "/cnn_data/inceptionv3_model/Conv2d_3b_1x1_BatchNorm_moving_variance.npy"), |
| 137 | get_random_accessor(1.f, 1.f), get_weights_accessor(data_path, |
| 138 | "/cnn_data/inceptionv3_model/Conv2d_3b_1x1_BatchNorm_beta.npy"), |
Giorgio Arena | 1167487 | 2018-02-07 15:38:12 +0000 | [diff] [blame] | 139 | 0.001f, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)) |
Georgios Pinitas | 652bde5 | 2018-01-10 15:33:28 +0000 | [diff] [blame] | 140 | |
| 141 | << ConvolutionLayer(3U, 3U, 192U, |
| 142 | get_weights_accessor(data_path, "/cnn_data/inceptionv3_model/Conv2d_4a_3x3_weights.npy"), |
| 143 | std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), PadStrideInfo(1, 1, 0, 0)) |
| 144 | << BatchNormalizationLayer(get_weights_accessor(data_path, |
| 145 | "/cnn_data/inceptionv3_model/Conv2d_4a_3x3_BatchNorm_moving_mean.npy"), |
| 146 | get_weights_accessor(data_path, |
| 147 | "/cnn_data/inceptionv3_model/Conv2d_4a_3x3_BatchNorm_moving_variance.npy"), |
| 148 | get_random_accessor(1.f, 1.f), get_weights_accessor(data_path, |
| 149 | "/cnn_data/inceptionv3_model/Conv2d_4a_3x3_BatchNorm_beta.npy"), |
Giorgio Arena | 1167487 | 2018-02-07 15:38:12 +0000 | [diff] [blame] | 150 | 0.001f, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)) |
Georgios Pinitas | 652bde5 | 2018-01-10 15:33:28 +0000 | [diff] [blame] | 151 | |
| 152 | << PoolingLayer(PoolingLayerInfo(PoolingType::MAX, 3, PadStrideInfo(2, 2, 0, 0, DimensionRoundingType::CEIL))) |
| 153 | |
| 154 | << get_inception_node_A(data_path, "Mixed_5b", 64U, std::make_tuple(48U, 64U), std::make_tuple(64U, 96U, 96U), |
| 155 | 32U) |
| 156 | << get_inception_node_A(data_path, "Mixed_5c", 64U, std::make_tuple(48U, 64U), std::make_tuple(64U, 96U, 96U), |
| 157 | 64U, true) |
| 158 | << get_inception_node_A(data_path, "Mixed_5d", 64U, std::make_tuple(48U, 64U), std::make_tuple(64U, 96U, 96U), |
| 159 | 64U) |
| 160 | |
| 161 | << get_inception_node_B(data_path, "Mixed_6a", 384U, std::make_tuple(64U, 96U, 96U)) |
| 162 | |
| 163 | << get_inception_node_C(data_path, "Mixed_6b", 192U, std::make_tuple(128U, 128U, 192U), |
| 164 | std::make_tuple(128U, 128U, 128U, 128U, 192U), 192U) |
| 165 | << get_inception_node_C(data_path, "Mixed_6c", 192U, std::make_tuple(160U, 160U, 192U), |
| 166 | std::make_tuple(160U, 160U, 160U, 160U, 192U), 192U) |
| 167 | << get_inception_node_C(data_path, "Mixed_6d", 192U, std::make_tuple(160U, 160U, 192U), |
| 168 | std::make_tuple(160U, 160U, 160U, 160U, 192U), 192U) |
| 169 | << get_inception_node_C(data_path, "Mixed_6e", 192U, std::make_tuple(192U, 192U, 192U), |
| 170 | std::make_tuple(192U, 192U, 192U, 192U, 192U), 192U) |
| 171 | |
| 172 | << get_inception_node_D(data_path, "Mixed_7a", std::make_tuple(192U, 320U), |
| 173 | std::make_tuple(192U, 192U, 192U, 192U)) |
| 174 | |
| 175 | << get_inception_node_E(data_path, "Mixed_7b", 320U, std::make_tuple(384U, 384U, 384U), |
| 176 | std::make_tuple(448U, 384U, 384U, 384U), 192U) |
| 177 | << get_inception_node_E(data_path, "Mixed_7c", 320U, std::make_tuple(384U, 384U, 384U), |
| 178 | std::make_tuple(448U, 384U, 384U, 384U), 192U, true) |
| 179 | |
| 180 | << PoolingLayer(PoolingLayerInfo(PoolingType::AVG, 8, PadStrideInfo(1, 1, 0, 0, DimensionRoundingType::CEIL))) |
| 181 | << ConvolutionLayer(1U, 1U, 1001U, get_weights_accessor(data_path, |
| 182 | "/cnn_data/inceptionv3_model/Logits_Conv2d_1c_1x1_weights.npy"), |
| 183 | get_weights_accessor(data_path, |
| 184 | "/cnn_data/inceptionv3_model/Logits_Conv2d_1c_1x1_biases.npy"), |
| 185 | PadStrideInfo(1, 1, 0, 0)) |
| 186 | << ReshapeLayer(TensorShape(1001U)) << SoftmaxLayer() |
| 187 | << Tensor(get_output_accessor(label, 5)); |
| 188 | } |
| 189 | |
| 190 | void do_run() override |
| 191 | { |
| 192 | graph.run(); |
| 193 | } |
| 194 | |
| 195 | private: |
| 196 | Graph graph{}; |
| 197 | |
| 198 | private: |
| 199 | BranchLayer get_inception_node_A(const std::string &data_path, std::string &¶m_path, |
| 200 | unsigned int a_filt, |
| 201 | std::tuple<unsigned int, unsigned int> b_filters, |
| 202 | std::tuple<unsigned int, unsigned int, unsigned int> c_filters, |
| 203 | unsigned int d_filt, |
| 204 | bool is_name_different = false) |
| 205 | { |
| 206 | std::string total_path = "/cnn_data/inceptionv3_model/" + param_path + "_"; |
| 207 | std::cout << total_path << std::endl; |
| 208 | |
| 209 | // This is due to a naming issue in the tf model |
| 210 | std::string conv_id0 = "_0a_"; |
| 211 | std::string conv_id1 = "2d_0b_"; |
| 212 | if(is_name_different) |
| 213 | { |
| 214 | conv_id0 = "_0b_"; |
| 215 | conv_id1 = "_1_0c_"; |
| 216 | } |
| 217 | |
| 218 | SubGraph i_a; |
| 219 | i_a << ConvolutionLayer( |
| 220 | 1U, 1U, a_filt, |
| 221 | get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_weights.npy"), |
| 222 | std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), |
| 223 | PadStrideInfo(1, 1, 0, 0)) |
| 224 | << BatchNormalizationLayer( |
| 225 | get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_moving_mean.npy"), |
| 226 | get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_moving_variance.npy"), |
| 227 | get_random_accessor(1.f, 1.f), |
| 228 | get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_beta.npy"), |
Giorgio Arena | 1167487 | 2018-02-07 15:38:12 +0000 | [diff] [blame] | 229 | 0.001f, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)); |
Georgios Pinitas | 652bde5 | 2018-01-10 15:33:28 +0000 | [diff] [blame] | 230 | |
| 231 | SubGraph i_b; |
| 232 | i_b << ConvolutionLayer( |
| 233 | 1U, 1U, std::get<0>(b_filters), |
| 234 | get_weights_accessor(data_path, total_path + "Branch_1_Conv2d" + conv_id0 + "1x1_weights.npy"), |
| 235 | std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), |
| 236 | PadStrideInfo(1, 1, 0, 0)) |
| 237 | << BatchNormalizationLayer( |
| 238 | get_weights_accessor(data_path, total_path + "Branch_1_Conv2d" + conv_id0 + "1x1_BatchNorm_moving_mean.npy"), |
| 239 | get_weights_accessor(data_path, total_path + "Branch_1_Conv2d" + conv_id0 + "1x1_BatchNorm_moving_variance.npy"), |
| 240 | get_random_accessor(1.f, 1.f), |
| 241 | get_weights_accessor(data_path, total_path + "Branch_1_Conv2d" + conv_id0 + "1x1_BatchNorm_beta.npy"), |
Giorgio Arena | 1167487 | 2018-02-07 15:38:12 +0000 | [diff] [blame] | 242 | 0.001f, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)) |
Georgios Pinitas | 652bde5 | 2018-01-10 15:33:28 +0000 | [diff] [blame] | 243 | << ConvolutionLayer( |
| 244 | 5U, 5U, std::get<1>(b_filters), |
| 245 | get_weights_accessor(data_path, total_path + "Branch_1_Conv" + conv_id1 + "5x5_weights.npy"), |
| 246 | std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), |
| 247 | PadStrideInfo(1, 1, 2, 2)) |
| 248 | << BatchNormalizationLayer( |
| 249 | get_weights_accessor(data_path, total_path + "Branch_1_Conv" + conv_id1 + "5x5_BatchNorm_moving_mean.npy"), |
| 250 | get_weights_accessor(data_path, total_path + "Branch_1_Conv" + conv_id1 + "5x5_BatchNorm_moving_variance.npy"), |
| 251 | get_random_accessor(1.f, 1.f), |
| 252 | get_weights_accessor(data_path, total_path + "Branch_1_Conv" + conv_id1 + "5x5_BatchNorm_beta.npy"), |
Giorgio Arena | 1167487 | 2018-02-07 15:38:12 +0000 | [diff] [blame] | 253 | 0.001f, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)); |
Georgios Pinitas | 652bde5 | 2018-01-10 15:33:28 +0000 | [diff] [blame] | 254 | |
| 255 | SubGraph i_c; |
| 256 | i_c << ConvolutionLayer( |
| 257 | 1U, 1U, std::get<0>(c_filters), |
| 258 | get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_weights.npy"), |
| 259 | std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), |
| 260 | PadStrideInfo(1, 1, 0, 0)) |
| 261 | << BatchNormalizationLayer( |
| 262 | get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_BatchNorm_moving_mean.npy"), |
| 263 | get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_BatchNorm_moving_variance.npy"), |
| 264 | get_random_accessor(1.f, 1.f), |
| 265 | get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_BatchNorm_beta.npy"), |
Giorgio Arena | 1167487 | 2018-02-07 15:38:12 +0000 | [diff] [blame] | 266 | 0.001f, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)) |
Georgios Pinitas | 652bde5 | 2018-01-10 15:33:28 +0000 | [diff] [blame] | 267 | << ConvolutionLayer( |
| 268 | 3U, 3U, std::get<1>(c_filters), |
| 269 | get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_3x3_weights.npy"), |
| 270 | std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), |
| 271 | PadStrideInfo(1, 1, 1, 1)) |
| 272 | << BatchNormalizationLayer( |
| 273 | get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_3x3_BatchNorm_moving_mean.npy"), |
| 274 | get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_3x3_BatchNorm_moving_variance.npy"), |
| 275 | get_random_accessor(1.f, 1.f), |
| 276 | get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_3x3_BatchNorm_beta.npy"), |
Giorgio Arena | 1167487 | 2018-02-07 15:38:12 +0000 | [diff] [blame] | 277 | 0.001f, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)) |
Georgios Pinitas | 652bde5 | 2018-01-10 15:33:28 +0000 | [diff] [blame] | 278 | << ConvolutionLayer( |
| 279 | 3U, 3U, std::get<2>(c_filters), |
| 280 | get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_3x3_weights.npy"), |
| 281 | std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), |
| 282 | PadStrideInfo(1, 1, 1, 1)) |
| 283 | << BatchNormalizationLayer( |
| 284 | get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_3x3_BatchNorm_moving_mean.npy"), |
| 285 | get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_3x3_BatchNorm_moving_variance.npy"), |
| 286 | get_random_accessor(1.f, 1.f), |
| 287 | get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_3x3_BatchNorm_beta.npy"), |
Giorgio Arena | 1167487 | 2018-02-07 15:38:12 +0000 | [diff] [blame] | 288 | 0.001f, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)); |
Georgios Pinitas | 652bde5 | 2018-01-10 15:33:28 +0000 | [diff] [blame] | 289 | |
| 290 | SubGraph i_d; |
| 291 | i_d << PoolingLayer(PoolingLayerInfo(PoolingType::AVG, 3, PadStrideInfo(1, 1, 1, 1, DimensionRoundingType::CEIL), true)) |
| 292 | << ConvolutionLayer( |
| 293 | 1U, 1U, d_filt, |
| 294 | get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_weights.npy"), |
| 295 | std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), |
| 296 | PadStrideInfo(1, 1, 0, 0)) |
| 297 | << BatchNormalizationLayer( |
| 298 | get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_BatchNorm_moving_mean.npy"), |
| 299 | get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_BatchNorm_moving_variance.npy"), |
| 300 | get_random_accessor(1.f, 1.f), |
| 301 | get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_BatchNorm_beta.npy"), |
Giorgio Arena | 1167487 | 2018-02-07 15:38:12 +0000 | [diff] [blame] | 302 | 0.001f, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)); |
Georgios Pinitas | 652bde5 | 2018-01-10 15:33:28 +0000 | [diff] [blame] | 303 | |
| 304 | return BranchLayer(BranchMergeMethod::DEPTH_CONCATENATE, std::move(i_a), std::move(i_b), std::move(i_c), std::move(i_d)); |
| 305 | } |
| 306 | |
| 307 | BranchLayer get_inception_node_B(const std::string &data_path, std::string &¶m_path, |
| 308 | unsigned int a_filt, |
| 309 | std::tuple<unsigned int, unsigned int, unsigned int> b_filters) |
| 310 | { |
| 311 | std::string total_path = "/cnn_data/inceptionv3_model/" + param_path + "_"; |
| 312 | SubGraph i_a; |
| 313 | i_a << ConvolutionLayer( |
| 314 | 3U, 3U, a_filt, |
| 315 | get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_1a_1x1_weights.npy"), |
| 316 | std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), |
| 317 | PadStrideInfo(2, 2, 0, 0)) |
| 318 | << BatchNormalizationLayer( |
| 319 | get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_1a_1x1_BatchNorm_moving_mean.npy"), |
| 320 | get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_1a_1x1_BatchNorm_moving_variance.npy"), |
| 321 | get_random_accessor(1.f, 1.f), |
| 322 | get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_1a_1x1_BatchNorm_beta.npy"), |
Giorgio Arena | 1167487 | 2018-02-07 15:38:12 +0000 | [diff] [blame] | 323 | 0.001f, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)); |
Georgios Pinitas | 652bde5 | 2018-01-10 15:33:28 +0000 | [diff] [blame] | 324 | |
| 325 | SubGraph i_b; |
| 326 | i_b << ConvolutionLayer( |
| 327 | 1U, 1U, std::get<0>(b_filters), |
| 328 | get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_weights.npy"), |
| 329 | std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), |
| 330 | PadStrideInfo(1, 1, 0, 0)) |
| 331 | << BatchNormalizationLayer( |
| 332 | get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_moving_mean.npy"), |
| 333 | get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_moving_variance.npy"), |
| 334 | get_random_accessor(1.f, 1.f), |
| 335 | get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_beta.npy"), |
Giorgio Arena | 1167487 | 2018-02-07 15:38:12 +0000 | [diff] [blame] | 336 | 0.001f, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)) |
Georgios Pinitas | 652bde5 | 2018-01-10 15:33:28 +0000 | [diff] [blame] | 337 | << ConvolutionLayer( |
| 338 | 3U, 3U, std::get<1>(b_filters), |
| 339 | get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_3x3_weights.npy"), |
| 340 | std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), |
| 341 | PadStrideInfo(1, 1, 1, 1)) |
| 342 | << BatchNormalizationLayer( |
| 343 | get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_3x3_BatchNorm_moving_mean.npy"), |
| 344 | get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_3x3_BatchNorm_moving_variance.npy"), |
| 345 | get_random_accessor(1.f, 1.f), |
| 346 | get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_3x3_BatchNorm_beta.npy"), |
Giorgio Arena | 1167487 | 2018-02-07 15:38:12 +0000 | [diff] [blame] | 347 | 0.001f, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)) |
Georgios Pinitas | 652bde5 | 2018-01-10 15:33:28 +0000 | [diff] [blame] | 348 | << ConvolutionLayer( |
| 349 | 3U, 3U, std::get<2>(b_filters), |
| 350 | get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_1a_1x1_weights.npy"), |
| 351 | std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), |
| 352 | PadStrideInfo(2, 2, 0, 0)) |
| 353 | << BatchNormalizationLayer( |
| 354 | get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_1a_1x1_BatchNorm_moving_mean.npy"), |
| 355 | get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_1a_1x1_BatchNorm_moving_variance.npy"), |
| 356 | get_random_accessor(1.f, 1.f), |
| 357 | get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_1a_1x1_BatchNorm_beta.npy"), |
Giorgio Arena | 1167487 | 2018-02-07 15:38:12 +0000 | [diff] [blame] | 358 | 0.001f, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)); |
Georgios Pinitas | 652bde5 | 2018-01-10 15:33:28 +0000 | [diff] [blame] | 359 | |
| 360 | SubGraph i_c; |
| 361 | i_c << PoolingLayer(PoolingLayerInfo(PoolingType::MAX, 3, PadStrideInfo(2, 2, 0, 0, DimensionRoundingType::CEIL))) |
| 362 | // TODO (geopin01) : Remove once we understand why a single node graph does not run in CL |
| 363 | << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LINEAR, 1.f, 0.f)); |
| 364 | |
| 365 | return BranchLayer(BranchMergeMethod::DEPTH_CONCATENATE, std::move(i_a), std::move(i_b), std::move(i_c)); |
| 366 | } |
| 367 | |
| 368 | BranchLayer get_inception_node_C(const std::string &data_path, std::string &¶m_path, |
| 369 | unsigned int a_filt, |
| 370 | std::tuple<unsigned int, unsigned int, unsigned int> b_filters, |
| 371 | std::tuple<unsigned int, unsigned int, unsigned int, unsigned int, unsigned int> c_filters, |
| 372 | unsigned int d_filt) |
| 373 | { |
| 374 | std::string total_path = "/cnn_data/inceptionv3_model/" + param_path + "_"; |
| 375 | SubGraph i_a; |
| 376 | i_a << ConvolutionLayer( |
| 377 | 1U, 1U, a_filt, |
| 378 | get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_weights.npy"), |
| 379 | std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), |
| 380 | PadStrideInfo(1, 1, 0, 0)) |
| 381 | << BatchNormalizationLayer( |
| 382 | get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_moving_mean.npy"), |
| 383 | get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_moving_variance.npy"), |
| 384 | get_random_accessor(1.f, 1.f), |
| 385 | get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_beta.npy"), |
Giorgio Arena | 1167487 | 2018-02-07 15:38:12 +0000 | [diff] [blame] | 386 | 0.001f, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)); |
Georgios Pinitas | 652bde5 | 2018-01-10 15:33:28 +0000 | [diff] [blame] | 387 | |
| 388 | SubGraph i_b; |
| 389 | i_b << ConvolutionLayer( |
| 390 | 1U, 1U, std::get<0>(b_filters), |
| 391 | get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_weights.npy"), |
| 392 | std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), |
| 393 | PadStrideInfo(1, 1, 0, 0)) |
| 394 | << BatchNormalizationLayer( |
| 395 | get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_moving_mean.npy"), |
| 396 | get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_moving_variance.npy"), |
| 397 | get_random_accessor(1.f, 1.f), |
| 398 | get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_beta.npy"), |
Giorgio Arena | 1167487 | 2018-02-07 15:38:12 +0000 | [diff] [blame] | 399 | 0.001f, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)) |
Georgios Pinitas | 652bde5 | 2018-01-10 15:33:28 +0000 | [diff] [blame] | 400 | << ConvolutionLayer( |
| 401 | 7U, 1U, std::get<1>(b_filters), |
| 402 | get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x7_weights.npy"), |
| 403 | std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), |
| 404 | PadStrideInfo(1, 1, 3, 0)) |
| 405 | << BatchNormalizationLayer( |
| 406 | get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x7_BatchNorm_moving_mean.npy"), |
| 407 | get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x7_BatchNorm_moving_variance.npy"), |
| 408 | get_random_accessor(1.f, 1.f), |
| 409 | get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x7_BatchNorm_beta.npy"), |
Giorgio Arena | 1167487 | 2018-02-07 15:38:12 +0000 | [diff] [blame] | 410 | 0.001f, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)) |
Georgios Pinitas | 652bde5 | 2018-01-10 15:33:28 +0000 | [diff] [blame] | 411 | << ConvolutionLayer( |
| 412 | 1U, 7U, std::get<2>(b_filters), |
| 413 | get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0c_7x1_weights.npy"), |
| 414 | std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), |
| 415 | PadStrideInfo(1, 1, 0, 3)) |
| 416 | << BatchNormalizationLayer( |
| 417 | get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0c_7x1_BatchNorm_moving_mean.npy"), |
| 418 | get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0c_7x1_BatchNorm_moving_variance.npy"), |
| 419 | get_random_accessor(1.f, 1.f), |
| 420 | get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0c_7x1_BatchNorm_beta.npy"), |
Giorgio Arena | 1167487 | 2018-02-07 15:38:12 +0000 | [diff] [blame] | 421 | 0.001f, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)); |
Georgios Pinitas | 652bde5 | 2018-01-10 15:33:28 +0000 | [diff] [blame] | 422 | |
| 423 | SubGraph i_c; |
| 424 | i_c << ConvolutionLayer( |
| 425 | 1U, 1U, std::get<0>(c_filters), |
| 426 | get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_weights.npy"), |
| 427 | std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), |
| 428 | PadStrideInfo(1, 1, 0, 0)) |
| 429 | << BatchNormalizationLayer( |
| 430 | get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_BatchNorm_moving_mean.npy"), |
| 431 | get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_BatchNorm_moving_variance.npy"), |
| 432 | get_random_accessor(1.f, 1.f), |
| 433 | get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_BatchNorm_beta.npy"), |
Giorgio Arena | 1167487 | 2018-02-07 15:38:12 +0000 | [diff] [blame] | 434 | 0.001f, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)) |
Georgios Pinitas | 652bde5 | 2018-01-10 15:33:28 +0000 | [diff] [blame] | 435 | << ConvolutionLayer( |
| 436 | 1U, 7U, std::get<1>(c_filters), |
| 437 | get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_7x1_weights.npy"), |
| 438 | std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), |
| 439 | PadStrideInfo(1, 1, 0, 3)) |
| 440 | << BatchNormalizationLayer( |
| 441 | get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_7x1_BatchNorm_moving_mean.npy"), |
| 442 | get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_7x1_BatchNorm_moving_variance.npy"), |
| 443 | get_random_accessor(1.f, 1.f), |
| 444 | get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_7x1_BatchNorm_beta.npy"), |
Giorgio Arena | 1167487 | 2018-02-07 15:38:12 +0000 | [diff] [blame] | 445 | 0.001f, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)) |
Georgios Pinitas | 652bde5 | 2018-01-10 15:33:28 +0000 | [diff] [blame] | 446 | << ConvolutionLayer( |
| 447 | 7U, 1U, std::get<2>(c_filters), |
| 448 | get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_1x7_weights.npy"), |
| 449 | std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), |
| 450 | PadStrideInfo(1, 1, 3, 0)) |
| 451 | << BatchNormalizationLayer( |
| 452 | get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_1x7_BatchNorm_moving_mean.npy"), |
| 453 | get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_1x7_BatchNorm_moving_variance.npy"), |
| 454 | get_random_accessor(1.f, 1.f), |
| 455 | get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_1x7_BatchNorm_beta.npy"), |
Giorgio Arena | 1167487 | 2018-02-07 15:38:12 +0000 | [diff] [blame] | 456 | 0.001f, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)) |
Georgios Pinitas | 652bde5 | 2018-01-10 15:33:28 +0000 | [diff] [blame] | 457 | << ConvolutionLayer( |
| 458 | 1U, 7U, std::get<3>(c_filters), |
| 459 | get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0d_7x1_weights.npy"), |
| 460 | std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), |
| 461 | PadStrideInfo(1, 1, 0, 3)) |
| 462 | << BatchNormalizationLayer( |
| 463 | get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0d_7x1_BatchNorm_moving_mean.npy"), |
| 464 | get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0d_7x1_BatchNorm_moving_variance.npy"), |
| 465 | get_random_accessor(1.f, 1.f), |
| 466 | get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0d_7x1_BatchNorm_beta.npy"), |
Giorgio Arena | 1167487 | 2018-02-07 15:38:12 +0000 | [diff] [blame] | 467 | 0.001f, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)) |
Georgios Pinitas | 652bde5 | 2018-01-10 15:33:28 +0000 | [diff] [blame] | 468 | << ConvolutionLayer( |
| 469 | 7U, 1U, std::get<4>(c_filters), |
| 470 | get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0e_1x7_weights.npy"), |
| 471 | std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), |
| 472 | PadStrideInfo(1, 1, 3, 0)) |
| 473 | << BatchNormalizationLayer( |
| 474 | get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0e_1x7_BatchNorm_moving_mean.npy"), |
| 475 | get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0e_1x7_BatchNorm_moving_variance.npy"), |
| 476 | get_random_accessor(1.f, 1.f), |
| 477 | get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0e_1x7_BatchNorm_beta.npy"), |
Giorgio Arena | 1167487 | 2018-02-07 15:38:12 +0000 | [diff] [blame] | 478 | 0.001f, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)); |
Georgios Pinitas | 652bde5 | 2018-01-10 15:33:28 +0000 | [diff] [blame] | 479 | |
| 480 | SubGraph i_d; |
| 481 | i_d << PoolingLayer(PoolingLayerInfo(PoolingType::AVG, 3, PadStrideInfo(1, 1, 1, 1, DimensionRoundingType::CEIL), true)) |
| 482 | << ConvolutionLayer( |
| 483 | 1U, 1U, d_filt, |
| 484 | get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_weights.npy"), |
| 485 | std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), |
| 486 | PadStrideInfo(1, 1, 0, 0)) |
| 487 | << BatchNormalizationLayer( |
| 488 | get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_BatchNorm_moving_mean.npy"), |
| 489 | get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_BatchNorm_moving_variance.npy"), |
| 490 | get_random_accessor(1.f, 1.f), |
| 491 | get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_BatchNorm_beta.npy"), |
Giorgio Arena | 1167487 | 2018-02-07 15:38:12 +0000 | [diff] [blame] | 492 | 0.001f, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)); |
Georgios Pinitas | 652bde5 | 2018-01-10 15:33:28 +0000 | [diff] [blame] | 493 | |
| 494 | return BranchLayer(BranchMergeMethod::DEPTH_CONCATENATE, std::move(i_a), std::move(i_b), std::move(i_c), std::move(i_d)); |
| 495 | } |
| 496 | |
| 497 | BranchLayer get_inception_node_D(const std::string &data_path, std::string &¶m_path, |
| 498 | std::tuple<unsigned int, unsigned int> a_filters, |
| 499 | std::tuple<unsigned int, unsigned int, unsigned int, unsigned int> b_filters) |
| 500 | { |
| 501 | std::string total_path = "/cnn_data/inceptionv3_model/" + param_path + "_"; |
| 502 | SubGraph i_a; |
| 503 | i_a << ConvolutionLayer( |
| 504 | 1U, 1U, std::get<0>(a_filters), |
| 505 | get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_weights.npy"), |
| 506 | std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), |
| 507 | PadStrideInfo(1, 1, 0, 0)) |
| 508 | << BatchNormalizationLayer( |
| 509 | get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_moving_mean.npy"), |
| 510 | get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_moving_variance.npy"), |
| 511 | get_random_accessor(1.f, 1.f), |
| 512 | get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_beta.npy"), |
Giorgio Arena | 1167487 | 2018-02-07 15:38:12 +0000 | [diff] [blame] | 513 | 0.001f, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)) |
Georgios Pinitas | 652bde5 | 2018-01-10 15:33:28 +0000 | [diff] [blame] | 514 | << ConvolutionLayer( |
| 515 | 3U, 3U, std::get<1>(a_filters), |
| 516 | get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_1a_3x3_weights.npy"), |
| 517 | std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), |
| 518 | PadStrideInfo(2, 2, 0, 0)) |
| 519 | << BatchNormalizationLayer( |
| 520 | get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_1a_3x3_BatchNorm_moving_mean.npy"), |
| 521 | get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_1a_3x3_BatchNorm_moving_variance.npy"), |
| 522 | get_random_accessor(1.f, 1.f), |
| 523 | get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_1a_3x3_BatchNorm_beta.npy"), |
Giorgio Arena | 1167487 | 2018-02-07 15:38:12 +0000 | [diff] [blame] | 524 | 0.001f, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)); |
Georgios Pinitas | 652bde5 | 2018-01-10 15:33:28 +0000 | [diff] [blame] | 525 | |
| 526 | SubGraph i_b; |
| 527 | i_b << ConvolutionLayer( |
| 528 | 1U, 1U, std::get<0>(b_filters), |
| 529 | get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_weights.npy"), |
| 530 | std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), |
| 531 | PadStrideInfo(1, 1, 0, 0)) |
| 532 | << BatchNormalizationLayer( |
| 533 | get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_moving_mean.npy"), |
| 534 | get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_moving_variance.npy"), |
| 535 | get_random_accessor(1.f, 1.f), |
| 536 | get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_beta.npy"), |
Giorgio Arena | 1167487 | 2018-02-07 15:38:12 +0000 | [diff] [blame] | 537 | 0.001f, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)) |
Georgios Pinitas | 652bde5 | 2018-01-10 15:33:28 +0000 | [diff] [blame] | 538 | << ConvolutionLayer( |
| 539 | 7U, 1U, std::get<1>(b_filters), |
| 540 | get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x7_weights.npy"), |
| 541 | std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), |
| 542 | PadStrideInfo(1, 1, 3, 0)) |
| 543 | << BatchNormalizationLayer( |
| 544 | get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x7_BatchNorm_moving_mean.npy"), |
| 545 | get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x7_BatchNorm_moving_variance.npy"), |
| 546 | get_random_accessor(1.f, 1.f), |
| 547 | get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x7_BatchNorm_beta.npy"), |
Giorgio Arena | 1167487 | 2018-02-07 15:38:12 +0000 | [diff] [blame] | 548 | 0.001f, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)) |
Georgios Pinitas | 652bde5 | 2018-01-10 15:33:28 +0000 | [diff] [blame] | 549 | << ConvolutionLayer( |
| 550 | 1U, 7U, std::get<2>(b_filters), |
| 551 | get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0c_7x1_weights.npy"), |
| 552 | std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), |
| 553 | PadStrideInfo(1, 1, 0, 3)) |
| 554 | << BatchNormalizationLayer( |
| 555 | get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0c_7x1_BatchNorm_moving_mean.npy"), |
| 556 | get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0c_7x1_BatchNorm_moving_variance.npy"), |
| 557 | get_random_accessor(1.f, 1.f), |
| 558 | get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0c_7x1_BatchNorm_beta.npy"), |
Giorgio Arena | 1167487 | 2018-02-07 15:38:12 +0000 | [diff] [blame] | 559 | 0.001f, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)) |
Georgios Pinitas | 652bde5 | 2018-01-10 15:33:28 +0000 | [diff] [blame] | 560 | << ConvolutionLayer( |
| 561 | 3U, 3U, std::get<3>(b_filters), |
| 562 | get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_1a_3x3_weights.npy"), |
| 563 | std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), |
| 564 | PadStrideInfo(2, 2, 0, 0)) |
| 565 | << BatchNormalizationLayer( |
| 566 | get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_1a_3x3_BatchNorm_moving_mean.npy"), |
| 567 | get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_1a_3x3_BatchNorm_moving_variance.npy"), |
| 568 | get_random_accessor(1.f, 1.f), |
| 569 | get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_1a_3x3_BatchNorm_beta.npy"), |
Giorgio Arena | 1167487 | 2018-02-07 15:38:12 +0000 | [diff] [blame] | 570 | 0.001f, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)); |
Georgios Pinitas | 652bde5 | 2018-01-10 15:33:28 +0000 | [diff] [blame] | 571 | |
| 572 | SubGraph i_c; |
| 573 | i_c << PoolingLayer(PoolingLayerInfo(PoolingType::MAX, 3, PadStrideInfo(2, 2, 0, 0, DimensionRoundingType::CEIL))) |
| 574 | // TODO (geopin01) : Remove once we understand why a single node graph does not run in CL |
| 575 | << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LINEAR, 1.f, 0.f)); |
| 576 | |
| 577 | return BranchLayer(BranchMergeMethod::DEPTH_CONCATENATE, std::move(i_a), std::move(i_b), std::move(i_c)); |
| 578 | } |
| 579 | |
| 580 | BranchLayer get_inception_node_E(const std::string &data_path, std::string &¶m_path, |
| 581 | unsigned int a_filt, |
| 582 | std::tuple<unsigned int, unsigned int, unsigned int> b_filters, |
| 583 | std::tuple<unsigned int, unsigned int, unsigned int, unsigned int> c_filters, |
| 584 | unsigned int d_filt, |
| 585 | bool is_name_different = false) |
| 586 | { |
| 587 | // This is due to a naming issue in the tf model |
| 588 | std::string conv_id = "_0b_"; |
| 589 | if(is_name_different) |
| 590 | { |
| 591 | conv_id = "_0c_"; |
| 592 | } |
| 593 | |
| 594 | std::string total_path = "/cnn_data/inceptionv3_model/" + param_path + "_"; |
| 595 | SubGraph i_a; |
| 596 | i_a << ConvolutionLayer( |
| 597 | 1U, 1U, a_filt, |
| 598 | get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_weights.npy"), |
| 599 | std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), |
| 600 | PadStrideInfo(1, 1, 0, 0)) |
| 601 | << BatchNormalizationLayer( |
| 602 | get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_moving_mean.npy"), |
| 603 | get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_moving_variance.npy"), |
| 604 | get_random_accessor(1.f, 1.f), |
| 605 | get_weights_accessor(data_path, total_path + "Branch_0_Conv2d_0a_1x1_BatchNorm_beta.npy"), |
Giorgio Arena | 1167487 | 2018-02-07 15:38:12 +0000 | [diff] [blame] | 606 | 0.001f, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)); |
Georgios Pinitas | 652bde5 | 2018-01-10 15:33:28 +0000 | [diff] [blame] | 607 | |
| 608 | SubGraph i_b1; |
| 609 | i_b1 << ConvolutionLayer( |
| 610 | 3U, 1U, std::get<1>(b_filters), |
| 611 | get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x3_weights.npy"), |
| 612 | std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), |
| 613 | PadStrideInfo(1, 1, 1, 0)) |
| 614 | << BatchNormalizationLayer( |
| 615 | get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x3_BatchNorm_moving_mean.npy"), |
| 616 | get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x3_BatchNorm_moving_variance.npy"), |
| 617 | get_random_accessor(1.f, 1.f), |
| 618 | get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0b_1x3_BatchNorm_beta.npy"), |
Giorgio Arena | 1167487 | 2018-02-07 15:38:12 +0000 | [diff] [blame] | 619 | 0.001f, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)); |
Georgios Pinitas | 652bde5 | 2018-01-10 15:33:28 +0000 | [diff] [blame] | 620 | |
| 621 | SubGraph i_b2; |
| 622 | i_b2 << ConvolutionLayer( |
| 623 | 1U, 3U, std::get<2>(b_filters), |
| 624 | get_weights_accessor(data_path, total_path + "Branch_1_Conv2d" + conv_id + "3x1_weights.npy"), |
| 625 | std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), |
| 626 | PadStrideInfo(1, 1, 0, 1)) |
| 627 | << BatchNormalizationLayer( |
| 628 | get_weights_accessor(data_path, total_path + "Branch_1_Conv2d" + conv_id + "3x1_BatchNorm_moving_mean.npy"), |
| 629 | get_weights_accessor(data_path, total_path + "Branch_1_Conv2d" + conv_id + "3x1_BatchNorm_moving_variance.npy"), |
| 630 | get_random_accessor(1.f, 1.f), |
| 631 | get_weights_accessor(data_path, total_path + "Branch_1_Conv2d" + conv_id + "3x1_BatchNorm_beta.npy"), |
Giorgio Arena | 1167487 | 2018-02-07 15:38:12 +0000 | [diff] [blame] | 632 | 0.001f, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)); |
Georgios Pinitas | 652bde5 | 2018-01-10 15:33:28 +0000 | [diff] [blame] | 633 | |
| 634 | SubGraph i_b; |
| 635 | i_b << ConvolutionLayer( |
| 636 | 1U, 1U, std::get<0>(b_filters), |
| 637 | get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_weights.npy"), |
| 638 | std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), |
| 639 | PadStrideInfo(1, 1, 0, 0)) |
| 640 | << BatchNormalizationLayer( |
| 641 | get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_moving_mean.npy"), |
| 642 | get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_moving_variance.npy"), |
| 643 | get_random_accessor(1.f, 1.f), |
| 644 | get_weights_accessor(data_path, total_path + "Branch_1_Conv2d_0a_1x1_BatchNorm_beta.npy"), |
Giorgio Arena | 1167487 | 2018-02-07 15:38:12 +0000 | [diff] [blame] | 645 | 0.001f, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)) |
Georgios Pinitas | 652bde5 | 2018-01-10 15:33:28 +0000 | [diff] [blame] | 646 | << BranchLayer(BranchMergeMethod::DEPTH_CONCATENATE, std::move(i_b1), std::move(i_b2)); |
| 647 | |
| 648 | SubGraph i_c1; |
| 649 | i_c1 << ConvolutionLayer( |
| 650 | 3U, 1U, std::get<2>(c_filters), |
| 651 | get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_1x3_weights.npy"), |
| 652 | std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), |
| 653 | PadStrideInfo(1, 1, 1, 0)) |
| 654 | << BatchNormalizationLayer( |
| 655 | get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_1x3_BatchNorm_moving_mean.npy"), |
| 656 | get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_1x3_BatchNorm_moving_variance.npy"), |
| 657 | get_random_accessor(1.f, 1.f), |
| 658 | get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0c_1x3_BatchNorm_beta.npy"), |
Giorgio Arena | 1167487 | 2018-02-07 15:38:12 +0000 | [diff] [blame] | 659 | 0.001f, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)); |
Georgios Pinitas | 652bde5 | 2018-01-10 15:33:28 +0000 | [diff] [blame] | 660 | |
| 661 | SubGraph i_c2; |
| 662 | i_c2 << ConvolutionLayer( |
| 663 | 1U, 3U, std::get<3>(c_filters), |
| 664 | get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0d_3x1_weights.npy"), |
| 665 | std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), |
| 666 | PadStrideInfo(1, 1, 0, 1)) |
| 667 | << BatchNormalizationLayer( |
| 668 | get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0d_3x1_BatchNorm_moving_mean.npy"), |
| 669 | get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0d_3x1_BatchNorm_moving_variance.npy"), |
| 670 | get_random_accessor(1.f, 1.f), |
| 671 | get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0d_3x1_BatchNorm_beta.npy"), |
Giorgio Arena | 1167487 | 2018-02-07 15:38:12 +0000 | [diff] [blame] | 672 | 0.001f, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)); |
Georgios Pinitas | 652bde5 | 2018-01-10 15:33:28 +0000 | [diff] [blame] | 673 | |
| 674 | SubGraph i_c; |
| 675 | i_c << ConvolutionLayer( |
| 676 | 1U, 1U, std::get<0>(c_filters), |
| 677 | get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_weights.npy"), |
| 678 | std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), |
| 679 | PadStrideInfo(1, 1, 0, 0)) |
| 680 | << BatchNormalizationLayer( |
| 681 | get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_BatchNorm_moving_mean.npy"), |
| 682 | get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_BatchNorm_moving_variance.npy"), |
| 683 | get_random_accessor(1.f, 1.f), |
| 684 | get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0a_1x1_BatchNorm_beta.npy"), |
Giorgio Arena | 1167487 | 2018-02-07 15:38:12 +0000 | [diff] [blame] | 685 | 0.001f, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)) |
Georgios Pinitas | 652bde5 | 2018-01-10 15:33:28 +0000 | [diff] [blame] | 686 | << ConvolutionLayer( |
| 687 | 3U, 3U, std::get<1>(c_filters), |
| 688 | get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_3x3_weights.npy"), |
| 689 | std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), |
| 690 | PadStrideInfo(1, 1, 1, 1)) |
| 691 | << BatchNormalizationLayer( |
| 692 | get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_3x3_BatchNorm_moving_mean.npy"), |
| 693 | get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_3x3_BatchNorm_moving_variance.npy"), |
| 694 | get_random_accessor(1.f, 1.f), |
| 695 | get_weights_accessor(data_path, total_path + "Branch_2_Conv2d_0b_3x3_BatchNorm_beta.npy"), |
Giorgio Arena | 1167487 | 2018-02-07 15:38:12 +0000 | [diff] [blame] | 696 | 0.001f, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)) |
Georgios Pinitas | 652bde5 | 2018-01-10 15:33:28 +0000 | [diff] [blame] | 697 | << BranchLayer(BranchMergeMethod::DEPTH_CONCATENATE, std::move(i_c1), std::move(i_c2)); |
| 698 | |
| 699 | SubGraph i_d; |
| 700 | i_d << PoolingLayer(PoolingLayerInfo(PoolingType::AVG, 3, PadStrideInfo(1, 1, 1, 1, DimensionRoundingType::CEIL), true)) |
| 701 | << ConvolutionLayer( |
| 702 | 1U, 1U, d_filt, |
| 703 | get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_weights.npy"), |
| 704 | std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), |
| 705 | PadStrideInfo(1, 1, 0, 0)) |
| 706 | << BatchNormalizationLayer( |
| 707 | get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_BatchNorm_moving_mean.npy"), |
| 708 | get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_BatchNorm_moving_variance.npy"), |
| 709 | get_random_accessor(1.f, 1.f), |
| 710 | get_weights_accessor(data_path, total_path + "Branch_3_Conv2d_0b_1x1_BatchNorm_beta.npy"), |
Giorgio Arena | 1167487 | 2018-02-07 15:38:12 +0000 | [diff] [blame] | 711 | 0.001f, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)); |
Georgios Pinitas | 652bde5 | 2018-01-10 15:33:28 +0000 | [diff] [blame] | 712 | |
| 713 | return BranchLayer(BranchMergeMethod::DEPTH_CONCATENATE, std::move(i_a), std::move(i_b), std::move(i_c), std::move(i_d)); |
| 714 | } |
| 715 | }; |
| 716 | |
| 717 | /** Main program for Inception V3 |
| 718 | * |
| 719 | * @param[in] argc Number of arguments |
| 720 | * @param[in] argv Arguments ( [optional] Target (0 = NEON, 1 = OpenCL), [optional] Path to the weights folder, [optional] image, [optional] labels ) |
| 721 | */ |
| 722 | int main(int argc, char **argv) |
| 723 | { |
| 724 | return arm_compute::utils::run_example<InceptionV3Example>(argc, argv); |
| 725 | } |