Publishing R3
[platform/upstream/dldt.git] / inference-engine / thirdparty / clDNN / src / include / proposal_inst.h
1 /*
2 // Copyright (c) 2017 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 ///////////////////////////////////////////////////////////////////////////////////////////////////
18 #pragma once
19 #include "api/CPP/proposal.hpp"
20 #include "primitive_inst.h"
21
22 namespace cldnn
23 {
24
25 template <>
26 struct typed_program_node<proposal> : public typed_program_node_base<proposal>
27 {
28     using parent = typed_program_node_base<proposal>;
29     using parent::parent;
30
31     decltype(auto) cls_score() const { return get_dependency(0); }
32     decltype(auto) bbox_pred() const { return get_dependency(1); }
33     decltype(auto) image_info() const { return get_dependency(2); }
34 };
35
36 using proposal_node = typed_program_node<proposal>;
37
38 template <>
39 class typed_primitive_inst<proposal> : public typed_primitive_inst_base<proposal>
40 {
41     using parent = typed_primitive_inst_base<proposal>;
42
43 public:
44     struct anchor
45     {
46         float start_x;
47         float start_y;
48         float end_x;
49         float end_y;
50
51         anchor()
52         {
53             start_x = start_y = end_x = end_y = 0.0f;
54         }
55
56         anchor(float s_x, float s_y, float e_x, float e_y)
57         {
58             start_x = s_x;
59             start_y = s_y;
60             end_x = e_x;
61             end_y = e_y;
62         }
63     };
64
65     // indices of the memory objects used by the layer
66     enum input_index {
67         cls_scores_index,
68         bbox_pred_index,
69         image_info_index
70     };
71
72     //TODO(ruv): missign validation?? for image_info dimensions? also faster r-cnn expected it to be dim3 while the new networks expect dim 6!!! ([5] being unused)
73     //TODO(ruv): we should be able to set dims[3]=dim[4]=1 if not provided
74
75     // indices of the image info parameters inside the image_info memory object (the object
76     // is an integer array of these parameters)
77     enum image_info_size_index {
78         image_info_height_index,
79         image_info_width_index,
80         image_info_depth_index,
81         image_info_scale_min_bbox_y,
82         image_info_scale_min_bbox_x,
83         image_info_scale_depth_index,
84     };
85
86     static layout calc_output_layout(proposal_node const& node);
87     static std::string to_string(proposal_node const& node);
88
89 public:    
90     typed_primitive_inst(network_impl& network, proposal_node const& desc);
91
92     const std::vector<anchor>& get_anchors() const { return _anchors; }
93
94 private:
95     std::vector<anchor> _anchors;
96 };
97
98 using proposal_inst = typed_primitive_inst<proposal>;
99
100 }