Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / thirdparty / clDNN / src / upsampling.cpp
1 /*
2 // Copyright (c) 2016 Intel Corporation
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //      http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 */
16
17 ///////////////////////////////////////////////////////////////////////////////////////////////////
18 #include "upsampling_inst.h"
19 #include "primitive_type_base.h"
20 #include "error_handler.h"
21
22 namespace cldnn
23 {
24 primitive_type_id upsampling_type_id()
25 {
26     static primitive_type_base<upsampling> instance;
27     return &instance;
28 }
29
30 layout upsampling_inst::calc_output_layout(upsampling_node const& node)
31 {
32     assert((bool)node.get_primitive()->output_data_type == false
33            && "Output data type forcing is not supported for upsampling_node!");
34     auto desc = node.get_primitive();
35     auto input_layout = node.input().get_output_layout();
36     auto scale = desc->scale;
37
38     auto result_sizes = tensor(input_layout.size.batch[0], input_layout.size.feature[0], static_cast<size_t>(input_layout.size.spatial[0] * scale),
39         static_cast<size_t>(input_layout.size.spatial[1] * scale));
40     auto result = layout({ input_layout.data_type, input_layout.format, result_sizes });
41
42     return result;
43 }
44
45 std::string upsampling_inst::to_string(upsampling_node const& node)
46 {
47     std::stringstream           primitive_description;
48     auto desc                   = node.get_primitive();
49     auto& input_1               = node.input();
50     auto activation             = desc->with_activation ? " true" : "false";
51     std::string                 str_type;
52     switch(desc->sample_type)
53     {
54     case upsampling_sample_type::nearest:
55             str_type = "nearest";
56             break;
57     case upsampling_sample_type::bilinear:
58             str_type = "bilinear";
59             break;
60     default:
61             str_type = "not supported sample type";
62             break;
63     }
64
65     primitive_description << "id: " << desc->id << ", type: upsampling" << 
66         "\n\tinput_1: " << input_1.id() << ", count: " << input_1.get_output_layout().count() << ",  size: " << input_1.get_output_layout().size <<
67         "\n\tscale: " << desc->scale <<
68         "\n\tnum_filter: " << desc->num_filter <<
69         "\n\tsample_type: " << str_type <<
70         "\n\twith activation: " << activation << ", slope: " << desc->activation_negative_slope << 
71         "\n\toutput padding lower size: " << desc->output_padding.lower_size() <<
72         "\n\toutput padding upper size: " << desc->output_padding.upper_size() <<
73         "\n\toutput: count: " << node.get_output_layout().count() << ",  size: " << node.get_output_layout().size << '\n';
74
75     return primitive_description.str();
76 }
77
78 upsampling_inst::typed_primitive_inst(network_impl& network, upsampling_node const& node)
79     :parent(network, node)
80 {
81     if(argument.sample_type == upsampling_sample_type::bilinear)
82         CLDNN_ERROR_MESSAGE(node.id(), "Upsampling primitive instance with bilinear filtering should be replaced by deconvolution!");
83 }
84 }