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