blob: 77783d97ed1f8b84f9d0e6f62653a52e4d565951 [file] [log] [blame]
Sang-Hoon Park68001172020-03-06 16:32:01 +00001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2020 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;
78
79 context.set_config(config);
80
81 auto pass_manager = create_default_pass_manager(common_params.target, config);
82 manager.finalize_graph(model.graph(), context, pass_manager, common_params.target);
83
84 return true;
85 }
86
87 void do_run() override
88 {
89 manager.execute_graph(model.graph());
90 }
91
92private:
93 CommandLineParser cmd_parser;
94 CommonGraphOptions common_opts;
95 CommonGraphParams common_params;
96
97 GraphContext context{};
98 GraphManager manager{};
99
100 SimpleOption<std::string> *expected_output_filename{ nullptr };
101
102 GraphEdsr model{};
103};
104
Michele Di Giorgioe4340a42020-08-26 14:48:57 +0100105/** Internal implementation of UINT8 EDSR with some modifications from the paper.
106 * The sub-pixel convolution has been replaced with a deconvolution layer. This
107 * operation is mathematically the same.
108 *
109 * Convolution replaced by deconvolution:
110 * https://arxiv.org/abs/1609.07009
111 * "Is the deconvolution layer the same as a convolutional layer?"
112 * Wenzhe Shi, Jose Caballero, Lucas Theis, Ferenc Huszar, Andrew Aitken, Christian Ledig, Zehan Wang
113 *
114 * Original model is:
115 * https://arxiv.org/abs/1707.02921
116 * "Enhanced Deep Residual Networks for Single Image Super-Resolution"
117 * Bee Lim, Sanghyun Son, Heewon Kim, Seungjun Nah, Kyoung Mu Lee
118 *
119 * @note To list all the possible arguments execute the binary appended with the --help option
120 *
121 * @param[in] argc Number of arguments
122 * @param[in] argv Arguments
123 *
124 * @return Return code
125 */
Sang-Hoon Park68001172020-03-06 16:32:01 +0000126int main(int argc, char **argv)
127{
128 return run_example<GraphEdsrExample>(argc, argv);
129}