Publishing R5 content (#72)
[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     auto desc = node.get_primitive();
33     layout data_layout = node.input().get_output_layout();
34     int fm = data_layout.size.feature[0];
35
36     layout rois_layout = node.rois().get_output_layout();
37     int num_rois = rois_layout.size.batch[0];
38
39     int gss = desc->group_sz * desc->group_sz;
40
41
42     CLDNN_ERROR_LESS_THAN(node.id(), "Group size", desc->group_sz, "value", 0, "");
43     if (gss && fm % gss != 0)
44     {
45         CLDNN_ERROR_MESSAGE(node.id(), "group_sz must be either 0 (For RoIPooling) or satisfy fm % (group_sz^2) == 0");
46     }
47     
48     if (gss)
49     {
50         fm /= gss;
51     }
52
53     return layout(data_layout.data_type, format::bfyx, { num_rois, fm, desc->pooled_width, desc->pooled_height });
54 }
55
56 std::string roi_pooling_inst::to_string(roi_pooling_node const& node)
57 {
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();
61
62     std::stringstream primitive_description;
63
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);
70
71     node_info->add("roi info", roi_info);
72     node_info->dump(primitive_description);
73
74     return primitive_description.str();
75 }
76
77 }