blob: 0e41f1215561730c88f2b4353dd48bee05bd684b [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
25#include "arm_compute/graph/Utils.h"
26
27#include "support/ToolchainSupport.h"
28#include "utils/CommonGraphOptions.h"
29#include "utils/Utils.h"
30
31#include "graph_edsr.h"
32
33using namespace arm_compute::graph;
34using namespace arm_compute::utils;
35
36class GraphEdsrExample : public Example
37{
38public:
39 GraphEdsrExample()
40 : cmd_parser(), common_opts(cmd_parser), common_params()
41 {
42 expected_output_filename = cmd_parser.add_option<SimpleOption<std::string>>("expected-output-filename", "");
43 expected_output_filename->set_help("Name of npy file containing the expected output to validate the graph output.");
44 }
45
46 GraphEdsrExample(const GraphEdsrExample &) = delete;
47 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
60 if(common_params.help)
61 {
62 cmd_parser.print_help(argv[0]);
63 return false;
64 }
65
Sang-Hoon Park4df2cf32020-04-02 16:52:47 +010066 ARM_COMPUTE_EXIT_ON_MSG(common_params.data_type != DataType::QASYMM8, "Only QASYMM8 is supported for this graph example");
67
Sang-Hoon Park68001172020-03-06 16:32:01 +000068 // Print parameter values
69 std::cout << common_params << std::endl;
70
71 model.setup(common_params, *expected_output_filename);
72
73 GraphConfig config;
74 config.num_threads = common_params.threads;
75 config.use_tuner = common_params.enable_tuner;
76 config.tuner_mode = common_params.tuner_mode;
77 config.tuner_file = common_params.tuner_file;
SiCong Li4841c972021-02-03 12:17:35 +000078 config.mlgo_file = common_params.mlgo_file;
Sang-Hoon Park68001172020-03-06 16:32:01 +000079
80 context.set_config(config);
81
82 auto pass_manager = create_default_pass_manager(common_params.target, config);
83 manager.finalize_graph(model.graph(), context, pass_manager, common_params.target);
84
85 return true;
86 }
87
88 void do_run() override
89 {
90 manager.execute_graph(model.graph());
91 }
92
93private:
94 CommandLineParser cmd_parser;
95 CommonGraphOptions common_opts;
96 CommonGraphParams common_params;
97
98 GraphContext context{};
99 GraphManager manager{};
100
101 SimpleOption<std::string> *expected_output_filename{ nullptr };
102
103 GraphEdsr model{};
104};
105
Michele Di Giorgioe4340a42020-08-26 14:48:57 +0100106/** Internal implementation of UINT8 EDSR with some modifications from the paper.
107 * The sub-pixel convolution has been replaced with a deconvolution layer. This
108 * operation is mathematically the same.
109 *
110 * Convolution replaced by deconvolution:
111 * https://arxiv.org/abs/1609.07009
112 * "Is the deconvolution layer the same as a convolutional layer?"
113 * Wenzhe Shi, Jose Caballero, Lucas Theis, Ferenc Huszar, Andrew Aitken, Christian Ledig, Zehan Wang
114 *
115 * Original model is:
116 * https://arxiv.org/abs/1707.02921
117 * "Enhanced Deep Residual Networks for Single Image Super-Resolution"
118 * Bee Lim, Sanghyun Son, Heewon Kim, Seungjun Nah, Kyoung Mu Lee
119 *
120 * @note To list all the possible arguments execute the binary appended with the --help option
121 *
122 * @param[in] argc Number of arguments
123 * @param[in] argv Arguments
124 *
125 * @return Return code
126 */
Sang-Hoon Park68001172020-03-06 16:32:01 +0000127int main(int argc, char **argv)
128{
129 return run_example<GraphEdsrExample>(argc, argv);
130}