Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / thirdparty / clDNN / src / roi_pooling.cpp
1 /*
2 // Copyright (c) 2017-2018 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 "roi_pooling_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 roi_pooling_type_id()
25 {
26     static primitive_type_base<roi_pooling> instance;
27     return &instance;
28 }
29
30 layout roi_pooling_inst::calc_output_layout(roi_pooling_node const& node)
31 {
32     assert((bool)node.get_primitive()->output_data_type == false
33            && "Output data type forcing is not supported for roi_pooling_node!");
34     auto desc = node.get_primitive();
35     layout data_layout = node.input().get_output_layout();
36     layout rois_layout = node.rois().get_output_layout();
37     int num_rois = rois_layout.size.batch[0];
38     int out_fm = desc->position_sensitive ? desc->output_dim : data_layout.size.feature[0];
39
40     return layout(data_layout.data_type, format::bfyx, { num_rois, out_fm, desc->pooled_width, desc->pooled_height });
41 }
42
43 std::string roi_pooling_inst::to_string(roi_pooling_node const& node)
44 {
45     auto desc      = node.get_primitive();
46     auto mode      = desc->mode == pooling_mode::max ? "max" : desc->mode == pooling_mode::bilinear ? "bilinear" : "average";
47     auto is_ps     = desc->position_sensitive ? "true" : "false";
48     auto node_info = node.desc_to_json();
49
50     std::stringstream primitive_description;
51
52     json_composite roi_info;
53     roi_info.add("mode", mode);
54     roi_info.add("position sensitive", is_ps);
55     roi_info.add("pooled_w", desc->pooled_width);
56     roi_info.add("pooled_h", desc->pooled_height);
57     roi_info.add("spatial_scale", desc->spatial_scale);
58     roi_info.add("output_dim", desc->output_dim);
59     roi_info.add("spatial_bins_x", desc->spatial_bins_x);
60     roi_info.add("spatial_bins_y", desc->spatial_bins_y);
61
62     node_info->add("roi info", roi_info);
63     node_info->dump(primitive_description);
64
65     return primitive_description.str();
66 }
67
68 }