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