Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / thirdparty / clDNN / src / region_yolo.cpp
1 /*
2 // Copyright (c) 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 "region_yolo_inst.h"
18 #include "primitive_type_base.h"
19 #include "json_object.h"
20
21 namespace cldnn
22 {
23     primitive_type_id region_yolo_type_id()
24     {
25         static primitive_type_base<region_yolo> instance;
26         return &instance;
27     }
28
29     layout region_yolo_inst::calc_output_layout(region_yolo_node const& node)
30     {
31         assert((bool)node.get_primitive()->output_data_type == false
32                && "Output data type forcing is not supported for "
33                   "region_yolo_node!");
34         auto input_layout = node.input().get_output_layout();
35         auto desc = node.get_primitive();
36
37         if (desc->do_softmax)
38         {
39             return cldnn::layout(input_layout.data_type, input_layout.format,
40                                  tensor(input_layout.size.batch[0],
41                                         input_layout.size.feature[0] * input_layout.size.spatial[0] * input_layout.size.spatial[1],
42                                         1, 1));
43         }
44         else
45         {
46             tensor::value_type features = (desc->classes + desc->coords + 1)*desc->mask_size;
47             return cldnn::layout(input_layout.data_type, input_layout.format,
48                                  tensor(input_layout.size.batch[0],
49                                         features,
50                                         input_layout.size.spatial[0], input_layout.size.spatial[1]));
51
52         }
53     }
54
55     std::string region_yolo_inst::to_string(region_yolo_node const& node)
56     {
57         auto desc = node.get_primitive();
58         auto node_info = node.desc_to_json();
59         auto coords = desc->coords;
60         auto classes = desc->classes;
61         auto num = desc->num;
62         auto do_softmax = desc->do_softmax;
63         auto mask_size = desc->mask_size;
64
65         std::stringstream primitive_description;
66
67         json_composite region_yolo_info;
68         region_yolo_info.add("coords", coords);
69         region_yolo_info.add("classes", classes);
70         region_yolo_info.add("num", num);
71         region_yolo_info.add("do_softmax", do_softmax);
72         region_yolo_info.add("mask_size", mask_size);
73
74
75         node_info->add("region yolo info", region_yolo_info);
76         node_info->dump(primitive_description);
77
78         return primitive_description.str();
79     }
80
81     region_yolo_inst::typed_primitive_inst(network_impl& network, region_yolo_node const& node)
82         : parent(network, node)
83     {
84     }
85 }