Georgios Pinitas | 236bfe7 | 2017-11-23 15:59:55 +0000 | [diff] [blame] | 1 | /* |
Georgios Pinitas | 7f530b3 | 2018-01-22 11:20:44 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2018 ARM Limited. |
Georgios Pinitas | 236bfe7 | 2017-11-23 15:59:55 +0000 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: MIT |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | * of this software and associated documentation files (the "Software"), to |
| 8 | * deal in the Software without restriction, including without limitation the |
| 9 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 10 | * sell copies of the Software, and to permit persons to whom the Software is |
| 11 | * furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in all |
| 14 | * copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | * SOFTWARE. |
| 23 | */ |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 24 | #include "arm_compute/graph.h" |
Georgios Pinitas | 236bfe7 | 2017-11-23 15:59:55 +0000 | [diff] [blame] | 25 | #include "support/ToolchainSupport.h" |
| 26 | #include "utils/GraphUtils.h" |
| 27 | #include "utils/Utils.h" |
| 28 | |
| 29 | #include <cstdlib> |
| 30 | |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 31 | using namespace arm_compute::utils; |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 32 | using namespace arm_compute::graph::frontend; |
Georgios Pinitas | 236bfe7 | 2017-11-23 15:59:55 +0000 | [diff] [blame] | 33 | using namespace arm_compute::graph_utils; |
| 34 | |
Georgios Pinitas | 236bfe7 | 2017-11-23 15:59:55 +0000 | [diff] [blame] | 35 | /** Example demonstrating how to implement MobileNet's network using the Compute Library's graph API |
| 36 | * |
| 37 | * @param[in] argc Number of arguments |
Michele Di Giorgio | e3fba0a | 2018-02-14 14:18:01 +0000 | [diff] [blame] | 38 | * @param[in] argv Arguments ( [optional] Target (0 = NEON, 1 = OpenCL, 2 = OpenCL with Tuner), [optional] Path to the weights folder, [optional] image, [optional] labels ) |
Georgios Pinitas | 236bfe7 | 2017-11-23 15:59:55 +0000 | [diff] [blame] | 39 | */ |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 40 | class GraphMobilenetExample : public Example |
Georgios Pinitas | 236bfe7 | 2017-11-23 15:59:55 +0000 | [diff] [blame] | 41 | { |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 42 | public: |
| 43 | void do_setup(int argc, char **argv) override |
| 44 | { |
| 45 | std::string data_path; /* Path to the trainable data */ |
| 46 | std::string image; /* Image data */ |
| 47 | std::string label; /* Label data */ |
Georgios Pinitas | 236bfe7 | 2017-11-23 15:59:55 +0000 | [diff] [blame] | 48 | |
Georgios Pinitas | 140fdc7 | 2018-02-16 11:42:38 +0000 | [diff] [blame] | 49 | // Create a preprocessor object |
| 50 | std::unique_ptr<IPreprocessor> preprocessor = arm_compute::support::cpp14::make_unique<TFPreproccessor>(); |
Georgios Pinitas | 236bfe7 | 2017-11-23 15:59:55 +0000 | [diff] [blame] | 51 | |
Michele Di Giorgio | e3fba0a | 2018-02-14 14:18:01 +0000 | [diff] [blame] | 52 | // Set target. 0 (NEON), 1 (OpenCL), 2 (OpenCL with Tuner). By default it is NEON |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 53 | const int target = argc > 1 ? std::strtol(argv[1], nullptr, 10) : 0; |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 54 | Target target_hint = set_target_hint(target); |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 55 | ConvolutionMethod convolution_hint = ConvolutionMethod::GEMM; |
| 56 | DepthwiseConvolutionMethod depthwise_convolution_hint = DepthwiseConvolutionMethod::OPTIMIZED_3x3; |
Gian Marco | bfa3b52 | 2017-12-12 10:08:38 +0000 | [diff] [blame] | 57 | |
Georgios Pinitas | 7f530b3 | 2018-01-22 11:20:44 +0000 | [diff] [blame] | 58 | // Set model to execute. 0 (MobileNetV1_1.0_224), 1 (MobileNetV1_0.75_160) |
| 59 | int model_id = (argc > 2) ? std::strtol(argv[2], nullptr, 10) : 0; |
| 60 | ARM_COMPUTE_ERROR_ON_MSG(model_id > 1, "Invalid model ID. Model must be 0 (MobileNetV1_1.0_224) or 1 (MobileNetV1_0.75_160)"); |
Georgios Pinitas | cac13b1 | 2018-04-27 19:07:19 +0100 | [diff] [blame] | 61 | int layout_id = (argc > 3) ? std::strtol(argv[3], nullptr, 10) : 0; |
| 62 | ARM_COMPUTE_ERROR_ON_MSG(layout_id > 1, "Invalid layout ID. Layout must be 0 (NCHW) or 1 (NHWC)"); |
| 63 | |
| 64 | float depth_scale = (model_id == 0) ? 1.f : 0.75; |
| 65 | unsigned int spatial_size = (model_id == 0) ? 224 : 160; |
| 66 | std::string model_path = (model_id == 0) ? "/cnn_data/mobilenet_v1_1_224_model/" : "/cnn_data/mobilenet_v1_075_160_model/"; |
| 67 | TensorDescriptor input_descriptor_nchw = TensorDescriptor(TensorShape(spatial_size, spatial_size, 3U, 1U), DataType::F32); |
| 68 | TensorDescriptor input_descriptor_nhwc = TensorDescriptor(TensorShape(3U, spatial_size, spatial_size, 1U), DataType::F32).set_layout(DataLayout::NHWC); |
| 69 | TensorDescriptor input_descriptor = (layout_id == 0) ? input_descriptor_nchw : input_descriptor_nhwc; |
Georgios Pinitas | 7f530b3 | 2018-01-22 11:20:44 +0000 | [diff] [blame] | 70 | |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 71 | // Parse arguments |
| 72 | if(argc < 2) |
| 73 | { |
| 74 | // Print help |
Georgios Pinitas | cac13b1 | 2018-04-27 19:07:19 +0100 | [diff] [blame] | 75 | std::cout << "Usage: " << argv[0] << " [target] [model] [layout] [path_to_data] [image] [labels]\n\n"; |
Georgios Pinitas | 7f530b3 | 2018-01-22 11:20:44 +0000 | [diff] [blame] | 76 | std::cout << "No model ID provided: using MobileNetV1_1.0_224\n\n"; |
Georgios Pinitas | cac13b1 | 2018-04-27 19:07:19 +0100 | [diff] [blame] | 77 | std::cout << "No data layout provided: using NCHW\n\n"; |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 78 | std::cout << "No data folder provided: using random values\n\n"; |
| 79 | } |
| 80 | else if(argc == 2) |
| 81 | { |
Georgios Pinitas | cac13b1 | 2018-04-27 19:07:19 +0100 | [diff] [blame] | 82 | std::cout << "Usage: " << argv[0] << " " << argv[1] << " [model] [layout] [path_to_data] [image] [labels]\n\n"; |
Georgios Pinitas | 7f530b3 | 2018-01-22 11:20:44 +0000 | [diff] [blame] | 83 | std::cout << "No model ID provided: using MobileNetV1_1.0_224\n\n"; |
Georgios Pinitas | cac13b1 | 2018-04-27 19:07:19 +0100 | [diff] [blame] | 84 | std::cout << "No data layout provided: using NCHW\n\n"; |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 85 | std::cout << "No data folder provided: using random values\n\n"; |
| 86 | } |
| 87 | else if(argc == 3) |
| 88 | { |
Georgios Pinitas | cac13b1 | 2018-04-27 19:07:19 +0100 | [diff] [blame] | 89 | std::cout << "Usage: " << argv[0] << " " << argv[1] << " " << argv[2] << " [layout] [path_to_data] [image] [labels]\n\n"; |
| 90 | std::cout << "No data layout provided: using NCHW\n\n"; |
Georgios Pinitas | 7f530b3 | 2018-01-22 11:20:44 +0000 | [diff] [blame] | 91 | std::cout << "No data folder provided: using random values\n\n"; |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 92 | } |
| 93 | else if(argc == 4) |
| 94 | { |
Georgios Pinitas | cac13b1 | 2018-04-27 19:07:19 +0100 | [diff] [blame] | 95 | std::cout << "Usage: " << argv[0] << " " << argv[1] << " " << argv[2] << " " << argv[3] << " [path_to_data] [image] [labels]\n\n"; |
| 96 | std::cout << "No data folder provided: using random values\n\n"; |
Georgios Pinitas | 7f530b3 | 2018-01-22 11:20:44 +0000 | [diff] [blame] | 97 | } |
| 98 | else if(argc == 5) |
| 99 | { |
Georgios Pinitas | cac13b1 | 2018-04-27 19:07:19 +0100 | [diff] [blame] | 100 | data_path = argv[4]; |
| 101 | std::cout << "Usage: " << argv[0] << " " << argv[1] << " " << argv[2] << " " << argv[3] << " " << argv[4] << " [image] [labels]\n\n"; |
| 102 | std::cout << "No image provided: using random values\n\n"; |
| 103 | std::cout << "No text file with labels provided: skipping output accessor\n\n"; |
| 104 | } |
| 105 | else if(argc == 6) |
| 106 | { |
| 107 | data_path = argv[4]; |
| 108 | image = argv[5]; |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 109 | std::cout << "Usage: " << argv[0] << " " << argv[1] << " " << argv[2] << " " << argv[3] << " [labels]\n\n"; |
| 110 | std::cout << "No text file with labels provided: skipping output accessor\n\n"; |
| 111 | } |
| 112 | else |
| 113 | { |
Georgios Pinitas | cac13b1 | 2018-04-27 19:07:19 +0100 | [diff] [blame] | 114 | data_path = argv[4]; |
| 115 | image = argv[5]; |
| 116 | label = argv[6]; |
Georgios Pinitas | 7f530b3 | 2018-01-22 11:20:44 +0000 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | // Add model path to data path |
| 120 | if(!data_path.empty()) |
| 121 | { |
| 122 | data_path += model_path; |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | graph << target_hint |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 126 | << convolution_hint |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 127 | << depthwise_convolution_hint |
Georgios Pinitas | cac13b1 | 2018-04-27 19:07:19 +0100 | [diff] [blame] | 128 | << InputLayer(input_descriptor, |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 129 | get_input_accessor(image, std::move(preprocessor), false)) |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 130 | << ConvolutionLayer( |
Georgios Pinitas | 7f530b3 | 2018-01-22 11:20:44 +0000 | [diff] [blame] | 131 | 3U, 3U, 32U * depth_scale, |
Georgios Pinitas | cac13b1 | 2018-04-27 19:07:19 +0100 | [diff] [blame] | 132 | get_weights_accessor(data_path, "Conv2d_0_weights.npy", DataLayout::NCHW), |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 133 | std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), |
| 134 | PadStrideInfo(2, 2, 0, 1, 0, 1, DimensionRoundingType::FLOOR)) |
Georgios Pinitas | 5c2fb3f | 2018-05-01 15:26:20 +0100 | [diff] [blame] | 135 | .set_name("Conv2d_0") |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 136 | << BatchNormalizationLayer( |
Georgios Pinitas | 7f530b3 | 2018-01-22 11:20:44 +0000 | [diff] [blame] | 137 | get_weights_accessor(data_path, "Conv2d_0_BatchNorm_moving_mean.npy"), |
| 138 | get_weights_accessor(data_path, "Conv2d_0_BatchNorm_moving_variance.npy"), |
| 139 | get_weights_accessor(data_path, "Conv2d_0_BatchNorm_gamma.npy"), |
| 140 | get_weights_accessor(data_path, "Conv2d_0_BatchNorm_beta.npy"), |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 141 | 0.001f) |
Georgios Pinitas | 5c2fb3f | 2018-05-01 15:26:20 +0100 | [diff] [blame] | 142 | .set_name("Conv2d_0/BatchNorm") |
| 143 | << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::BOUNDED_RELU, 6.f)).set_name("Conv2d_0/Relu6"); |
Georgios Pinitas | 41c482d | 2018-04-17 13:23:26 +0100 | [diff] [blame] | 144 | graph << get_dwsc_node(data_path, "Conv2d_1", 64 * depth_scale, PadStrideInfo(1, 1, 1, 1), PadStrideInfo(1, 1, 0, 0)); |
| 145 | graph << get_dwsc_node(data_path, "Conv2d_2", 128 * depth_scale, PadStrideInfo(2, 2, 0, 1, 0, 1, DimensionRoundingType::CEIL), PadStrideInfo(1, 1, 0, 0)); |
| 146 | graph << get_dwsc_node(data_path, "Conv2d_3", 128 * depth_scale, PadStrideInfo(1, 1, 1, 1, 1, 1, DimensionRoundingType::CEIL), PadStrideInfo(1, 1, 0, 0)); |
| 147 | graph << get_dwsc_node(data_path, "Conv2d_4", 256 * depth_scale, PadStrideInfo(2, 2, 0, 1, 0, 1, DimensionRoundingType::CEIL), PadStrideInfo(1, 1, 0, 0)); |
| 148 | graph << get_dwsc_node(data_path, "Conv2d_5", 256 * depth_scale, PadStrideInfo(1, 1, 1, 1, 1, 1, DimensionRoundingType::CEIL), PadStrideInfo(1, 1, 0, 0)); |
| 149 | graph << get_dwsc_node(data_path, "Conv2d_6", 512 * depth_scale, PadStrideInfo(2, 2, 0, 1, 0, 1, DimensionRoundingType::CEIL), PadStrideInfo(1, 1, 0, 0)); |
| 150 | graph << get_dwsc_node(data_path, "Conv2d_7", 512 * depth_scale, PadStrideInfo(1, 1, 1, 1, 1, 1, DimensionRoundingType::CEIL), PadStrideInfo(1, 1, 0, 0)); |
| 151 | graph << get_dwsc_node(data_path, "Conv2d_8", 512 * depth_scale, PadStrideInfo(1, 1, 1, 1, 1, 1, DimensionRoundingType::CEIL), PadStrideInfo(1, 1, 0, 0)); |
| 152 | graph << get_dwsc_node(data_path, "Conv2d_9", 512 * depth_scale, PadStrideInfo(1, 1, 1, 1, 1, 1, DimensionRoundingType::CEIL), PadStrideInfo(1, 1, 0, 0)); |
| 153 | graph << get_dwsc_node(data_path, "Conv2d_10", 512 * depth_scale, PadStrideInfo(1, 1, 1, 1, 1, 1, DimensionRoundingType::CEIL), PadStrideInfo(1, 1, 0, 0)); |
| 154 | graph << get_dwsc_node(data_path, "Conv2d_11", 512 * depth_scale, PadStrideInfo(1, 1, 1, 1, 1, 1, DimensionRoundingType::CEIL), PadStrideInfo(1, 1, 0, 0)); |
| 155 | graph << get_dwsc_node(data_path, "Conv2d_12", 1024 * depth_scale, PadStrideInfo(2, 2, 0, 1, 0, 1, DimensionRoundingType::CEIL), PadStrideInfo(1, 1, 0, 0)); |
| 156 | graph << get_dwsc_node(data_path, "Conv2d_13", 1024 * depth_scale, PadStrideInfo(1, 1, 1, 1, 1, 1, DimensionRoundingType::CEIL), PadStrideInfo(1, 1, 0, 0)); |
Georgios Pinitas | 5c2fb3f | 2018-05-01 15:26:20 +0100 | [diff] [blame] | 157 | graph << PoolingLayer(PoolingLayerInfo(PoolingType::AVG)).set_name("Logits/AvgPool_1a") |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 158 | << ConvolutionLayer( |
| 159 | 1U, 1U, 1001U, |
Georgios Pinitas | cac13b1 | 2018-04-27 19:07:19 +0100 | [diff] [blame] | 160 | get_weights_accessor(data_path, "Logits_Conv2d_1c_1x1_weights.npy", DataLayout::NCHW), |
Georgios Pinitas | 7f530b3 | 2018-01-22 11:20:44 +0000 | [diff] [blame] | 161 | get_weights_accessor(data_path, "Logits_Conv2d_1c_1x1_biases.npy"), |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 162 | PadStrideInfo(1, 1, 0, 0)) |
Georgios Pinitas | 5c2fb3f | 2018-05-01 15:26:20 +0100 | [diff] [blame] | 163 | .set_name("Logits/Conv2d_1c_1x1") |
| 164 | << ReshapeLayer(TensorShape(1001U)).set_name("Reshape") |
| 165 | << SoftmaxLayer().set_name("Softmax") |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 166 | << OutputLayer(get_output_accessor(label, 5)); |
Gian Marco | c1b6e37 | 2018-02-21 18:03:26 +0000 | [diff] [blame] | 167 | |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 168 | // Finalize graph |
Georgios Pinitas | 9a8c672 | 2018-03-21 17:52:35 +0000 | [diff] [blame] | 169 | GraphConfig config; |
Georgios Pinitas | 3d1489d | 2018-05-03 20:47:16 +0100 | [diff] [blame] | 170 | config.use_tuner = (target == 2); |
Georgios Pinitas | 9a8c672 | 2018-03-21 17:52:35 +0000 | [diff] [blame] | 171 | graph.finalize(target_hint, config); |
Georgios Pinitas | 236bfe7 | 2017-11-23 15:59:55 +0000 | [diff] [blame] | 172 | } |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 173 | void do_run() override |
Georgios Pinitas | 236bfe7 | 2017-11-23 15:59:55 +0000 | [diff] [blame] | 174 | { |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 175 | // Run graph |
| 176 | graph.run(); |
Georgios Pinitas | 236bfe7 | 2017-11-23 15:59:55 +0000 | [diff] [blame] | 177 | } |
| 178 | |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 179 | private: |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 180 | Stream graph{ 0, "MobileNetV1" }; |
Gian Marco | bfa3b52 | 2017-12-12 10:08:38 +0000 | [diff] [blame] | 181 | |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 182 | BranchLayer get_dwsc_node(const std::string &data_path, std::string &¶m_path, |
| 183 | unsigned int conv_filt, |
| 184 | PadStrideInfo dwc_pad_stride_info, PadStrideInfo conv_pad_stride_info) |
| 185 | { |
Georgios Pinitas | 7f530b3 | 2018-01-22 11:20:44 +0000 | [diff] [blame] | 186 | std::string total_path = param_path + "_"; |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 187 | SubStream sg(graph); |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 188 | sg << DepthwiseConvolutionLayer( |
| 189 | 3U, 3U, |
Georgios Pinitas | cac13b1 | 2018-04-27 19:07:19 +0100 | [diff] [blame] | 190 | get_weights_accessor(data_path, total_path + "depthwise_depthwise_weights.npy", DataLayout::NCHW), |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 191 | std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 192 | dwc_pad_stride_info) |
Georgios Pinitas | 5c2fb3f | 2018-05-01 15:26:20 +0100 | [diff] [blame] | 193 | .set_name(total_path + "depthwise/depthwise") |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 194 | << BatchNormalizationLayer( |
| 195 | get_weights_accessor(data_path, total_path + "depthwise_BatchNorm_moving_mean.npy"), |
| 196 | get_weights_accessor(data_path, total_path + "depthwise_BatchNorm_moving_variance.npy"), |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 197 | get_weights_accessor(data_path, total_path + "depthwise_BatchNorm_gamma.npy"), |
Georgios Pinitas | 7f530b3 | 2018-01-22 11:20:44 +0000 | [diff] [blame] | 198 | get_weights_accessor(data_path, total_path + "depthwise_BatchNorm_beta.npy"), |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 199 | 0.001f) |
Georgios Pinitas | 5c2fb3f | 2018-05-01 15:26:20 +0100 | [diff] [blame] | 200 | .set_name(total_path + "depthwise/BatchNorm") |
| 201 | << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::BOUNDED_RELU, 6.f)).set_name(total_path + "depthwise/Relu6") |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 202 | << ConvolutionLayer( |
| 203 | 1U, 1U, conv_filt, |
Georgios Pinitas | cac13b1 | 2018-04-27 19:07:19 +0100 | [diff] [blame] | 204 | get_weights_accessor(data_path, total_path + "pointwise_weights.npy", DataLayout::NCHW), |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 205 | std::unique_ptr<arm_compute::graph::ITensorAccessor>(nullptr), |
| 206 | conv_pad_stride_info) |
Georgios Pinitas | 5c2fb3f | 2018-05-01 15:26:20 +0100 | [diff] [blame] | 207 | .set_name(total_path + "pointwise/Conv2D") |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 208 | << BatchNormalizationLayer( |
| 209 | get_weights_accessor(data_path, total_path + "pointwise_BatchNorm_moving_mean.npy"), |
| 210 | get_weights_accessor(data_path, total_path + "pointwise_BatchNorm_moving_variance.npy"), |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 211 | get_weights_accessor(data_path, total_path + "pointwise_BatchNorm_gamma.npy"), |
Georgios Pinitas | 7f530b3 | 2018-01-22 11:20:44 +0000 | [diff] [blame] | 212 | get_weights_accessor(data_path, total_path + "pointwise_BatchNorm_beta.npy"), |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 213 | 0.001f) |
Georgios Pinitas | 5c2fb3f | 2018-05-01 15:26:20 +0100 | [diff] [blame] | 214 | .set_name(total_path + "pointwise/BatchNorm") |
| 215 | << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::BOUNDED_RELU, 6.f)).set_name(total_path + "pointwise/Relu6"); |
Gian Marco | bfa3b52 | 2017-12-12 10:08:38 +0000 | [diff] [blame] | 216 | |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 217 | return BranchLayer(std::move(sg)); |
| 218 | } |
| 219 | }; |
Georgios Pinitas | 236bfe7 | 2017-11-23 15:59:55 +0000 | [diff] [blame] | 220 | |
| 221 | /** Main program for MobileNetV1 |
| 222 | * |
| 223 | * @param[in] argc Number of arguments |
Georgios Pinitas | 7f530b3 | 2018-01-22 11:20:44 +0000 | [diff] [blame] | 224 | * @param[in] argv Arguments ( [optional] Target (0 = NEON, 1 = OpenCL), |
| 225 | * [optional] Model ID (0 = MobileNetV1_1.0_224, 1 = MobileNetV1_0.75_160), |
| 226 | * [optional] Path to the weights folder, |
| 227 | * [optional] image, |
| 228 | * [optional] labels ) |
Georgios Pinitas | 236bfe7 | 2017-11-23 15:59:55 +0000 | [diff] [blame] | 229 | */ |
Anthony Barbier | 6db0ff5 | 2018-01-05 10:59:12 +0000 | [diff] [blame] | 230 | int main(int argc, char **argv) |
Georgios Pinitas | 236bfe7 | 2017-11-23 15:59:55 +0000 | [diff] [blame] | 231 | { |
Michalis Spyrou | 2b5f0f2 | 2018-01-10 14:08:50 +0000 | [diff] [blame] | 232 | return arm_compute::utils::run_example<GraphMobilenetExample>(argc, argv); |
Georgios Pinitas | 236bfe7 | 2017-11-23 15:59:55 +0000 | [diff] [blame] | 233 | } |