blob: b4f2fadf4aa67eb79b5967dfe624464ad3d5878c [file] [log] [blame]
Sang-Hoon Park68001172020-03-06 16:32:01 +00001/*
SiCong Li4841c972021-02-03 12:17:35 +00002 * Copyright (c) 2020-2021 Arm Limited.
Sang-Hoon Park68001172020-03-06 16:32:01 +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
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010025#include "graph_edsr.h"
26
Sang-Hoon Park68001172020-03-06 16:32:01 +000027#include "arm_compute/graph/Utils.h"
28
29#include "support/ToolchainSupport.h"
30#include "utils/CommonGraphOptions.h"
31#include "utils/Utils.h"
32
Sang-Hoon Park68001172020-03-06 16:32:01 +000033using namespace arm_compute::graph;
34using namespace arm_compute::utils;
35
36class GraphEdsrExample : public Example
37{
38public:
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010039 GraphEdsrExample() : cmd_parser(), common_opts(cmd_parser), common_params()
Sang-Hoon Park68001172020-03-06 16:32:01 +000040 {
41 expected_output_filename = cmd_parser.add_option<SimpleOption<std::string>>("expected-output-filename", "");
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010042 expected_output_filename->set_help(
43 "Name of npy file containing the expected output to validate the graph output.");
Sang-Hoon Park68001172020-03-06 16:32:01 +000044 }
45
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010046 GraphEdsrExample(const GraphEdsrExample &) = delete;
Sang-Hoon Park68001172020-03-06 16:32:01 +000047 GraphEdsrExample &operator=(const GraphEdsrExample &) = delete;
Sang-Hoon Park6cd1c9b2020-03-19 16:22:14 +000048 ~GraphEdsrExample() override = default;
Sang-Hoon Park68001172020-03-06 16:32:01 +000049
50 bool do_setup(int argc, char **argv) override
51 {
52 // Parse arguments
53 cmd_parser.parse(argc, argv);
54 cmd_parser.validate();
55
56 // Consume common parameters
57 common_params = consume_common_graph_parameters(common_opts);
58
59 // Return when help menu is requested
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010060 if (common_params.help)
Sang-Hoon Park68001172020-03-06 16:32:01 +000061 {
62 cmd_parser.print_help(argv[0]);
63 return false;
64 }
65
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010066 ARM_COMPUTE_EXIT_ON_MSG(common_params.data_type != DataType::QASYMM8,
67 "Only QASYMM8 is supported for this graph example");
Sang-Hoon Park4df2cf32020-04-02 16:52:47 +010068
Sang-Hoon Park68001172020-03-06 16:32:01 +000069 // Print parameter values
70 std::cout << common_params << std::endl;
71
72 model.setup(common_params, *expected_output_filename);
73
74 GraphConfig config;
75 config.num_threads = common_params.threads;
76 config.use_tuner = common_params.enable_tuner;
77 config.tuner_mode = common_params.tuner_mode;
78 config.tuner_file = common_params.tuner_file;
SiCong Li4841c972021-02-03 12:17:35 +000079 config.mlgo_file = common_params.mlgo_file;
Sang-Hoon Park68001172020-03-06 16:32:01 +000080
81 context.set_config(config);
82
83 auto pass_manager = create_default_pass_manager(common_params.target, config);
84 manager.finalize_graph(model.graph(), context, pass_manager, common_params.target);
85
86 return true;
87 }
88
89 void do_run() override
90 {
91 manager.execute_graph(model.graph());
92 }
93
94private:
95 CommandLineParser cmd_parser;
96 CommonGraphOptions common_opts;
97 CommonGraphParams common_params;
98
99 GraphContext context{};
100 GraphManager manager{};
101
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100102 SimpleOption<std::string> *expected_output_filename{nullptr};
Sang-Hoon Park68001172020-03-06 16:32:01 +0000103
104 GraphEdsr model{};
105};
106
Michele Di Giorgioe4340a42020-08-26 14:48:57 +0100107/** Internal implementation of UINT8 EDSR with some modifications from the paper.
108 * The sub-pixel convolution has been replaced with a deconvolution layer. This
109 * operation is mathematically the same.
110 *
111 * Convolution replaced by deconvolution:
112 * https://arxiv.org/abs/1609.07009
113 * "Is the deconvolution layer the same as a convolutional layer?"
114 * Wenzhe Shi, Jose Caballero, Lucas Theis, Ferenc Huszar, Andrew Aitken, Christian Ledig, Zehan Wang
115 *
116 * Original model is:
117 * https://arxiv.org/abs/1707.02921
118 * "Enhanced Deep Residual Networks for Single Image Super-Resolution"
119 * Bee Lim, Sanghyun Son, Heewon Kim, Seungjun Nah, Kyoung Mu Lee
120 *
121 * @note To list all the possible arguments execute the binary appended with the --help option
122 *
123 * @param[in] argc Number of arguments
124 * @param[in] argv Arguments
125 *
126 * @return Return code
127 */
Sang-Hoon Park68001172020-03-06 16:32:01 +0000128int main(int argc, char **argv)
129{
130 return run_example<GraphEdsrExample>(argc, argv);
131}