Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / thirdparty / clDNN / src / normalize.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 #include "normalize_inst.h"
18 #include "primitive_type_base.h"
19 #include "error_handler.h"
20 #include "json_object.h"
21
22 namespace cldnn
23 {
24 primitive_type_id normalize_type_id()
25 {
26     static primitive_type_base<normalize> instance;
27     return &instance;
28 }
29
30 layout normalize_inst::calc_output_layout(normalize_node const& node)
31 {
32     assert((bool)node.get_primitive()->output_data_type == false
33            && "Output data type forcing is not supported for normalize_node!");
34     return node.input().get_non_padded_output_layout();
35 }
36
37 std::string normalize_inst::to_string(normalize_node const& node)
38 {
39     auto node_info    = node.desc_to_json();
40     auto desc         = node.get_primitive();
41     auto epsilon      = desc->epsilon;
42     auto norm_region  = desc->across_spatial ? "across spatial" : "within spatial";
43     auto& input       = node.input();
44     auto& scale_input = node.scale();
45     
46     std::stringstream primitive_description;
47
48     json_composite normalize_info;
49     normalize_info.add("input id", input.id());
50     normalize_info.add("scale input id", scale_input.id());
51     normalize_info.add("epsilon", epsilon);
52     normalize_info.add("normalization region", norm_region);
53
54     node_info->add("noramlize info", normalize_info);
55     node_info->dump(primitive_description);
56
57     return primitive_description.str();
58 }
59
60 normalize_inst::typed_primitive_inst(network_impl& network, normalize_node const& node)
61     :parent(network, node)
62 {
63     /// Scale x dimension should be 1 (if all channels have the same scale) or equal to input feature size (one scale per channel).
64     auto scale_layout = node.scale().get_output_layout();
65     auto scale_size = scale_layout.size;
66     auto scale_feature_size = scale_size.spatial[0];
67     auto input_layout = node.input().get_output_layout();
68     auto input_feature_size = input_layout.size.feature[0];
69
70     if (scale_feature_size != 1)
71     {
72         CLDNN_ERROR_NOT_EQUAL(node.id(), "Scale feature size", scale_feature_size, "input feature size", input_feature_size, "");
73     }
74
75     // All other dimensions should be 1
76     CLDNN_ERROR_NOT_EQUAL(node.id(), "Scale input size elements count", (int32_t)scale_size.count(), "scale feature size", scale_feature_size, "Dimensions mismatch of scale input in Normalize layer!");
77
78 }
79 }