ie_layers.h
Go to the documentation of this file.
1 // Copyright (C) 2018-2019 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4 
5 /**
6  * @brief a header file for internal Layers structure to describe layers information
7  * @file ie_layers.h
8  */
9 #pragma once
10 
11 #include <memory>
12 #include <string>
13 #include <vector>
14 #include <algorithm>
15 #include <map>
16 #include <iterator>
17 #include <limits>
18 #include <cctype>
19 #include "ie_common.h"
20 #include "ie_data.h"
21 #include "ie_blob.h"
22 #include "ie_device.hpp"
23 #include "ie_layers_property.hpp"
24 
25 namespace InferenceEngine {
26 /**
27  * @brief This is an internal common Layer parameter parsing arguments
28  */
29 struct LayerParams {
30  /// @brief Layer name
31  std::string name;
32  /// @brief Layer type
33  std::string type;
34  /// @brief Layer precision
36 };
37 
38 /**
39  * @brief This is a base abstraction Layer - all DNN Layers inherit from this class
40  */
41 class CNNLayer {
42 public:
43  /**
44  * @brief A shared pointer to CNNLayer
45  */
46  using Ptr = std::shared_ptr<CNNLayer>;
47 
48  /**
49  * @brief Layer name
50  */
51  std::string name;
52  /**
53  * @brief Layer type
54  */
55  std::string type;
56  /**
57  * @brief Layer base operating precision
58  */
60  /**
61  * @brief A vector of pointers to the output data elements of this layer in the di-graph (order matters)
62  */
63  std::vector<DataPtr> outData;
64  /**
65  * @brief A vector of weak pointers to the input data elements of this layer in the di-graph (order matters)
66  */
67  std::vector<DataWeakPtr> insData;
68  /**
69  * @brief If suggested to fuse - a pointer to the layer which needs to be fused with this layer
70  */
72  /**
73  * @brief Convenience user values to store in this object as extra data
74  */
76  /**
77  * @brief Layer affinity set by user.
78  */
79  std::string affinity;
80 
81  /**
82  * @brief A constructor. Creates a new CNNLayer instance and initializes layer parameters with the given values.
83  * @param prms Basic common parsing parameters
84  */
85  explicit CNNLayer(const LayerParams &prms) : name(prms.name), type(prms.type),
86  precision(prms.precision), userValue({0}) {
87  }
88 
89  /**
90  * @brief A virtual destructor
91  */
92  virtual ~CNNLayer() = default;
93 
94  /**
95  * @brief Sets a layer to be fused with
96  * @param layer Reference to the layer to be fused with
97  */
98  void fuse(Ptr &layer) {
99  _fusedWith = layer;
100  }
101 
102  /**
103  * @brief Returns the first element of the input data for this layer
104  * @return A smart pointer to the input data element
105  */
106  virtual const DataPtr input() const {
107  if (insData.empty()) {
108  THROW_IE_EXCEPTION << "Internal error: input data is empty";
109  }
110  auto lockedFirstInsData = insData[0].lock();
111  if (!lockedFirstInsData) {
112  THROW_IE_EXCEPTION << "Internal error: unable to lock weak_ptr\n";
113  }
114  return lockedFirstInsData;
115  }
116 
117  /**
118  * @brief Checks if the input data and layer data are legitimate
119  */
120  INFERENCE_ENGINE_API_CPP(void) validateLayer();
121 
122  /**
123  * @brief Parse string with float in accordance with IE rules
124  * @param str input string with float value
125  * @return float value if parsing was successful
126  * @throws InferenceEngineException in case of parsing error
127  */
128  static float ie_parse_float(const std::string &str) {
129  if (str == "-inf") {
130  return -std::numeric_limits<float>::infinity();
131  } else if (str == "inf") {
132  return std::numeric_limits<float>::infinity();
133  } else {
134  float res;
135  std::stringstream val_stream(str);
136  val_stream.imbue(std::locale("C"));
137  val_stream >> res;
138  if (!val_stream.eof()) THROW_IE_EXCEPTION;
139  return res;
140  }
141  }
142  /**
143  * @brief serialize float with c_locale formating
144  * used for default values serializing
145  */
146  static std::string ie_serialize_float(float value) {
147  std::stringstream val_stream;
148  val_stream.imbue(std::locale("C"));
149  val_stream << value;
150  return val_stream.str();
151  }
152 
153  /**
154  * @brief Gets float value for the given parameter
155  * @param param name of the parameter to find
156  * @param def default value of the parameter if not found
157  * @return float value
158  */
159  float GetParamAsFloat(const char* param, float def) const {
160  std::string val = GetParamAsString(param, ie_serialize_float(def).c_str());
161  try {
162  return ie_parse_float(val);
163  } catch (...) {
164  THROW_IE_EXCEPTION << "Cannot parse parameter " << param << " from IR for layer " << name
165  << ". Value " << val << " cannot be casted to float.";
166  }
167  }
168 
169  /**
170  * @brief Returns a float value for the given layer parameter
171  * @param param Name of the layer parameter
172  * @return A float value for the specified parameter
173  */
174  float GetParamAsFloat(const char *param) const {
175  std::string val = GetParamAsString(param);
176  try {
177  return ie_parse_float(val);
178  } catch (...) {
179  THROW_IE_EXCEPTION << "Cannot parse parameter " << param << " from IR for layer " << name
180  << ". Value " << val << " cannot be casted to float.";
181  }
182  }
183 
184  /**
185  * @brief Returns a vector of float values for the given parameter or returns the default value
186  * @param param Name of the layer parameter
187  * @param def Default value of the parameter if not found
188  * @return vector of float values
189  */
190  std::vector<float> GetParamAsFloats(const char *param, std::vector<float> def) const {
191  std::string vals = GetParamAsString(param, "");
192  std::vector<float> result;
193  std::istringstream stream(vals);
194  std::string str;
195  if (vals.empty())
196  return def;
197  while (getline(stream, str, ',')) {
198  try {
199  float val = ie_parse_float(str);
200  result.push_back(val);
201  } catch (...) {
202  THROW_IE_EXCEPTION << "Cannot parse parameter " << param << " " << str << " from IR for layer " << name
203  << ". Value " << vals << " cannot be casted to floats.";
204  }
205  }
206  return result;
207  }
208 
209  /**
210  * @brief Returns a vector of float values for the given parameter
211  * @param param Name of the layer parameter
212  * @return vector of float values
213  */
214  std::vector<float> GetParamAsFloats(const char *param) const {
215  std::string vals = GetParamAsString(param);
216  std::vector<float> result;
217  std::istringstream stream(vals);
218  std::string str;
219  while (getline(stream, str, ',')) {
220  try {
221  float val = ie_parse_float(str);
222  result.push_back(val);
223  } catch (...) {
224  THROW_IE_EXCEPTION << "Cannot parse parameter " << param << " " << str << " from IR for layer " << name
225  << ". Value " << vals << " cannot be casted to floats.";
226  }
227  }
228  return result;
229  }
230 
231  /**
232  * @brief Returns an integer value for the given parameter or returns the default value
233  * @param param Name of the layer parameter
234  * @param def Default value of the parameter if not found
235  * @return An int value for the specified parameter
236  */
237  int GetParamAsInt(const char *param, int def) const {
238  std::string val = GetParamAsString(param, std::to_string(def).c_str());
239  try {
240  return std::stoi(val);
241  } catch (...) {
242  THROW_IE_EXCEPTION << "Cannot parse parameter " << param << " from IR for layer " << name
243  << ". Value " << val << " cannot be casted to int.";
244  }
245  }
246 
247  /**
248  * @brief Returns an integer value for the given parameter
249  * @param param Name of the layer parameter
250  * @return An int value for the specified parameter
251  */
252  int GetParamAsInt(const char *param) const {
253  std::string val = GetParamAsString(param);
254  try {
255  return std::stoi(val);
256  } catch (...) {
257  THROW_IE_EXCEPTION << "Cannot parse parameter " << param << " from IR for layer " << name
258  << ". Value " << val << " cannot be casted to int.";
259  }
260  }
261 
262 
263  /**
264  * @brief Returns a vector of int values for the given parameter or returns the default value
265  * @param param Name of the layer parameter
266  * @param def Default value of the parameter if not found
267  * @return vector of int values
268  */
269  std::vector<int> GetParamAsInts(const char *param, std::vector<int> def) const {
270  std::string vals = GetParamAsString(param, "");
271  std::vector<int> result;
272  std::istringstream stream(vals);
273  std::string str;
274  if (vals.empty())
275  return def;
276  while (getline(stream, str, ',')) {
277  try {
278  result.push_back(std::stoi(str));
279  } catch (...) {
280  THROW_IE_EXCEPTION << "Cannot parse parameter " << param << " " << str << " from IR for layer " << name
281  << ". Value " << vals << " cannot be casted to int.";
282  }
283  }
284  return result;
285  }
286 
287  /**
288  * @brief Returns a vector of int values for the given parameter
289  * @param param Name of the layer parameter
290  * @return vector of int values
291  */
292  std::vector<int> GetParamAsInts(const char *param) const {
293  std::string vals = GetParamAsString(param);
294  std::vector<int> result;
295  std::istringstream stream(vals);
296  std::string str;
297  while (getline(stream, str, ',')) {
298  try {
299  result.push_back(std::stoi(str));
300  } catch (...) {
301  THROW_IE_EXCEPTION << "Cannot parse parameter " << param << " " << str << " from IR for layer " << name
302  << ". Value " << vals << " cannot be casted to int.";
303  }
304  }
305  return result;
306  }
307  /**
308  * @brief Returns an unsigned integer value for the given parameter or returns the default value
309  * @param param Name of the layer parameter
310  * @param def Default value of the parameter if not found
311  * @return An unsigned integer value for the specified parameter
312  */
313  unsigned int GetParamAsUInt(const char *param, unsigned int def) const {
314  std::string val = GetParamAsString(param, std::to_string(def).c_str());
315  std::string message = "Cannot parse parameter " + std::string(param) + " from IR for layer " + name
316  + ". Value " + val + " cannot be casted to int.";
317  try {
318  int value = std::stoi(val);
319  if (value < 0) {
320  THROW_IE_EXCEPTION << message;
321  }
322  return static_cast<unsigned int>(value);
323  } catch (...) {
324  THROW_IE_EXCEPTION << message;
325  }
326  }
327 
328  /**
329  * @brief Returns an unsigned integer value for the given parameter
330  * @param param Name of the layer parameter
331  * @return An unsigned integer value for the specified parameter
332  */
333  unsigned int GetParamAsUInt(const char *param) const {
334  std::string val = GetParamAsString(param);
335  std::string message = "Cannot parse parameter " + std::string(param) + " from IR for layer " + name
336  + ". Value " + val + " cannot be casted to unsigned int.";
337  try {
338  int value = std::stoi(val);
339  if (value < 0) {
340  THROW_IE_EXCEPTION << message;
341  }
342  return static_cast<unsigned int>(value);
343  } catch (...) {
344  THROW_IE_EXCEPTION << message;
345  }
346  }
347 
348 
349  /**
350  * @brief Returns a vector of unsigned int values for the given parameter or returns the default value
351  * @param param Name of the layer parameter
352  * @param def Default value of the parameter if not found
353  * @return vector of unsigned int values
354  */
355  std::vector<unsigned int> GetParamAsUInts(const char *param, std::vector<unsigned int> def) const {
356  std::string vals = GetParamAsString(param, "");
357  std::vector<unsigned int> result;
358  std::istringstream stream(vals);
359  std::string str;
360  std::string message = "Cannot parse parameter " + std::string(param) + " " + str + " from IR for layer " + name
361  + ". Value " + vals + " cannot be casted to unsigned int.";
362  if (vals.empty())
363  return def;
364  while (getline(stream, str, ',')) {
365  try {
366  int value = std::stoi(str);
367  if (value < 0) {
368  THROW_IE_EXCEPTION << message;
369  }
370  result.push_back(static_cast<unsigned int>(value));
371  } catch (...) {
372  THROW_IE_EXCEPTION << message;
373  }
374  }
375  return result;
376  }
377 
378  /**
379  * @brief Returns a vector of unsigned int values for the given parameter
380  * @param param Name of the layer parameter
381  * @return vector of unsigned int values
382  */
383  std::vector<unsigned int> GetParamAsUInts(const char *param) const {
384  std::string vals = GetParamAsString(param);
385  std::vector<unsigned int> result;
386  std::istringstream stream(vals);
387  std::string str;
388  std::string message = "Cannot parse parameter " + std::string(param) + " " + str + " from IR for layer " + name
389  + ". Value " + vals + " cannot be casted to int.";
390  while (getline(stream, str, ',')) {
391  try {
392  int value = std::stoi(str);
393  if (value < 0) {
394  THROW_IE_EXCEPTION << message;
395  }
396  result.push_back(static_cast<unsigned int>(value));
397  } catch (...) {
398  THROW_IE_EXCEPTION << message;
399  }
400  }
401  return result;
402  }
403  /**
404  * @brief Returns a boolean value for the given parameter.
405  * The valid values are (true, false, 1, 0).
406  * @param param Name of the layer parameter
407  * @param def Default value of the parameter if not found
408  * @return A bool value for the specified parameter
409  */
410  bool GetParamAsBool(const char *param, bool def) const {
411  std::string val = GetParamAsString(param, std::to_string(def).c_str());
412  std::string loweredCaseValue;
413  std::transform(val.begin(), val.end(), std::back_inserter(loweredCaseValue), [](char value) {
414  return std::tolower(value);
415  });
416 
417  bool result = false;
418 
419  if (!(std::istringstream(loweredCaseValue) >> std::boolalpha >> result)) {
420  // attempting parse using non alpha bool
421  return (GetParamAsInt(param, def) != 0);
422  }
423 
424  return result;
425  }
426  /**
427  * @brief Returns a boolean value for the given parameter
428  * @param param Name of the layer parameter
429  * @return A bool value for the specified parameter
430  */
431  bool GetParamAsBool(const char *param) const {
432  std::string val = GetParamAsString(param);
433  std::string loweredCaseValue;
434  std::transform(val.begin(), val.end(), std::back_inserter(loweredCaseValue), [](char value) {
435  return std::tolower(value);
436  });
437 
438  bool result = false;
439 
440  if (!(std::istringstream(loweredCaseValue) >> std::boolalpha >> result)) {
441  // attempting parse using non alpha bool
442  return (GetParamAsInt(param) != 0);
443  }
444 
445  return result;
446  }
447 
448  /**
449  * @deprecated Use GetParamAsBool function for that functionality
450  */
451  INFERENCE_ENGINE_DEPRECATED
452  bool GetParamsAsBool(const char *param, bool def) const {
453  return GetParamAsBool(param, def);
454  }
455 
456  /**
457  * @brief Returns a string value for the given parameter or returns the default one
458  * @param param Name of the layer parameter
459  * @param def Default value of the parameter if not found
460  * @return A string value
461  */
462  std::string GetParamAsString(const char *param, const char *def) const {
463  auto it = params.find(param);
464  if (it == params.end() || it->second.empty()) {
465  return def;
466  }
467  return (*it).second;
468  }
469 
470  /**
471  * @brief Checks the param presence in the layer
472  * @param param Name of the layer parameter
473  * @return a bool depending param presence
474  */
475  bool CheckParamPresence(const char *param) const {
476  auto it = params.find(param);
477  if (it == params.end()) {
478  return false;
479  }
480  return true;
481  }
482 
483  /**
484  * @brief Returns a string value for the given parameter.
485  * Throws exception if parameter was not found.
486  * @param param Name of the layer parameter
487  * @return A string value
488  */
489  std::string GetParamAsString(const char *param) const {
490  auto it = params.find(param);
491  if (it == params.end()) {
492  THROW_IE_EXCEPTION << "No such parameter name '" << param << "' for layer " << name;
493  }
494  return (*it).second;
495  }
496 
497  std::vector<std::string> GetParamAsStrings(const char *param, std::vector<std::string> def) const {
498  std::string vals = GetParamAsString(param, "");
499  std::vector<std::string> result;
500  std::istringstream stream(vals);
501  std::string str;
502  if (vals.empty())
503  return def;
504  while (getline(stream, str, ',')) {
505  try {
506  result.push_back(str);
507  } catch (...) {
508  THROW_IE_EXCEPTION << "Cannot parse parameter " << param << " from IR for layer " << name << ".";
509  }
510  }
511  return result;
512  }
513 
514  /**
515  * @brief Map of pairs: (parameter name, parameter value)
516  */
517  std::map<std::string, std::string> params;
518 
519  /**
520  * @brief Map of pairs: (name, weights/biases blob)
521  */
522  std::map<std::string, Blob::Ptr> blobs;
523 };
524 
525 /**
526  * @brief Alias for CNNLayer object
527  */
528 using GenericLayer = class CNNLayer;
529 
530 /**
531  * @brief This class represents a layer with Weights and/or Biases (e.g. Convolution/Fully Connected, etc.)
532  */
533 class WeightableLayer : public CNNLayer {
534 public:
535  /**
536  * @brief A default constructor. Constructs a WeightableLayer instance and initiates layer parameters with the given values
537  * @param prms Initial layer parameters
538  */
539  explicit WeightableLayer(const LayerParams &prms) : CNNLayer(prms) {}
540 
541  /**
542  * @brief A pointer to a weights blob
543  */
545  /**
546  * @brief A pointer to a biases blob
547  */
549 
550  /**
551  * @brief Constructs a WeightableLayer instance and initiates layer parameters with the given values
552  */
553  using CNNLayer::CNNLayer;
554 };
555 
556 /**
557  * @brief convinenent way to declare property with backward compatibility to 2D members
558  */
559 #define DEFINE_PROP(prop_name) \
560 PropertyVector<unsigned int> prop_name;\
561 unsigned int &prop_name##_x = prop_name.at(X_AXIS);\
562 unsigned int &prop_name##_y = prop_name.at(Y_AXIS);\
563 
564 /**
565  * @brief This class represents a standard 3D Convolution Layer
566  */
568 public:
569  /**
570  * @brief A convolution kernel array [X, Y, Z, ...]
571  */
572  DEFINE_PROP(_kernel);
573  /**
574  * @brief A convolution paddings begin array [X, Y, Z, ...]
575  */
576  DEFINE_PROP(_padding);
577  /**
578  * @brief A convolution paddings end array [X, Y, Z, ...]
579  */
581  /**
582  * @brief A convolution strides array [X, Y, Z, ...]
583  */
584  DEFINE_PROP(_stride);
585  /**
586  * @brief A convolution dilations array [X, Y, Z, ...]
587  */
588  DEFINE_PROP(_dilation);
589  /**
590  * @brief A number of output feature maps (size) generating the 3'rd output dimension
591  */
592  unsigned int _out_depth = 0u;
593  /**
594  * @brief Number of groups
595  */
596  unsigned int _group = 1u;
597  /**
598  * @brief Auto padding type
599  */
600  std::string _auto_pad;
601 
602  /**
603  * @brief Creates a new ConvolutionLayer instance.
604  */
606  _kernel(2, 0u), _padding(2, 0u), _stride(2, 1u), _dilation(2, 1u) {}
607  /**
608  * @brief assignment operator
609  */
610  ConvolutionLayer & operator = (const ConvolutionLayer & that) {
611  if (&that != this) {
612  WeightableLayer::operator=(that);
613  _kernel = that._kernel;
614  _padding = that._padding;
615  _pads_end = that._pads_end;
616  _stride = that._stride;
617  _dilation = that._dilation;
618  _out_depth = that._out_depth;
619  _group = that._group;
620  }
621  return *this;
622  }
623  /**
624  * @brief copy constructor
625  */
627  operator = (that);
628  }
629  /**
630  * @brief move constructor
631  */
632  ConvolutionLayer(ConvolutionLayer &&) = default;
633 };
634 
635 /**
636  * @brief This class represents a standard deconvolution layer
637  */
639  public:
641  using ConvolutionLayer::operator=;
642 };
643 
644 /**
645  * @brief This class represents a standard deformable convolution layer
646  */
648 public:
650  using ConvolutionLayer::operator=;
651 
652  /**
653  * @brief Number of deformable groups
654  */
655  unsigned int _deformable_group = 1u;
656 };
657 
658 /**
659  * @brief This class represents a standard pooling layer
660  */
661 class PoolingLayer : public CNNLayer {
662 public:
663  /**
664  * @brief Pooling kernel array [X, Y, Z, ...]
665  */
666  DEFINE_PROP(_kernel);
667  /**
668  * @brief Pooling paddings begin array [X, Y, Z, ...]
669  */
670  DEFINE_PROP(_padding);
671  /**
672  * @brief Pooling paddings end array [X, Y, Z, ...]
673  */
675  /**
676  * @brief Pooling strides array [X, Y, Z, ...]
677  */
678  DEFINE_PROP(_stride);
679 
680  /**
681  * @enum PoolType
682  * @brief Defines available pooling types
683  */
684  enum PoolType {
685  MAX = 1,
686  AVG = 2,
687  STOCH = 3,
688  ROI = 4,
689  SPACIAL_PYRAMID = 5
690  };
691 
692  /**
693  * @brief A pooling type
694  */
695  PoolType _type = MAX;
696 
697  /**
698  * @brief A flag that indicates if padding is excluded or not
699  */
700  bool _exclude_pad = false;
701  /**
702  * @brief Auto padding type
703  */
704  std::string _auto_pad;
705 
706  /**
707  * @brief Creates a new PoolingLayer instance.
708  */
709  explicit PoolingLayer(const LayerParams &p) : CNNLayer(p),
710  _kernel(2, 0u), _padding(2, 0u), _stride(2, 0u) {}
711 
712  /**
713  * @brief assignment operator
714  */
715  PoolingLayer & operator = (const PoolingLayer & that) {
716  if (&that != this) {
717  CNNLayer::operator=(that);
718  _kernel = that._kernel;
719  _padding = that._padding;
720  _pads_end = that._pads_end;
721  _stride = that._stride;
722  _type = that._type;
723  _exclude_pad = that._exclude_pad;
724  }
725  return *this;
726  }
727  /**
728  * @brief copy constructor
729  */
730  PoolingLayer(const PoolingLayer & that) : CNNLayer(that) {
731  operator=(that);
732  }
733 
734  /**
735  * @brief move constructor
736  */
737  PoolingLayer(PoolingLayer &&) = default;
738 };
739 
740 /**
741  * @brief This class represents a standard binary convolution layer
742  */
744 public:
745  /**
746  * @enum eBinaryConvolutionMode
747  * @brief Defines possible modes of binary convolution operation
748  */
750  xnor_popcount = 0
751  };
752 
753  /**
754  * @brief Mode of binary convolution operation
755  */
756  eBinaryConvolutionMode _mode = xnor_popcount;
757 
758  /**
759  * @brief A number of input feature maps (size) generating the 3'rd input dimension
760  */
761  unsigned int _in_depth = 0u;
762 
763  /**
764  * @brief A pad value which is used to fill pad area
765  */
766  float _pad_value = 0.0f;
767 
768  /**
769  * @brief A convolution kernel array [X, Y, Z, ...]
770  */
771  DEFINE_PROP(_kernel);
772  /**
773  * @brief A convolution paddings begin array [X, Y, Z, ...]
774  */
775  DEFINE_PROP(_padding);
776  /**
777  * @brief A convolution paddings end array [X, Y, Z, ...]
778  */
780  /**
781  * @brief A convolution strides array [X, Y, Z, ...]
782  */
783  DEFINE_PROP(_stride);
784  /**
785  * @brief A convolution dilations array [X, Y, Z, ...]
786  */
787  DEFINE_PROP(_dilation);
788  /**
789  * @brief A number of output feature maps (size) generating the 3'rd output dimension
790  */
791  unsigned int _out_depth = 0u;
792  /**
793  * @brief Number of groups
794  */
795  unsigned int _group = 1u;
796  /**
797  * @brief Auto padding type
798  */
799  std::string _auto_pad;
800 
801  /**
802  * @brief Creates a new BinaryConvolutionLayer instance.
803  */
805  _kernel(2, 0u), _padding(2, 0u), _stride(2, 1u), _dilation(2, 1u) {}
806  /**
807  * @brief assignment operator
808  */
809  BinaryConvolutionLayer & operator = (const BinaryConvolutionLayer & that) {
810  if (&that != this) {
811  WeightableLayer::operator=(that);
812  _kernel = that._kernel;
813  _padding = that._padding;
814  _pads_end = that._pads_end;
815  _stride = that._stride;
816  _dilation = that._dilation;
817  _out_depth = that._out_depth;
818  _group = that._group;
819  _mode = that._mode;
820  _in_depth = that._in_depth;
821  _pad_value = that._pad_value;
822  }
823  return *this;
824  }
825  /**
826  * @brief copy constructor
827  */
829  operator = (that);
830  }
831  /**
832  * @brief move constructor
833  */
835 };
836 
837 #undef DEFINE_PROP
838 
839 /**
840  * @brief This class represents a fully connected layer
841  */
843 public:
844  /**
845  * @brief A size of output
846  */
847  unsigned int _out_num = 0;
848 
849  /**
850  * @brief Creates a new FullyConnectedLayer instance and initializes layer parameters with the given values.
851  */
853 };
854 
855 /**
856  * @brief This class represents concatenation layer
857  * Takes as input several data elements and merges them to one using the supplied axis
858  */
859 class ConcatLayer : public CNNLayer {
860 public:
861  /**
862  * @brief An axis on which concatenation operation is performed
863  */
864  unsigned int _axis = 1;
865 
866  /**
867  * @brief Creates a new ConcatLayer instance and initializes layer parameters with the given values.
868  * If batch is used, then batch needs to be specified as an input dimension also
869  * In current implementation 1 means channels, 0 - batch
870  */
871  using CNNLayer::CNNLayer;
872 };
873 
874 /**
875  * @brief This class represents a layer that evenly splits the input into the supplied outputs
876  */
877 class SplitLayer : public CNNLayer {
878 public:
879  /**
880  * @brief An axis on which split operation is performed
881  */
882  unsigned int _axis = 1;
883 
884  /**
885  * @brief Creates a new SplitLayer instance.
886  */
887  using CNNLayer::CNNLayer;
888 };
889 
890 /**
891  * @brief This class represents a Linear Response Normalization (LRN) Layer
892  */
893 class NormLayer : public CNNLayer {
894 public:
895  /**
896  * @brief Response size
897  */
898  unsigned int _size = 0;
899  /**
900  * @brief K
901  */
902  unsigned int _k = 1;
903  /**
904  * @brief Alpha coefficient
905  */
906  float _alpha = 0;
907  /**
908  * @brief Beta coefficient
909  */
910  float _beta = 0;
911  /**
912  * @brief Flag to specify normalization across feature maps (true) or across channels
913  */
914  bool _isAcrossMaps = false;
915 
916  /**
917  * @brief Creates a new NormLayer instance.
918  */
919  using CNNLayer::CNNLayer;
920 };
921 
922 /**
923  * @brief This class represents standard softmax Layer
924  */
925 class SoftMaxLayer : public CNNLayer {
926 public:
927  /**
928  * @brief Axis number for a softmax operation
929  */
930  int axis = 1;
931  /**
932  * @brief Creates a new SoftMaxLayer instance.
933  */
934  using CNNLayer::CNNLayer;
935 };
936 
937 /**
938  * @class GRNLayer
939  * @brief This class represents standard GRN Layer
940  */
941 class GRNLayer : public CNNLayer {
942 public:
943  /**
944  * @brief A default constructor. Creates a new GRNLayer instance and initializes layer parameters with the given values.
945  * @param prms Initial layer parameters
946  */
947  explicit GRNLayer(const LayerParams &prms) : CNNLayer(prms), bias(0.f) {}
948 
949  /**
950  * @brief Bias for squares sum
951  */
952  float bias = 0.f;
953 };
954 
955 /**
956  * @class MVNLayer
957  * @brief This class represents standard MVN Layer
958  */
959 class MVNLayer : public CNNLayer {
960 public:
961  /**
962  * @brief A default constructor. Creates a new MVNLayer instance and initializes layer parameters with the given values.
963  * @param prms Initial layer parameters
964  */
965  explicit MVNLayer(const LayerParams &prms) : CNNLayer(prms), across_channels(0), normalize(1) {}
966 
967  /**
968  * @brief Indicate that mean value is calculated across channels
969  */
971 
972  /**
973  * @brief Indicate that the result needs to be normalized
974  */
975  int normalize = 1;
976 };
977 
978 /**
979  * @brief This class represents a Rectified Linear activation layer
980  */
981 class ReLULayer : public CNNLayer {
982 public:
983  /**
984  * @brief Negative slope is used to takle negative inputs instead of setting them to 0
985  */
986  float negative_slope = 0.0f;
987 
988  /**
989  * @brief Creates a new ReLULayer instance.
990  */
991  using CNNLayer::CNNLayer;
992 };
993 
994 /**
995  * @brief This class represents a Clamp activation layer
996  * Clamps all tensor elements into the range [min_value, max_value]
997  */
998 class ClampLayer : public CNNLayer {
999 public:
1000  /**
1001  * @brief A minimum value
1002  */
1003  float min_value = 0.0f;
1004 
1005  /**
1006  * @brief A maximum value
1007  */
1008  float max_value = 1.0f;
1009  /**
1010  * @brief Creates a new ClampLayer instance.
1011  */
1012  using CNNLayer::CNNLayer;
1013 };
1014 
1015 
1016 /**
1017  * @brief This class represents a ReLU6 activation layer
1018  * Clamps all tensor elements into the range [0, 6.0]
1019  */
1020 class ReLU6Layer : public ClampLayer {
1021 public:
1022  explicit ReLU6Layer(const LayerParams &prms) : ClampLayer(prms) {
1023  max_value = 6.0f;
1024  }
1025 
1026  using ClampLayer::ClampLayer;
1027 };
1028 
1029 
1030 /**
1031  * @brief This class represents an element wise operation layer
1032  */
1033 class EltwiseLayer : public CNNLayer {
1034 public:
1035  /**
1036  * @enum eOperation
1037  * @brief Defines possible operations that can be used
1038  */
1039  enum eOperation {
1040  Sum = 0, Prod, Max, Sub, Min, Div, Squared_diff, Floor_mod, Pow,
1041  Equal, Not_equal, Less, Less_equal, Greater, Greater_equal,
1042  Logical_AND, Logical_OR, Logical_XOR, Logical_NOT, Mean
1043  };
1044 
1045  /**
1046  * @brief A type of the operation to use
1047  */
1048  eOperation _operation = Sum;
1049 
1050  /**
1051  * @brief A vector of coefficients to scale the operands
1052  */
1053  std::vector<float> coeff;
1054 
1055  /**
1056  * @brief Creates a new EltwiseLayer instance.
1057  */
1058  using CNNLayer::CNNLayer;
1059 };
1060 
1061 /**
1062  * @brief This class represents a standard crop layer
1063  */
1064 class CropLayer : public CNNLayer {
1065 public:
1066  /**
1067  * @brief A vector of dimensions for cropping
1068  */
1069  std::vector<int> axis;
1070  /**
1071  * @brief A vector of dimensions to be preserved
1072  */
1073  std::vector<int> dim;
1074  /**
1075  * @brief A vector of offsets for each dimension
1076  */
1077  std::vector<int> offset;
1078 
1079  /**
1080  * @brief Creates a new CropLayer instance.
1081  */
1082  using CNNLayer::CNNLayer;
1083 };
1084 
1085 /**
1086  * @brief This class represents a standard reshape layer
1087  */
1088 class ReshapeLayer : public CNNLayer {
1089 public:
1090  /**
1091  * @brief A vector of sizes of the shape
1092  */
1093  std::vector<int> shape;
1094  /**
1095  * @brief A number of axis to be taken for a reshape
1096  */
1097  int axis = 0;
1098  /**
1099  * @brief A number of first axises to be taken for a reshape
1100  */
1101  int num_axes = -1;
1102 
1103  /**
1104  * @brief Creates a new ReshapeLayer instance.
1105  */
1106  using CNNLayer::CNNLayer;
1107 };
1108 
1109 /**
1110  * @brief This class represents a standard Tile Layer
1111  */
1112 class TileLayer : public CNNLayer {
1113 public:
1114  /**
1115  * @brief An index of the axis to tile
1116  */
1117  int axis = -1;
1118  /**
1119  * @brief A number of copies to be made
1120  */
1121  int tiles = -1;
1122 
1123  /**
1124  * @brief Creates a new TileLayer instance.
1125  */
1126  using CNNLayer::CNNLayer;
1127 };
1128 
1129 
1130 /**
1131  * @brief This class represents a Layer which performs Scale and Shift
1132  */
1134 public:
1135  /**
1136  * @brief A flag that indicates if the same value is used for all the features. If false, the value is used pixel wise
1137  */
1138  unsigned int _broadcast = 0;
1139 
1140  /**
1141  * @brief Creates a new ScaleShiftLayer instance.
1142  */
1144 };
1145 
1146 /**
1147  * @brief This class represents TensorIterator layer
1148  */
1149 class TensorIterator : public CNNLayer {
1150 public:
1151  struct PortMap {
1152  // Data map rule
1153  int from; /**< Index of exteral data from ins/outs fields of CNNLayer */
1154  int to; /**< Index of internal data in iterator body */
1155 
1156  // Iteration rule
1157  int axis; /**< Axis to iterate throught */
1158  int stride; /**< Stride to iterate throught */
1159  int start; /**< Start index of iteration range */
1160  int end; /**< Last index of iteration range */
1161  int part_size; /**< Part size which will be transfered to body subnetwork */
1162  };
1163 
1164  struct Body {
1165  std::vector<DataPtr> inputs;
1166  std::vector<DataPtr> outputs;
1167  };
1168 
1169  std::vector<PortMap> input_port_map;
1170  std::vector<PortMap> output_port_map;
1171  std::vector<PortMap> back_edges;
1172 
1173  Body body;
1174 
1175  using CNNLayer::CNNLayer;
1176 };
1177 
1178 /**
1179  * @brief Base class for recurrent cell layers
1180  */
1182 public:
1184 
1185  /**
1186  * @brief Direct type of recurrent cell (including subtypes)
1187  * Description of particular cell semantics is in LSTMCell, GRUCell, RNNCell.
1188  */
1189  enum CellType {
1190  LSTM, /**< Original LSTM cell */
1191  GRU, /**< Original GRU cell */
1192  RNN, /**< Original RNN cell */
1193  GRU_LBR, /**< GRU cell modification. "Linear before reset" */
1194  };
1195 
1196  /** @copybrief CellType */
1197  CellType cellType = LSTM;
1198 
1199  /**
1200  * @brief Size of hidden state data
1201  *
1202  * In case of batch output state tensor will have shape [N, hidden_size]
1203  */
1204  int hidden_size = 0;
1205 
1206  /**
1207  * @brief Clip data into range [-clip, clip] on input of activations
1208  *
1209  * clip==0.0f means no clipping
1210  */
1211  float clip = 0.0f;
1212  /**
1213  * @brief Activations used inside recurrent cell
1214  *
1215  * Valid values: sigmoid, tanh, relu
1216  */
1217  std::vector<std::string> activations;
1218 
1219  /**
1220  * @brief Alpha parameters of activations
1221  *
1222  * Respective to activation list.
1223  */
1224  std::vector<float> activation_alpha;
1225 
1226  /**
1227  * @brief Beta parameters of activations
1228  *
1229  * Respective to activation list.
1230  */
1231  std::vector<float> activation_beta;
1232 };
1233 
1234 /**
1235  * @brief LSTM Cell layer
1236  *
1237  * G - number of gates (=4)
1238  * N - batch size
1239  * S - state size (=hidden_size)
1240  *
1241  * Inputs:
1242  * [N,D] Xt - input data
1243  * [N,S] Ht-1 - initial hidden state
1244  * [N,S] Ct-1 - initial cell state
1245  *
1246  * Outputs:
1247  * [N,S] Ht - out hidden state
1248  * [N,S] Ct - out cell state
1249  *
1250  * Weights:
1251  * - weights [G,S,D+S]
1252  * - biases [G,S]
1253  * NB! gates order is FICO {forget, input, candidate, output}
1254  *
1255  * activations is {_f, _g, _h}
1256  * default: {_f=sigm, _g=tanh, _h=tanh}
1257  *
1258  * Equations:
1259  *
1260  * * - matrix mult
1261  * (.) - eltwise mult
1262  * [,] - concatenation
1263  *
1264  * - ft = _f(Wf*[Ht-1, Xt] + Bf)
1265  * - it = _f(Wi*[Ht-1, Xt] + Bi)
1266  * - ct = _g(Wc*[Ht-1, Xt] + Bc)
1267  * - ot = _f(Wo*[Ht-1, Xt] + Bo)
1268  * - Ct = ft (.) Ct-1 + it (.) ct
1269  * - Ht = ot (.) _h(Ct)
1270  */
1271 class LSTMCell : public RNNCellBase {
1272  public:
1273  using RNNCellBase::RNNCellBase;
1274  using RNNCellBase::operator=;
1275 };
1276 
1277 /**
1278  * @brief GRU Cell layer
1279  *
1280  * G - number of gates (=3)
1281  * N - batch size
1282  * S - state size (=hidden_size)
1283  *
1284  * Inputs:
1285  * [N,D] Xt - input data
1286  * [N,S] Ht-1 - initial hidden state
1287  *
1288  * Outputs:
1289  * [N,S] Ht - out hidden state
1290  *
1291  * Weights:
1292  * - weights [G,S,D+S]
1293  * - biases [G,S]
1294  * NB! gates order is ZRH {update, reset, output}
1295  *
1296  * activations is {_f, _g}
1297  * default: {_f=sigm, _g=tanh}
1298  *
1299  * Equations:
1300  *
1301  * * - matrix mult
1302  * (.) - eltwise mult
1303  * [,] - concatenation
1304  *
1305  * - zt = _f(Wz*[Ht-1, Xt] + Bz)
1306  * - rt = _f(Wr*[Ht-1, Xt] + Br)
1307  * - ht = _g(Wh*[rt (.) Ht-1, Xt] + Bh)
1308  * - Ht = (1 - zt) (.) ht + zt (.) Ht-1
1309  */
1310 class GRUCell : public RNNCellBase {
1311  public:
1312  using RNNCellBase::RNNCellBase;
1313  using RNNCellBase::operator=;
1314 };
1315 
1316 /**
1317  * @brief RNN Cell layer
1318  *
1319  * G - number of gates (=1)
1320  * N - batch size
1321  * S - state size (=hidden_size)
1322  *
1323  * Inputs:
1324  * [N,D] Xt - input data
1325  * [N,S] Ht-1 - initial hidden state
1326  *
1327  * Outputs:
1328  * [N,S] Ht - out hidden state
1329  *
1330  * Weights:
1331  * - weights [G,S,D+S]
1332  * - biases [G,S]
1333  *
1334  * activations is {_f}
1335  * default: {_f=tanh}
1336  *
1337  * Equations:
1338  *
1339  * * - matrix mult
1340  * [,] - concatenation
1341  *
1342  * - Ht = _f(Wi*[Ht-1, Xt] + Bi)
1343  */
1344 class RNNCell : public RNNCellBase {
1345  public:
1346  using RNNCellBase::RNNCellBase;
1347  using RNNCellBase::operator=;
1348 };
1349 
1350 
1351 /**
1352  * @brief Sequence of recurrent cells
1353  *
1354  * N - batch size
1355  * T - sequence size
1356  * S - state size (=hidden_size)
1357  * NS - num of state tensors (LSTM=2, GRU/RNN=1)
1358  * ND - num of direction (BDR=2, WFD/BWD=1)
1359  *
1360  * Inputs:
1361  * [N,T,D] Xt - input data
1362  * [ND,N,S] Ht-1 - initial hidden state
1363  * [ND,N,S] Ct-1 - initial cell state // if NS==2
1364  * [N] SL - sequence length (optional input)
1365  *
1366  * Outputs:
1367  * [ND,N,T,S] Xt - input data
1368  * [ND,N,S] Ht-1 - initial hidden state
1369  * [ND,N,S] Ct-1 - initial cell state // if NS==2
1370  *
1371  * NB! if axis==0 batch and sequense dimensions are swapped (N <-> T) for input and output tensors
1372  *
1373  * Weights:
1374  * - weights [ND,G,S,D+S]
1375  * - biases [ND,G,S]
1376  * NB! if ND==2 weights are concatenated cell weights [forward_cell_weights, backward_cell_weights]
1377  *
1378  */
1380 public:
1381  using RNNCellBase::RNNCellBase;
1382 
1383  /**
1384  * @brief An axis by which iteration is performed
1385  * axis=0 means first input/output data blob dimension is sequence
1386  * axis=1 means first input/output data blob dimension is batch
1387  */
1388  unsigned int axis = 1;
1389 
1390  /**
1391  * @brief Direction of iteration through sequence dimension
1392  */
1393  enum Direction {
1394  FWD, /**< Forward mode. Iterate starts from index 0 with step 1. */
1395  BWD, /**< Backward mode. Iterate starts from last index with step -1. */
1396  BDR /**< Bidirectional mode. First is forward pass, second is backward. */
1397  };
1398 
1399  /** @copybrief Direction */
1400  Direction direction = FWD;
1401 };
1402 
1403 /**
1404  * @brief This class represents a Layer which performs Scale and Shift
1405  */
1406 class PReLULayer : public WeightableLayer {
1407 public:
1408  /**
1409  * @brief A flag that indicates if the same negative_slope value is used for all the features. If false, the value is used pixel wise
1410  */
1412 
1413 public:
1414  /**
1415  * @brief A default constructor. Creates a new PReLULayer instance and initializes layer parameters with the given values.
1416  * @param prms Initial layer parameters
1417  */
1418  explicit PReLULayer(const LayerParams &prms) : WeightableLayer(prms), _channel_shared(false) {}
1419 };
1420 
1421 /**
1422  * @brief This class represents a standard Power Layer
1423  * Formula is: output = (offset + scale * input) ^ power
1424  */
1425 class PowerLayer : public CNNLayer {
1426 public:
1427  /**
1428  * @brief An exponent value
1429  */
1430  float power = 1.f;
1431  /**
1432  * @brief A scale factor
1433  */
1434  float scale = 1.f;
1435  /**
1436  * @brief An offset value
1437  */
1438  float offset = 0.f;
1439 
1440  /**
1441  * @brief Creates a new PowerLayer instance.
1442  */
1443  using CNNLayer::CNNLayer;
1444 };
1445 
1446 /**
1447  * @brief This class represents a Batch Normalization Layer
1448  */
1450 public:
1451  /**
1452  * @brief A small value to add to the variance estimate to avoid division by zero
1453  */
1454  float epsilon = 1e-3f;
1455 
1456  /**
1457  * @brief Creates a new BatchNormalizationLayer instance.
1458  */
1460 };
1461 
1462 /**
1463  * @brief This class represents a general matrix multiplication operation layer
1464  * Formula is: dst := alpha*src1*src2 + beta*src3
1465  */
1466 class GemmLayer : public CNNLayer {
1467 public:
1468  /**
1469  * @brief A scale factor of src1 matrix
1470  */
1471  float alpha = 1.f;
1472  /**
1473  * @brief A scale factor of src3 matrix
1474  */
1475  float beta = 1.f;
1476  /**
1477  * @brief A flag that indicates if the src1 matrix is to be transposed
1478  */
1479  bool transpose_a = false;
1480  /**
1481  * @brief A flag that indicates if the src2 matrix is to be transposed
1482  */
1483  bool transpose_b = false;
1484  /**
1485  * @brief Creates a new GemmLayer instance.
1486  */
1487  using CNNLayer::CNNLayer;
1488 };
1489 
1490 /**
1491  * @brief This class represents a standard Pad layer
1492  * Adds paddings to input tensor
1493  */
1494 class PadLayer : public CNNLayer {
1495 public:
1496  /**
1497  * @enum ePadMode
1498  * @brief Defines possible modes of pad operation
1499  */
1500  enum ePadMode {
1501  Constant = 0, Edge, Reflect, Symmetric
1502  };
1503 
1504  /**
1505  * @brief Size of padding in the beginning of each axis
1506  */
1508  /**
1509  * @brief Size of padding in the end of each axis
1510  */
1512  /**
1513  * @brief Mode of pad operation
1514  */
1515  ePadMode pad_mode = Constant;
1516  /**
1517  * @brief A pad value which is used for filling in Constant mode
1518  */
1519  float pad_value = 0.0f;
1520  /**
1521  * @brief Creates a new PadLayer instance.
1522  */
1523  using CNNLayer::CNNLayer;
1524 };
1525 
1526 /**
1527  * @brief This class represents a standard Gather layer
1528  * Gather slices from Dictionary according to Indexes
1529  */
1530 class GatherLayer : public CNNLayer {
1531 public:
1532  /**
1533  * @brief The axis in Dictionary to gather Indexes from
1534  */
1535  int axis = 0;
1536  /**
1537  * @brief Creates a new GatherLayer instance.
1538  */
1539  using CNNLayer::CNNLayer;
1540 };
1541 
1542 /**
1543  * @brief This class represents a standard Strided Slice layer
1544  * Strided Slice picks from input tensor according parameters
1545  */
1546 class StridedSliceLayer : public CNNLayer {
1547 public:
1548  /**
1549  * @brief The begin_mask is a bitmask where bit i being 0 means
1550  * to ignore the begin value and instead use the default value
1551  */
1552  std::string begin_mask;
1553  /**
1554  * @brief Analogous to begin_mask
1555  */
1556  std::string end_mask;
1557  /**
1558  * @brief The ellipsis_mask is a bitmask where bit i being 1 means
1559  * the i-th is actually an ellipsis
1560  */
1561  std::string ellipsis_mask;
1562  /**
1563  * @brief The new_axis_mask_ is a bitmask where bit i being 1 means
1564  * the i-th position creates a new 1 dimension shape
1565  */
1566  std::string new_axis_mask;
1567  /**
1568  * @brief The shrink_axis_mask is a bitmask where bit i being 1 means
1569  * the i-th position shrinks the dimensionality
1570  */
1571  std::string shrink_axis_mask;
1572 
1573  /**
1574  * @brief Creates a new StridedSliceLayer instance.
1575  */
1576  using CNNLayer::CNNLayer;
1577 };
1578 
1579 /**
1580 * @brief This class represents a standard Shuffle Channels layer
1581 * Shuffle Channels picks from input tensor according parameters
1582 */
1584 public:
1585  /**
1586  * @brief The axis in tensor to shuffle channels
1587  */
1588  int axis = 1;
1589 
1590  /**
1591  * @brief The group of output shuffled channels
1592  */
1593  unsigned int group = 1;
1594 
1595  /**
1596  * @brief Creates a new ShuffleChannelsLayer instance.
1597  */
1598  using CNNLayer::CNNLayer;
1599 };
1600 
1601 
1602 /**
1603 * @brief This class represents a standard Depth To Space layer
1604 * Depth To Space picks from input tensor according parameters
1605 */
1606 class DepthToSpaceLayer : public CNNLayer {
1607 public:
1608  /**
1609  * @brief The group of output shuffled channels
1610  */
1611  unsigned int block_size = 1;
1612 
1613  /**
1614  * @brief Creates a new DepthToSpaceLayer instance.
1615  */
1616  using CNNLayer::CNNLayer;
1617 };
1618 
1619 
1620 /**
1621 * @brief This class represents a standard Space To Depth layer
1622 * Depth To Space picks from input tensor according parameters
1623 */
1624 class SpaceToDepthLayer : public CNNLayer {
1625 public:
1626  /**
1627  * @brief The group of output Space To Depth
1628  */
1629  unsigned int block_size = 1;
1630 
1631  /**
1632  * @brief Creates a new SpaceToDepthLayer instance.
1633  */
1634  using CNNLayer::CNNLayer;
1635 };
1636 
1637 
1638 /**
1639  * @brief This class represents SparseFillEmptyRows layer
1640  * SparseFillEmptyRows fills empty rows in a sparse tensor
1641  */
1643 public:
1644  /**
1645  * @brief Creates a new SparseFillEmptyRowsLayer instance.
1646  */
1647  using CNNLayer::CNNLayer;
1648 };
1649 
1650 
1651 /**
1652 * @brief This class represents a standard Reverse Sequence layer
1653 * Reverse Sequence modifies input tensor according parameters
1654 */
1656 public:
1657  /**
1658  * @brief The seq_axis dimension in tensor which is partially reversed
1659  */
1660  int seq_axis = 1;
1661 
1662  /**
1663  * @brief The batch_axis dimension in tensor along which reversal is performed
1664  */
1665  int batch_axis = 0;
1666 
1667  /**
1668  * @brief Creates a new ReverseSequence instance.
1669  */
1670  using CNNLayer::CNNLayer;
1671 };
1672 
1673 
1674 /**
1675 * @brief This class represents a OneHot layer
1676 * Converts input into OneHot representation.
1677 */
1678 class OneHotLayer : public CNNLayer {
1679 public:
1680  /**
1681  * @brief A depth of representation
1682  */
1683  unsigned int depth = 0;
1684 
1685  /**
1686  * @brief The locations represented by indices in input take value on_value
1687  */
1688  float on_value = 1.f;
1689 
1690  /**
1691  * @brief The locations not represented by indices in input take value off_value
1692  */
1693  float off_value = 0.f;
1694 
1695  /**
1696  * @brief Define the shape of output tensor
1697  */
1698  int axis = -1;
1699 
1700  /**
1701  * @brief Creates a new OneHot instance
1702  */
1703  using CNNLayer::CNNLayer;
1704 };
1705 
1706 
1707 /**
1708 * @brief This class represents a standard RangeLayer layer
1709 * RangeLayer modifies input tensor dimensions according parameters
1710 */
1711 class RangeLayer : public CNNLayer {
1712 public:
1713  /**
1714  * @brief Creates a new RangeLayer instance.
1715  */
1716  using CNNLayer::CNNLayer;
1717 };
1718 
1719 
1720 /**
1721 * @brief This class represents a standard Fill layer
1722 * RFill modifies input tensor according parameters
1723 */
1724 class FillLayer : public CNNLayer {
1725 public:
1726  /**
1727  * @brief Creates a new Fill instance.
1728  */
1729  using CNNLayer::CNNLayer;
1730 };
1731 
1732 
1733 /**
1734 * @brief This class represents a SelectLayer layer
1735 * SelectLayer layer takes elements from the second (“then”) or the third (“else”) input based on condition mask (“cond”) provided in the first input.
1736 * The “cond” tensor is broadcasted to “then” and “else” tensors.
1737 * The output tensor shape is equal to broadcasted shape of “cond”, “then” and “else”.
1738 */
1739 class SelectLayer : public CNNLayer {
1740 public:
1741  /**
1742  * @brief Creates a new SelectLayer instance.
1743  */
1744  using CNNLayer::CNNLayer;
1745 };
1746 
1747 
1748 /**
1749 * @brief This class represents a standard Broadcast layer
1750 * Broadcast modifies input tensor dimensions according parameters
1751 */
1752 class BroadcastLayer : public CNNLayer {
1753 public:
1754  /**
1755  * @brief Creates a new Broadcast instance.
1756  */
1757  using CNNLayer::CNNLayer;
1758 };
1759 
1760 /**
1761  * @brief This class represents a quantization operation layer
1762  * Element-wise linear quantization of floating point input values into a descrete set of floating point values
1763  */
1764 class QuantizeLayer : public CNNLayer {
1765 public:
1766  /**
1767  * @brief The number of quantization levels
1768  */
1769  int levels = 1;
1770 
1771  /**
1772  * @brief Creates a new QuantizeLayer instance.
1773  */
1774  using CNNLayer::CNNLayer;
1775 };
1776 
1777 
1778 /**
1779 * @brief This class represents a standard Math layers
1780 * Math modifies input tensor dimensions according parameters
1781 */
1782 class MathLayer : public CNNLayer {
1783 public:
1784  /**
1785  * @brief Creates a new Math instance.
1786  */
1787  using CNNLayer::CNNLayer;
1788 };
1789 
1790 
1791 /**
1792 * @brief This class represents a standard Reduce layers
1793 * Reduce modifies input tensor according parameters
1794 */
1795 class ReduceLayer : public CNNLayer {
1796 public:
1797  /**
1798  * @brief The keep_dims dimension in tensor which is partially reversed
1799  */
1800  bool keep_dims = true;
1801 
1802  /**
1803  * @brief Creates a new Reduce instance.
1804  */
1805  using CNNLayer::CNNLayer;
1806 };
1807 
1808 
1809 /**
1810  * @brief This class represents a standard TopK layer
1811  * TopK picks top K values from input tensor according parameters
1812  */
1813 class TopKLayer : public CNNLayer {
1814 public:
1815  /**
1816  * @brief The mode could be 'max' or 'min'
1817  */
1818  std::string mode;
1819  /**
1820  * @brief top K values sort mode could be 'value' or 'index'
1821  */
1822  std::string sort;
1823  /**
1824  * @brief The axis dimension in tensor which is top K values are picked
1825  */
1826  int axis = -1;
1827 
1828  /**
1829  * @brief Creates a new TopKLayer instance.
1830  */
1831  using CNNLayer::CNNLayer;
1832 };
1833 
1834 
1835 /**
1836  * @brief This class represents Unique layer.
1837  * The Unique operation searches for unique elements in 1-D input
1838  */
1839 class UniqueLayer : public CNNLayer {
1840 public:
1841  /**
1842  * @brief A flag indicating whether to sort unique elements
1843  */
1844  bool sorted;
1845  /**
1846  * @brief A flag indicating whether to return indices of input data elements in the output of uniques
1847  */
1849  /**
1850  * @brief A flag indicating whether to return a number of occurences for each unique element
1851  */
1853 
1854  /**
1855  * @brief Creates a new UniqueLayer instance.
1856  */
1857  using CNNLayer::CNNLayer;
1858 };
1859 
1860 
1861 /**
1862  * @brief This class represents a standard NonMaxSuppression layer
1863  */
1865 public:
1866  /**
1867  * @brief The 'center_point_box' indicates the format of the box data
1868  */
1869  bool center_point_box = false;
1870  /**
1871  * @brief Creates a new NonMaxSuppressionLayer instance.
1872  */
1873  using CNNLayer::CNNLayer;
1874 };
1875 
1876 
1877 /**
1878  * @brief This class represents a standard Scatter layer
1879  */
1880 class ScatterLayer : public CNNLayer {
1881 public:
1882  /**
1883  * @brief The axis in Dictionary to scatter Indexes from
1884  */
1885  int axis = 0;
1886  /**
1887  * @brief Creates a new ScatterLayer instance.
1888  */
1889  using CNNLayer::CNNLayer;
1890 };
1891 
1892 } // namespace InferenceEngine
int GetParamAsInt(const char *param, int def) const
Returns an integer value for the given parameter or returns the default value.
Definition: ie_layers.h:237
BinaryConvolutionLayer(const LayerParams &p)
Creates a new BinaryConvolutionLayer instance.
Definition: ie_layers.h:804
std::shared_ptr< CNNLayer > Ptr
A shared pointer to CNNLayer.
Definition: ie_layers.h:46
#define THROW_IE_EXCEPTION
A macro used to throw the exception with a notable description.
Definition: ie_exception.hpp:22
#define DEFINE_PROP(prop_name)
convinenent way to declare property with backward compatibility to 2D members
Definition: ie_layers.h:559
PoolingLayer(const PoolingLayer &that)
copy constructor
Definition: ie_layers.h:730
std::vector< int > axis
A vector of dimensions for cropping.
Definition: ie_layers.h:1069
virtual const DataPtr input() const
Returns the first element of the input data for this layer.
Definition: ie_layers.h:106
This class represents a Layer which performs Scale and Shift.
Definition: ie_layers.h:1406
std::string type
Layer type.
Definition: ie_layers.h:55
unsigned int _group
Number of groups.
Definition: ie_layers.h:596
LSTM Cell layer.
Definition: ie_layers.h:1271
PoolType _type
A pooling type.
Definition: ie_layers.h:695
This class represents a standard Strided Slice layer Strided Slice picks from input tensor according ...
Definition: ie_layers.h:1546
unsigned int GetParamAsUInt(const char *param, unsigned int def) const
Returns an unsigned integer value for the given parameter or returns the default value.
Definition: ie_layers.h:313
PoolType
Defines available pooling types.
Definition: ie_layers.h:684
float GetParamAsFloat(const char *param, float def) const
Gets float value for the given parameter.
Definition: ie_layers.h:159
This class represents a standard crop layer.
Definition: ie_layers.h:1064
std::vector< float > activation_beta
Beta parameters of activations.
Definition: ie_layers.h:1231
The method holds the user values to enable binding of data per graph node.
Definition: ie_common.h:66
This structure describes ROI data.
Definition: ie_blob.h:1082
PReLULayer(const LayerParams &prms)
A default constructor. Creates a new PReLULayer instance and initializes layer parameters with the gi...
Definition: ie_layers.h:1418
This class represents a standard Power Layer Formula is: output = (offset + scale * input) ^ power...
Definition: ie_layers.h:1425
std::string begin_mask
The begin_mask is a bitmask where bit i being 0 means to ignore the begin value and instead use the d...
Definition: ie_layers.h:1552
std::vector< int > GetParamAsInts(const char *param, std::vector< int > def) const
Returns a vector of int values for the given parameter or returns the default value.
Definition: ie_layers.h:269
std::vector< int > shape
A vector of sizes of the shape.
Definition: ie_layers.h:1093
Inference Engine API.
Definition: ie_argmax_layer.hpp:11
Definition: ie_layers.h:1394
This is an internal common Layer parameter parsing arguments.
Definition: ie_layers.h:29
bool _channel_shared
A flag that indicates if the same negative_slope value is used for all the features. If false, the value is used pixel wise.
Definition: ie_layers.h:1411
PropertyVector< unsigned int > _dilation
A convolution dilations array [X, Y, Z, ...].
Definition: ie_layers.h:584
This class represents a standard Space To Depth layer Depth To Space picks from input tensor accordin...
Definition: ie_layers.h:1624
eBinaryConvolutionMode _mode
Mode of binary convolution operation.
Definition: ie_layers.h:756
Definition: ie_layers.h:1193
This class represents a OneHot layer Converts input into OneHot representation.
Definition: ie_layers.h:1678
Base class for recurrent cell layers.
Definition: ie_layers.h:1181
PropertyVector< unsigned int > pads_begin
Size of padding in the beginning of each axis.
Definition: ie_layers.h:1507
PropertyVector< unsigned int > _dilation
A convolution dilations array [X, Y, Z, ...].
Definition: ie_layers.h:783
This class represents a layer with Weights and/or Biases (e.g. Convolution/Fully Connected, etc.)
Definition: ie_layers.h:533
Blob::Ptr _weights
A pointer to a weights blob.
Definition: ie_layers.h:544
PropertyVector< unsigned int > _stride
A convolution strides array [X, Y, Z, ...].
Definition: ie_layers.h:584
This class represents a standard Fill layer RFill modifies input tensor according parameters...
Definition: ie_layers.h:1724
WeightableLayer(const LayerParams &prms)
A default constructor. Constructs a WeightableLayer instance and initiates layer parameters with the ...
Definition: ie_layers.h:539
std::vector< DataWeakPtr > insData
A vector of weak pointers to the input data elements of this layer in the di-graph (order matters) ...
Definition: ie_layers.h:67
RNN Cell layer.
Definition: ie_layers.h:1344
std::string _auto_pad
Auto padding type.
Definition: ie_layers.h:600
void fuse(Ptr &layer)
Sets a layer to be fused with.
Definition: ie_layers.h:98
A header file for Blob and generic TBlob<>
This class represents a standard deconvolution layer.
Definition: ie_layers.h:638
std::string shrink_axis_mask
The shrink_axis_mask is a bitmask where bit i being 1 means the i-th position shrinks the dimensional...
Definition: ie_layers.h:1571
std::vector< unsigned int > GetParamAsUInts(const char *param) const
Returns a vector of unsigned int values for the given parameter.
Definition: ie_layers.h:383
Direction
Direction of iteration through sequence dimension.
Definition: ie_layers.h:1393
int to
Definition: ie_layers.h:1154
std::vector< int > offset
A vector of offsets for each dimension.
Definition: ie_layers.h:1077
This class represents a standard Scatter layer.
Definition: ie_layers.h:1880
This class represents standard MVN Layer.
Definition: ie_layers.h:959
PropertyVector< unsigned int > _kernel
A convolution kernel array [X, Y, Z, ...].
Definition: ie_layers.h:572
int stride
Definition: ie_layers.h:1158
static std::string ie_serialize_float(float value)
serialize float with c_locale formating used for default values serializing
Definition: ie_layers.h:146
Ptr _fusedWith
If suggested to fuse - a pointer to the layer which needs to be fused with this layer.
Definition: ie_layers.h:71
This class represents a standard Reduce layers Reduce modifies input tensor according parameters...
Definition: ie_layers.h:1795
bool sorted
A flag indicating whether to sort unique elements.
Definition: ie_layers.h:1844
std::string sort
top K values sort mode could be &#39;value&#39; or &#39;index&#39;
Definition: ie_layers.h:1822
ConvolutionLayer(const ConvolutionLayer &that)
copy constructor
Definition: ie_layers.h:626
PropertyVector< unsigned int > _pads_end
Pooling paddings end array [X, Y, Z, ...].
Definition: ie_layers.h:670
std::vector< std::string > activations
Activations used inside recurrent cell.
Definition: ie_layers.h:1217
std::string name
Layer name.
Definition: ie_layers.h:31
std::string type
Layer type.
Definition: ie_layers.h:33
This class represents a standard Reverse Sequence layer Reverse Sequence modifies input tensor accord...
Definition: ie_layers.h:1655
This class represents a Clamp activation layer Clamps all tensor elements into the range [min_value...
Definition: ie_layers.h:998
int part_size
Definition: ie_layers.h:1161
This class represents a layer that evenly splits the input into the supplied outputs.
Definition: ie_layers.h:877
Definition: ie_layers.h:1395
Definition: ie_layers.h:1191
eOperation
Defines possible operations that can be used.
Definition: ie_layers.h:1039
This class represents a standard TopK layer TopK picks top K values from input tensor according param...
Definition: ie_layers.h:1813
bool _exclude_pad
A flag that indicates if padding is excluded or not.
Definition: ie_layers.h:700
GRU Cell layer.
Definition: ie_layers.h:1310
This class represents an element wise operation layer.
Definition: ie_layers.h:1033
PropertyVector< unsigned int > pads_end
Size of padding in the end of each axis.
Definition: ie_layers.h:1511
This class represents standard GRN Layer.
Definition: ie_layers.h:941
This class represents a standard Shuffle Channels layer Shuffle Channels picks from input tensor acco...
Definition: ie_layers.h:1583
This class represents a standard reshape layer.
Definition: ie_layers.h:1088
std::string mode
The mode could be &#39;max&#39; or &#39;min&#39;.
Definition: ie_layers.h:1818
UserValue userValue
Convenience user values to store in this object as extra data.
Definition: ie_layers.h:75
Sequence of recurrent cells.
Definition: ie_layers.h:1379
PropertyVector< unsigned int > _pads_end
A convolution paddings end array [X, Y, Z, ...].
Definition: ie_layers.h:775
BinaryConvolutionLayer(const BinaryConvolutionLayer &that)
copy constructor
Definition: ie_layers.h:828
GRNLayer(const LayerParams &prms)
A default constructor. Creates a new GRNLayer instance and initializes layer parameters with the give...
Definition: ie_layers.h:947
CNNLayer(const LayerParams &prms)
A constructor. Creates a new CNNLayer instance and initializes layer parameters with the given values...
Definition: ie_layers.h:85
static float ie_parse_float(const std::string &str)
Parse string with float in accordance with IE rules.
Definition: ie_layers.h:128
This class represents a fully connected layer.
Definition: ie_layers.h:842
ePadMode
Defines possible modes of pad operation.
Definition: ie_layers.h:1500
This class represents a SelectLayer layer SelectLayer layer takes elements from the second (“then”)...
Definition: ie_layers.h:1739
std::map< std::string, std::string > params
Map of pairs: (parameter name, parameter value)
Definition: ie_layers.h:517
Definition: ie_layers.h:1190
bool return_inverse
A flag indicating whether to return indices of input data elements in the output of uniques...
Definition: ie_layers.h:1848
PoolingLayer(const LayerParams &p)
Creates a new PoolingLayer instance.
Definition: ie_layers.h:709
std::shared_ptr< Blob > Ptr
A smart pointer containing Blob object.
Definition: ie_blob.h:40
std::shared_ptr< Data > DataPtr
Smart pointer to Data.
Definition: ie_common.h:50
std::vector< float > coeff
A vector of coefficients to scale the operands.
Definition: ie_layers.h:1053
bool GetParamsAsBool(const char *param, bool def) const
Definition: ie_layers.h:452
std::string end_mask
Analogous to begin_mask.
Definition: ie_layers.h:1556
This class represents Unique layer. The Unique operation searches for unique elements in 1-D input...
Definition: ie_layers.h:1839
std::vector< unsigned int > GetParamAsUInts(const char *param, std::vector< unsigned int > def) const
Returns a vector of unsigned int values for the given parameter or returns the default value...
Definition: ie_layers.h:355
std::vector< float > activation_alpha
Alpha parameters of activations.
Definition: ie_layers.h:1224
unsigned int GetParamAsUInt(const char *param) const
Returns an unsigned integer value for the given parameter.
Definition: ie_layers.h:333
This class represents a ReLU6 activation layer Clamps all tensor elements into the range [0...
Definition: ie_layers.h:1020
This class represents a Batch Normalization Layer.
Definition: ie_layers.h:1449
unsigned int _group
Number of groups.
Definition: ie_layers.h:795
PropertyVector< unsigned int > _stride
Pooling strides array [X, Y, Z, ...].
Definition: ie_layers.h:678
This class represents a Layer which performs Scale and Shift.
Definition: ie_layers.h:1133
This class represents standard softmax Layer.
Definition: ie_layers.h:925
unsigned int _out_depth
A number of output feature maps (size) generating the 3&#39;rd output dimension.
Definition: ie_layers.h:592
PropertyVector< unsigned int > _kernel
A convolution kernel array [X, Y, Z, ...].
Definition: ie_layers.h:771
std::vector< float > GetParamAsFloats(const char *param) const
Returns a vector of float values for the given parameter.
Definition: ie_layers.h:214
This header file defines the main Data representation node.
bool return_counts
A flag indicating whether to return a number of occurences for each unique element.
Definition: ie_layers.h:1852
int end
Definition: ie_layers.h:1160
bool GetParamAsBool(const char *param, bool def) const
Returns a boolean value for the given parameter. The valid values are (true, false, 1, 0).
Definition: ie_layers.h:410
std::vector< int > GetParamAsInts(const char *param) const
Returns a vector of int values for the given parameter.
Definition: ie_layers.h:292
float _pad_value
A pad value which is used to fill pad area.
Definition: ie_layers.h:766
std::string ellipsis_mask
The ellipsis_mask is a bitmask where bit i being 1 means the i-th is actually an ellipsis.
Definition: ie_layers.h:1561
unsigned int _in_depth
A number of input feature maps (size) generating the 3&#39;rd input dimension.
Definition: ie_layers.h:761
PropertyVector< unsigned int > _kernel
Pooling kernel array [X, Y, Z, ...].
Definition: ie_layers.h:666
float GetParamAsFloat(const char *param) const
Returns a float value for the given layer parameter.
Definition: ie_layers.h:174
PropertyVector< unsigned int > _padding
Pooling paddings begin array [X, Y, Z, ...].
Definition: ie_layers.h:666
Definition: ie_layers.h:1164
int GetParamAsInt(const char *param) const
Returns an integer value for the given parameter.
Definition: ie_layers.h:252
This class represents a standard deformable convolution layer.
Definition: ie_layers.h:647
PropertyVector< unsigned int > _padding
A convolution paddings begin array [X, Y, Z, ...].
Definition: ie_layers.h:771
int across_channels
Indicate that mean value is calculated across channels.
Definition: ie_layers.h:970
Precision precision
Layer base operating precision.
Definition: ie_layers.h:59
This class represents a quantization operation layer Element-wise linear quantization of floating poi...
Definition: ie_layers.h:1764
unsigned int _out_depth
A number of output feature maps (size) generating the 3&#39;rd output dimension.
Definition: ie_layers.h:791
MVNLayer(const LayerParams &prms)
A default constructor. Creates a new MVNLayer instance and initializes layer parameters with the give...
Definition: ie_layers.h:965
This class represents a Rectified Linear activation layer.
Definition: ie_layers.h:981
This class represents a standard 3D Convolution Layer.
Definition: ie_layers.h:567
CellType
Direct type of recurrent cell (including subtypes) Description of particular cell semantics is in LST...
Definition: ie_layers.h:1189
bool GetParamAsBool(const char *param) const
Returns a boolean value for the given parameter.
Definition: ie_layers.h:431
std::string _auto_pad
Auto padding type.
Definition: ie_layers.h:704
std::string _auto_pad
Auto padding type.
Definition: ie_layers.h:799
This class represents a standard Pad layer Adds paddings to input tensor.
Definition: ie_layers.h:1494
This header file contains aspects of working on different devices like CPU, GEN, FPGA, etc.
This class represents a standard Tile Layer.
Definition: ie_layers.h:1112
This class represents a standard binary convolution layer.
Definition: ie_layers.h:743
Precision precision
Layer precision.
Definition: ie_layers.h:35
PropertyVector< unsigned int > _pads_end
A convolution paddings end array [X, Y, Z, ...].
Definition: ie_layers.h:576
Blob::Ptr _biases
A pointer to a biases blob.
Definition: ie_layers.h:548
This class represents a Linear Response Normalization (LRN) Layer.
Definition: ie_layers.h:893
This class represents TensorIterator layer.
Definition: ie_layers.h:1149
This class represents concatenation layer Takes as input several data elements and merges them to one...
Definition: ie_layers.h:859
std::vector< float > GetParamAsFloats(const char *param, std::vector< float > def) const
Returns a vector of float values for the given parameter or returns the default value.
Definition: ie_layers.h:190
This class represents a standard RangeLayer layer RangeLayer modifies input tensor dimensions accordi...
Definition: ie_layers.h:1711
This is a base abstraction Layer - all DNN Layers inherit from this class.
Definition: ie_layers.h:41
int start
Definition: ie_layers.h:1159
std::string affinity
Layer affinity set by user.
Definition: ie_layers.h:79
This class represents a standard pooling layer.
Definition: ie_layers.h:661
PropertyVector< unsigned int > _stride
A convolution strides array [X, Y, Z, ...].
Definition: ie_layers.h:783
Definition: ie_layers.h:1151
This class represents a standard Gather layer Gather slices from Dictionary according to Indexes...
Definition: ie_layers.h:1530
Definition: ie_layers.h:1192
std::string GetParamAsString(const char *param) const
Returns a string value for the given parameter. Throws exception if parameter was not found...
Definition: ie_layers.h:489
class CNNLayer GenericLayer
Alias for CNNLayer object.
Definition: ie_layers.h:528
This class represents a standard Math layers Math modifies input tensor dimensions according paramete...
Definition: ie_layers.h:1782
std::string new_axis_mask
The new_axis_mask_ is a bitmask where bit i being 1 means the i-th position creates a new 1 dimension...
Definition: ie_layers.h:1566
PropertyVector< unsigned int > _padding
A convolution paddings begin array [X, Y, Z, ...].
Definition: ie_layers.h:572
std::map< std::string, Blob::Ptr > blobs
Map of pairs: (name, weights/biases blob)
Definition: ie_layers.h:522
std::string GetParamAsString(const char *param, const char *def) const
Returns a string value for the given parameter or returns the default one.
Definition: ie_layers.h:462
std::vector< DataPtr > outData
A vector of pointers to the output data elements of this layer in the di-graph (order matters) ...
Definition: ie_layers.h:63
eBinaryConvolutionMode
Defines possible modes of binary convolution operation.
Definition: ie_layers.h:749
int from
Definition: ie_layers.h:1153
This class represents a standard NonMaxSuppression layer.
Definition: ie_layers.h:1864
bool CheckParamPresence(const char *param) const
Checks the param presence in the layer.
Definition: ie_layers.h:475
This class represents a standard Depth To Space layer Depth To Space picks from input tensor accordin...
Definition: ie_layers.h:1606
This class represents a general matrix multiplication operation layer Formula is: dst := alpha*src1*s...
Definition: ie_layers.h:1466
int axis
Definition: ie_layers.h:1157
std::vector< int > dim
A vector of dimensions to be preserved.
Definition: ie_layers.h:1073
This class represents SparseFillEmptyRows layer SparseFillEmptyRows fills empty rows in a sparse tens...
Definition: ie_layers.h:1642
std::string name
Layer name.
Definition: ie_layers.h:51
This is a header file with common inference engine definitions.
ConvolutionLayer(const LayerParams &p)
Creates a new ConvolutionLayer instance.
Definition: ie_layers.h:605
This class holds precision value and provides precision related operations.
Definition: ie_precision.hpp:19
This class represents a standard Broadcast layer Broadcast modifies input tensor dimensions according...
Definition: ie_layers.h:1752