2 // Copyright (c) 2016 Intel Corporation
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
8 // http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include "normalize_inst.h"
18 #include "primitive_type_base.h"
19 #include "error_handler.h"
20 #include "json_object.h"
24 primitive_type_id normalize_type_id()
26 static primitive_type_base<normalize> instance;
30 layout normalize_inst::calc_output_layout(normalize_node const& node)
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();
37 std::string normalize_inst::to_string(normalize_node const& node)
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();
46 std::stringstream primitive_description;
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);
54 node_info->add("noramlize info", normalize_info);
55 node_info->dump(primitive_description);
57 return primitive_description.str();
60 normalize_inst::typed_primitive_inst(network_impl& network, normalize_node const& node)
61 :parent(network, node)
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];
70 if (scale_feature_size != 1)
72 CLDNN_ERROR_NOT_EQUAL(node.id(), "Scale feature size", scale_feature_size, "input feature size", input_feature_size, "");
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!");