2 // Copyright (c) 2017-2018 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 "roi_pooling_inst.h"
18 #include "primitive_type_base.h"
19 #include "error_handler.h"
20 #include "json_object.h"
24 primitive_type_id roi_pooling_type_id()
26 static primitive_type_base<roi_pooling> instance;
30 layout roi_pooling_inst::calc_output_layout(roi_pooling_node const& node)
32 auto desc = node.get_primitive();
33 layout data_layout = node.input().get_output_layout();
34 int fm = data_layout.size.feature[0];
36 layout rois_layout = node.rois().get_output_layout();
37 int num_rois = rois_layout.size.batch[0];
39 int gss = desc->group_sz * desc->group_sz;
42 CLDNN_ERROR_LESS_THAN(node.id(), "Group size", desc->group_sz, "value", 0, "");
43 if (gss && fm % gss != 0)
45 CLDNN_ERROR_MESSAGE(node.id(), "group_sz must be either 0 (For RoIPooling) or satisfy fm % (group_sz^2) == 0");
53 return layout(data_layout.data_type, format::bfyx, { num_rois, fm, desc->pooled_width, desc->pooled_height });
56 std::string roi_pooling_inst::to_string(roi_pooling_node const& node)
58 auto desc = node.get_primitive();
59 auto mode = desc->mode == pooling_mode::max ? "max" : desc->mode == pooling_mode::bilinear ? "bilinear" : "average";
60 auto node_info = node.desc_to_json();
62 std::stringstream primitive_description;
64 json_composite roi_info;
65 roi_info.add("mode", mode);
66 roi_info.add("pooled_w", desc->pooled_width);
67 roi_info.add("pooled_h", desc->pooled_height);
68 roi_info.add("spatial_scale", desc->spatial_scale);
69 roi_info.add("group_sz", desc->group_sz);
71 node_info->add("roi info", roi_info);
72 node_info->dump(primitive_description);
74 return primitive_description.str();