blob: 08cd4a47b1f856a92597417cd6f9e0c752160563 [file] [log] [blame]
Michele Di Giorgio3418ba52019-03-01 17:19:55 +00001/*
SiCong Li4841c972021-02-03 12:17:35 +00002 * Copyright (c) 2019-2021 Arm Limited.
Michele Di Giorgio3418ba52019-03-01 17:19:55 +00003 *
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.h"
25#include "arm_compute/graph/Types.h"
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010026
Michele Di Giorgio3418ba52019-03-01 17:19:55 +000027#include "support/ToolchainSupport.h"
28#include "utils/CommonGraphOptions.h"
29#include "utils/GraphUtils.h"
30#include "utils/Utils.h"
31
32using namespace arm_compute::utils;
33using namespace arm_compute::graph;
34using namespace arm_compute::graph::frontend;
35using namespace arm_compute::graph_utils;
36
37/** Example demonstrating how to implement DeepSpeech v0.4.1's network using the Compute Library's graph API */
38class GraphDeepSpeechExample : public Example
39{
40public:
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010041 GraphDeepSpeechExample() : cmd_parser(), common_opts(cmd_parser), common_params(), graph(0, "DeepSpeech v0.4.1")
Michele Di Giorgio3418ba52019-03-01 17:19:55 +000042 {
43 }
44 bool do_setup(int argc, char **argv) override
45 {
46 // Parse arguments
47 cmd_parser.parse(argc, argv);
Georgios Pinitascd60a5f2019-08-21 17:06:54 +010048 cmd_parser.validate();
Michele Di Giorgio3418ba52019-03-01 17:19:55 +000049
50 // Consume common parameters
51 common_params = consume_common_graph_parameters(common_opts);
52
53 // Return when help menu is requested
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010054 if (common_params.help)
Michele Di Giorgio3418ba52019-03-01 17:19:55 +000055 {
56 cmd_parser.print_help(argv[0]);
57 return false;
58 }
59
Michele Di Giorgio3418ba52019-03-01 17:19:55 +000060 // Print parameter values
61 std::cout << common_params << std::endl;
62
63 // Get trainable parameters data path
64 std::string data_path = common_params.data_path;
65 const std::string model_path = "/cnn_data/deepspeech_model/";
66
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010067 if (!data_path.empty())
Michele Di Giorgio3418ba52019-03-01 17:19:55 +000068 {
69 data_path += model_path;
70 }
71
72 // How many timesteps to process at once, higher values mean more latency
73 // Notice that this corresponds to the number of LSTM cells that will be instantiated
74 const unsigned int n_steps = 16;
75
76 // ReLU clipping value for non-recurrent layers
77 const float cell_clip = 20.f;
78
79 // Create input descriptor
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010080 const TensorShape tensor_shape =
81 permute_shape(TensorShape(26U, 19U, n_steps, 1U), DataLayout::NHWC, common_params.data_layout);
82 TensorDescriptor input_descriptor =
83 TensorDescriptor(tensor_shape, common_params.data_type).set_layout(common_params.data_layout);
Michele Di Giorgio3418ba52019-03-01 17:19:55 +000084
85 // Set weights trained layout
86 const DataLayout weights_layout = DataLayout::NHWC;
87
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010088 graph << common_params.target << common_params.fast_math_hint
Michele Di Giorgio3418ba52019-03-01 17:19:55 +000089 << InputLayer(input_descriptor,
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010090 get_weights_accessor(data_path, "input_values_x" + std::to_string(n_steps) + ".npy",
91 weights_layout))
92 .set_name("input_node");
Michele Di Giorgio3418ba52019-03-01 17:19:55 +000093
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010094 if (common_params.data_layout == DataLayout::NCHW)
Michele Di Giorgio3418ba52019-03-01 17:19:55 +000095 {
96 graph << PermuteLayer(PermutationVector(2U, 0U, 1U), common_params.data_layout).set_name("permute_to_nhwc");
97 }
98
99 graph << ReshapeLayer(TensorShape(494U, n_steps)).set_name("Reshape_input")
100 // Layer 1
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100101 << FullyConnectedLayer(2048U, get_weights_accessor(data_path, "h1_transpose.npy", weights_layout),
102 get_weights_accessor(data_path, "MatMul_bias.npy"))
103 .set_name("fc0")
Michele Di Giorgio3418ba52019-03-01 17:19:55 +0000104 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::BOUNDED_RELU, cell_clip))
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100105 .set_name("Relu")
Michele Di Giorgio3418ba52019-03-01 17:19:55 +0000106 // Layer 2
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100107 << FullyConnectedLayer(2048U, get_weights_accessor(data_path, "h2_transpose.npy", weights_layout),
108 get_weights_accessor(data_path, "MatMul_1_bias.npy"))
109 .set_name("fc1")
Michele Di Giorgio3418ba52019-03-01 17:19:55 +0000110 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::BOUNDED_RELU, cell_clip))
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100111 .set_name("Relu_1")
Michele Di Giorgio3418ba52019-03-01 17:19:55 +0000112 // Layer 3
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100113 << FullyConnectedLayer(2048U, get_weights_accessor(data_path, "h3_transpose.npy", weights_layout),
114 get_weights_accessor(data_path, "MatMul_2_bias.npy"))
115 .set_name("fc2")
Michele Di Giorgio3418ba52019-03-01 17:19:55 +0000116 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::BOUNDED_RELU, cell_clip))
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100117 .set_name("Relu_2")
Michele Di Giorgio3418ba52019-03-01 17:19:55 +0000118 // Layer 4
119 << ReshapeLayer(TensorShape(2048U, 1U, n_steps)).set_name("Reshape_1");
120
121 // Unstack Layer (using SplitLayerNode)
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100122 NodeParams unstack_params = {"unstack", graph.hints().target_hint};
123 NodeID unstack_nid =
124 GraphBuilder::add_split_node(graph.graph(), unstack_params, {graph.tail_node(), 0}, n_steps, 2);
Michele Di Giorgio3418ba52019-03-01 17:19:55 +0000125
126 // Create input state descriptor
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100127 TensorDescriptor state_descriptor =
128 TensorDescriptor(TensorShape(2048U), common_params.data_type).set_layout(common_params.data_layout);
129 SubStream previous_state(graph);
130 SubStream add_y(graph);
Michele Di Giorgio3418ba52019-03-01 17:19:55 +0000131
132 // Initial state for LSTM is all zeroes for both state_h and state_c, therefore only one input is created
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100133 previous_state << InputLayer(state_descriptor, get_weights_accessor(data_path, "zeros.npy"))
134 .set_name("previous_state_c_h");
135 add_y << InputLayer(state_descriptor, get_weights_accessor(data_path, "ones.npy")).set_name("add_y");
Michele Di Giorgio3418ba52019-03-01 17:19:55 +0000136
Michele Di Giorgio3418ba52019-03-01 17:19:55 +0000137 // Create LSTM Fully Connected weights and bias descriptors
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100138 TensorDescriptor lstm_weights_descriptor =
139 TensorDescriptor(TensorShape(4096U, 8192U), common_params.data_type).set_layout(common_params.data_layout);
140 TensorDescriptor lstm_bias_descriptor =
141 TensorDescriptor(TensorShape(8192U), common_params.data_type).set_layout(common_params.data_layout);
142 SubStream lstm_fc_weights(graph);
143 SubStream lstm_fc_bias(graph);
144 lstm_fc_weights << ConstantLayer(
145 lstm_weights_descriptor,
146 get_weights_accessor(data_path, "rnn_lstm_cell_kernel_transpose.npy", weights_layout))
147 .set_name("h5/transpose");
Michalis Spyroubd188112019-10-02 15:43:44 +0100148 lstm_fc_bias << ConstantLayer(lstm_bias_descriptor,
149 get_weights_accessor(data_path, "rnn_lstm_cell_MatMul_bias.npy"))
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100150 .set_name("MatMul_3_bias");
Michele Di Giorgio3418ba52019-03-01 17:19:55 +0000151
152 // LSTM Block
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100153 std::pair<SubStream, SubStream> new_state_1 =
154 add_lstm_cell(unstack_nid, 0, previous_state, previous_state, add_y, lstm_fc_weights, lstm_fc_bias);
155 std::pair<SubStream, SubStream> new_state_2 =
156 add_lstm_cell(unstack_nid, 1, new_state_1.first, new_state_1.second, add_y, lstm_fc_weights, lstm_fc_bias);
157 std::pair<SubStream, SubStream> new_state_3 =
158 add_lstm_cell(unstack_nid, 2, new_state_2.first, new_state_2.second, add_y, lstm_fc_weights, lstm_fc_bias);
159 std::pair<SubStream, SubStream> new_state_4 =
160 add_lstm_cell(unstack_nid, 3, new_state_3.first, new_state_3.second, add_y, lstm_fc_weights, lstm_fc_bias);
161 std::pair<SubStream, SubStream> new_state_5 =
162 add_lstm_cell(unstack_nid, 4, new_state_4.first, new_state_4.second, add_y, lstm_fc_weights, lstm_fc_bias);
163 std::pair<SubStream, SubStream> new_state_6 =
164 add_lstm_cell(unstack_nid, 5, new_state_5.first, new_state_5.second, add_y, lstm_fc_weights, lstm_fc_bias);
165 std::pair<SubStream, SubStream> new_state_7 =
166 add_lstm_cell(unstack_nid, 6, new_state_6.first, new_state_6.second, add_y, lstm_fc_weights, lstm_fc_bias);
167 std::pair<SubStream, SubStream> new_state_8 =
168 add_lstm_cell(unstack_nid, 7, new_state_7.first, new_state_7.second, add_y, lstm_fc_weights, lstm_fc_bias);
169 std::pair<SubStream, SubStream> new_state_9 =
170 add_lstm_cell(unstack_nid, 8, new_state_8.first, new_state_8.second, add_y, lstm_fc_weights, lstm_fc_bias);
171 std::pair<SubStream, SubStream> new_state_10 =
172 add_lstm_cell(unstack_nid, 9, new_state_9.first, new_state_9.second, add_y, lstm_fc_weights, lstm_fc_bias);
173 std::pair<SubStream, SubStream> new_state_11 = add_lstm_cell(
174 unstack_nid, 10, new_state_10.first, new_state_10.second, add_y, lstm_fc_weights, lstm_fc_bias);
175 std::pair<SubStream, SubStream> new_state_12 = add_lstm_cell(
176 unstack_nid, 11, new_state_11.first, new_state_11.second, add_y, lstm_fc_weights, lstm_fc_bias);
177 std::pair<SubStream, SubStream> new_state_13 = add_lstm_cell(
178 unstack_nid, 12, new_state_12.first, new_state_12.second, add_y, lstm_fc_weights, lstm_fc_bias);
179 std::pair<SubStream, SubStream> new_state_14 = add_lstm_cell(
180 unstack_nid, 13, new_state_13.first, new_state_13.second, add_y, lstm_fc_weights, lstm_fc_bias);
181 std::pair<SubStream, SubStream> new_state_15 = add_lstm_cell(
182 unstack_nid, 14, new_state_14.first, new_state_14.second, add_y, lstm_fc_weights, lstm_fc_bias);
183 std::pair<SubStream, SubStream> new_state_16 = add_lstm_cell(
184 unstack_nid, 15, new_state_15.first, new_state_15.second, add_y, lstm_fc_weights, lstm_fc_bias);
Michele Di Giorgio3418ba52019-03-01 17:19:55 +0000185
Michalis Spyroubd188112019-10-02 15:43:44 +0100186 // Concatenate new states on height
187 const int axis = 1;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100188 graph << StackLayer(axis, std::move(new_state_1.second), std::move(new_state_2.second),
189 std::move(new_state_3.second), std::move(new_state_4.second), std::move(new_state_5.second),
190 std::move(new_state_6.second), std::move(new_state_7.second), std::move(new_state_8.second),
191 std::move(new_state_9.second), std::move(new_state_10.second),
192 std::move(new_state_11.second), std::move(new_state_12.second),
193 std::move(new_state_13.second), std::move(new_state_14.second),
194 std::move(new_state_15.second), std::move(new_state_16.second))
195 .set_name("concat");
Michele Di Giorgio3418ba52019-03-01 17:19:55 +0000196
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100197 graph << FullyConnectedLayer(2048U, get_weights_accessor(data_path, "h5_transpose.npy", weights_layout),
198 get_weights_accessor(data_path, "MatMul_3_bias.npy"))
199 .set_name("fc3")
Michele Di Giorgio3418ba52019-03-01 17:19:55 +0000200 << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::BOUNDED_RELU, cell_clip))
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100201 .set_name("Relu3")
202 << FullyConnectedLayer(29U, get_weights_accessor(data_path, "h6_transpose.npy", weights_layout),
203 get_weights_accessor(data_path, "MatMul_4_bias.npy"))
204 .set_name("fc3")
Michele Di Giorgio3418ba52019-03-01 17:19:55 +0000205 << SoftmaxLayer().set_name("logits");
206
207 graph << OutputLayer(get_output_accessor(common_params, 5));
208
209 // Finalize graph
210 GraphConfig config;
SiCongLif466d752021-03-01 15:26:18 +0000211 config.num_threads = common_params.threads;
212 config.use_tuner = common_params.enable_tuner;
213 config.tuner_file = common_params.tuner_file;
214 config.mlgo_file = common_params.mlgo_file;
215 config.use_synthetic_type = arm_compute::is_data_type_quantized(common_params.data_type);
216 config.synthetic_type = common_params.data_type;
Michele Di Giorgio3418ba52019-03-01 17:19:55 +0000217
218 graph.finalize(common_params.target, config);
219
220 return true;
221 }
222 void do_run() override
223 {
224 // Run graph
225 graph.run();
226 }
227
228private:
229 CommandLineParser cmd_parser;
230 CommonGraphOptions common_opts;
231 CommonGraphParams common_params;
232 Stream graph;
233
234 Status set_node_params(Graph &g, NodeID nid, NodeParams &params)
235 {
236 INode *node = g.node(nid);
237 ARM_COMPUTE_RETURN_ERROR_ON(!node);
238
239 node->set_common_node_parameters(params);
240
241 return Status{};
242 }
243
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100244 std::pair<SubStream, SubStream> add_lstm_cell(NodeID unstack_nid,
Michele Di Giorgio3418ba52019-03-01 17:19:55 +0000245 unsigned int unstack_idx,
246 SubStream previous_state_c,
247 SubStream previous_state_h,
Michalis Spyroubd188112019-10-02 15:43:44 +0100248 SubStream add_y,
249 SubStream lstm_fc_weights,
250 SubStream lstm_fc_bias)
Michele Di Giorgio3418ba52019-03-01 17:19:55 +0000251 {
252 const std::string cell_name("rnn/lstm_cell_" + std::to_string(unstack_idx));
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100253 const DataLayoutDimension concat_dim =
254 (common_params.data_layout == DataLayout::NHWC) ? DataLayoutDimension::CHANNEL : DataLayoutDimension::WIDTH;
Michele Di Giorgio3418ba52019-03-01 17:19:55 +0000255
256 // Concatenate result of Unstack with previous_state_h
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100257 NodeParams concat_params = {cell_name + "/concat", graph.hints().target_hint};
Michele Di Giorgio3418ba52019-03-01 17:19:55 +0000258 NodeID concat_nid = graph.graph().add_node<ConcatenateLayerNode>(2, concat_dim);
259 graph.graph().add_connection(unstack_nid, unstack_idx, concat_nid, 0);
260 graph.graph().add_connection(previous_state_h.tail_node(), 0, concat_nid, 1);
261 set_node_params(graph.graph(), concat_nid, concat_params);
262 graph.forward_tail(concat_nid);
263
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100264 graph << FullyConnectedLayer(8192U, lstm_fc_weights, lstm_fc_bias).set_name(cell_name + "/BiasAdd");
Michele Di Giorgio3418ba52019-03-01 17:19:55 +0000265
266 // Split Layer
267 const unsigned int num_splits = 4;
268 const unsigned int split_axis = 0;
269
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100270 NodeParams split_params = {cell_name + "/split", graph.hints().target_hint};
271 NodeID split_nid =
272 GraphBuilder::add_split_node(graph.graph(), split_params, {graph.tail_node(), 0}, num_splits, split_axis);
Michele Di Giorgio3418ba52019-03-01 17:19:55 +0000273
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100274 NodeParams sigmoid_1_params = {cell_name + "/Sigmoid_1", graph.hints().target_hint};
275 NodeParams add_params = {cell_name + "/add", graph.hints().target_hint};
276 NodeParams sigmoid_2_params = {cell_name + "/Sigmoid_2", graph.hints().target_hint};
277 NodeParams tanh_params = {cell_name + "/Tanh", graph.hints().target_hint};
Michele Di Giorgio3418ba52019-03-01 17:19:55 +0000278
279 // Sigmoid 1 (first split)
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100280 NodeID sigmoid_1_nid = graph.graph().add_node<ActivationLayerNode>(
281 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LOGISTIC));
Michele Di Giorgio3418ba52019-03-01 17:19:55 +0000282 graph.graph().add_connection(split_nid, 0, sigmoid_1_nid, 0);
283 set_node_params(graph.graph(), sigmoid_1_nid, sigmoid_1_params);
284
285 // Tanh (second split)
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100286 NodeID tanh_nid = graph.graph().add_node<ActivationLayerNode>(
287 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::TANH, 1.f, 1.f));
Michele Di Giorgio3418ba52019-03-01 17:19:55 +0000288 graph.graph().add_connection(split_nid, 1, tanh_nid, 0);
289 set_node_params(graph.graph(), tanh_nid, tanh_params);
290
291 SubStream tanh_ss(graph);
292 tanh_ss.forward_tail(tanh_nid);
293
294 // Add (third split)
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100295 NodeID add_nid =
296 graph.graph().add_node<EltwiseLayerNode>(descriptors::EltwiseLayerDescriptor{EltwiseOperation::Add});
Michele Di Giorgio3418ba52019-03-01 17:19:55 +0000297 graph.graph().add_connection(split_nid, 2, add_nid, 0);
298 graph.graph().add_connection(add_y.tail_node(), 0, add_nid, 1);
299 set_node_params(graph.graph(), add_nid, add_params);
300
301 // Sigmoid 2 (fourth split)
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100302 NodeID sigmoid_2_nid = graph.graph().add_node<ActivationLayerNode>(
303 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LOGISTIC));
Michele Di Giorgio3418ba52019-03-01 17:19:55 +0000304 graph.graph().add_connection(split_nid, 3, sigmoid_2_nid, 0);
305 set_node_params(graph.graph(), sigmoid_2_nid, sigmoid_2_params);
306
Michalis Spyroubcfd09a2019-05-01 13:03:59 +0100307 SubStream sigmoid_1_ss(graph);
308 sigmoid_1_ss.forward_tail(sigmoid_1_nid);
309 SubStream mul_1_ss(sigmoid_1_ss);
310 mul_1_ss << EltwiseLayer(std::move(sigmoid_1_ss), std::move(tanh_ss), EltwiseOperation::Mul)
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100311 .set_name(cell_name + "/mul_1");
Michele Di Giorgio3418ba52019-03-01 17:19:55 +0000312
Michalis Spyroubcfd09a2019-05-01 13:03:59 +0100313 SubStream tanh_1_ss_tmp(graph);
314 tanh_1_ss_tmp.forward_tail(add_nid);
Michele Di Giorgio3418ba52019-03-01 17:19:55 +0000315
Michalis Spyroubcfd09a2019-05-01 13:03:59 +0100316 tanh_1_ss_tmp << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LOGISTIC))
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100317 .set_name(cell_name + "/Sigmoid");
Michalis Spyroubcfd09a2019-05-01 13:03:59 +0100318 SubStream tanh_1_ss_tmp2(tanh_1_ss_tmp);
319 tanh_1_ss_tmp2 << EltwiseLayer(std::move(tanh_1_ss_tmp), std::move(previous_state_c), EltwiseOperation::Mul)
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100320 .set_name(cell_name + "/mul");
Michalis Spyroubcfd09a2019-05-01 13:03:59 +0100321 SubStream tanh_1_ss(tanh_1_ss_tmp2);
322 tanh_1_ss << EltwiseLayer(std::move(tanh_1_ss_tmp2), std::move(mul_1_ss), EltwiseOperation::Add)
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100323 .set_name(cell_name + "/new_state_c");
Michele Di Giorgio3418ba52019-03-01 17:19:55 +0000324 SubStream new_state_c(tanh_1_ss);
325
326 tanh_1_ss << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::TANH, 1.f, 1.f))
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100327 .set_name(cell_name + "/Tanh_1");
Michele Di Giorgio3418ba52019-03-01 17:19:55 +0000328
329 SubStream sigmoid_2_ss(graph);
330 sigmoid_2_ss.forward_tail(sigmoid_2_nid);
331 graph << EltwiseLayer(std::move(sigmoid_2_ss), std::move(tanh_1_ss), EltwiseOperation::Mul)
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100332 .set_name(cell_name + "/new_state_h");
Michele Di Giorgio3418ba52019-03-01 17:19:55 +0000333
334 SubStream new_state_h(graph);
335 return std::pair<SubStream, SubStream>(new_state_c, new_state_h);
336 }
337};
338
339/** Main program for DeepSpeech v0.4.1
340 *
341 * Model is based on:
342 * https://arxiv.org/abs/1412.5567
343 * "Deep Speech: Scaling up end-to-end speech recognition"
344 * Awni Hannun, Carl Case, Jared Casper, Bryan Catanzaro, Greg Diamos, Erich Elsen, Ryan Prenger, Sanjeev Satheesh, Shubho Sengupta, Adam Coates, Andrew Y. Ng
345 *
346 * Provenance: https://github.com/mozilla/DeepSpeech
347 *
348 * @note To list all the possible arguments execute the binary appended with the --help option
349 *
350 * @param[in] argc Number of arguments
351 * @param[in] argv Arguments
352 *
353 * @return Return code
354 */
355int main(int argc, char **argv)
356{
357 return arm_compute::utils::run_example<GraphDeepSpeechExample>(argc, argv);
358}