ie_layers.h
Go to the documentation of this file.
1 // Copyright (C) 2018 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 <cctype>
18 #include "ie_common.h"
19 #include "ie_data.h"
20 #include "ie_blob.h"
21 #include "ie_device.hpp"
22 #include "ie_layers_property.hpp"
23 
24 namespace InferenceEngine {
25 /**
26  * @brief This is an internal common Layer parameter parsing arguments
27  */
28 struct LayerParams {
29  /// @brief Layer name
30  std::string name;
31  /// @brief Layer type
32  std::string type;
33  /// @brief Layer precision
35 };
36 
37 /**
38  * @brief This is a base abstraction Layer - all DNN Layers inherit from this class
39  */
40 class CNNLayer {
41 public:
42  /**
43  * @brief A shared pointer to CNNLayer
44  */
45  using Ptr = std::shared_ptr<CNNLayer>;
46 
47  /**
48  * @brief Layer name
49  */
50  std::string name;
51  /**
52  * @brief Layer type
53  */
54  std::string type;
55  /**
56  * @brief Layer base operating precision
57  */
59  /**
60  * @brief A vector of pointers to the output data elements of this layer in the di-graph (order matters)
61  */
62  std::vector<DataPtr> outData;
63  /**
64  * @brief A vector of weak pointers to the input data elements of this layer in the di-graph (order matters)
65  */
66  std::vector<DataWeakPtr> insData;
67  /**
68  * @brief If suggested to fuse - a pointer to the layer which needs to be fused with this layer
69  */
71  /**
72  * @brief Convenience user values to store in this object as extra data
73  */
75  /**
76  * @brief Layer affinity set by user.
77  */
78  std::string affinity;
79 
80  /**
81  * @brief A constructor. Creates a new CNNLayer instance and initializes layer parameters with the given values.
82  * @param prms Basic common parsing parameters
83  */
84  explicit CNNLayer(const LayerParams &prms) : name(prms.name), type(prms.type),
85  precision(prms.precision), userValue({0}) {
86  }
87 
88  /**
89  * @brief A virtual destructor
90  */
91  virtual ~CNNLayer() = default;
92 
93  /**
94  * @brief Sets a layer to be fused with
95  * @param layer Reference to the layer to be fused with
96  */
97  void fuse(Ptr &layer) {
98  _fusedWith = layer;
99  }
100 
101  /**
102  * @brief Returns the first element of the input data for this layer
103  * @return A smart pointer to the input data element
104  */
105  virtual const DataPtr input() const {
106  if (insData.empty()) {
107  THROW_IE_EXCEPTION << "Internal error: input data is empty";
108  }
109  auto lockedFirstInsData = insData[0].lock();
110  if (!lockedFirstInsData) {
111  THROW_IE_EXCEPTION << "Internal error: unable to lock weak_ptr\n";
112  }
113  return lockedFirstInsData;
114  }
115 
116  /**
117  * @brief Checks if the input data and layer data are legitimate
118  */
119  INFERENCE_ENGINE_API_CPP(void) validateLayer();
120 
121  /**
122  * @brief Gets float value for the given parameter
123  * @param param - name of the parameter to find
124  * @param def - default value of the parameter if not found
125  * @return float value
126  */
127  float GetParamAsFloat(const char* param, float def) const {
128  std::string val = GetParamAsString(param, std::to_string(def).c_str());
129  try {
130  return std::stof(val);
131  } catch (...) {
132  THROW_IE_EXCEPTION << "Cannot parse parameter " << param << " from IR for layer " << name
133  << ". Value " << val << " cannot be casted to float.";
134  }
135  }
136 
137  /**
138  * @brief Returns a float value for the given layer parameter
139  * @param param Name of the layer parameter
140  * @return A float value for the specified parameter
141  */
142  float GetParamAsFloat(const char *param) const {
143  std::string val = GetParamAsString(param);
144  try {
145  return std::stof(val);
146  } catch (...) {
147  THROW_IE_EXCEPTION << "Cannot parse parameter " << param << " from IR for layer " << name
148  << ". Value " << val << " cannot be casted to float.";
149  }
150  }
151 
152  /**
153  * @brief Returns a vector of float values for the given parameter or returns the default value
154  * @param param Name of the layer parameter
155  * @param def Default value of the parameter if not found
156  * @return vector of float values
157  */
158  std::vector<float> GetParamAsFloats(const char *param, std::vector<float> def) const {
159  std::string vals = GetParamAsString(param, "");
160  std::vector<float> result;
161  std::istringstream stream(vals);
162  std::string str;
163  if (vals.empty())
164  return def;
165  while (getline(stream, str, ',')) {
166  try {
167  result.push_back(std::stof(str));
168  } catch (...) {
169  THROW_IE_EXCEPTION << "Cannot parse parameter " << param << " " << str << " from IR for layer " << name
170  << ". Value " << vals << " cannot be casted to floats.";
171  }
172  }
173  return result;
174  }
175 
176  /**
177  * @brief Returns a vector of float values for the given parameter
178  * @param param Name of the layer parameter
179  * @return vector of float values
180  */
181  std::vector<float> GetParamAsFloats(const char *param) const {
182  std::string vals = GetParamAsString(param);
183  std::vector<float> result;
184  std::istringstream stream(vals);
185  std::string str;
186  while (getline(stream, str, ',')) {
187  try {
188  result.push_back(std::stof(str));
189  } catch (...) {
190  THROW_IE_EXCEPTION << "Cannot parse parameter " << param << " " << str << " from IR for layer " << name
191  << ". Value " << vals << " cannot be casted to floats.";
192  }
193  }
194  return result;
195  }
196 
197  /**
198  * @brief Returns an integer value for the given parameter or returns the default value
199  * @param param Name of the layer parameter
200  * @param def Default value of the parameter if not found
201  * @return An int value for the specified parameter
202  */
203  int GetParamAsInt(const char *param, int def) const {
204  std::string val = GetParamAsString(param, std::to_string(def).c_str());
205  try {
206  return std::stoi(val);
207  } catch (...) {
208  THROW_IE_EXCEPTION << "Cannot parse parameter " << param << " from IR for layer " << name
209  << ". Value " << val << " cannot be casted to int.";
210  }
211  }
212 
213  /**
214  * @brief Returns an integer value for the given parameter
215  * @param param Name of the layer parameter
216  * @return An int value for the specified parameter
217  */
218  int GetParamAsInt(const char *param) const {
219  std::string val = GetParamAsString(param);
220  try {
221  return std::stoi(val);
222  } catch (...) {
223  THROW_IE_EXCEPTION << "Cannot parse parameter " << param << " from IR for layer " << name
224  << ". Value " << val << " cannot be casted to int.";
225  }
226  }
227 
228 
229  /**
230  * @brief Returns a vector of int values for the given parameter or returns the default value
231  * @param param Name of the layer parameter
232  * @param def Default value of the parameter if not found
233  * @return vector of int values
234  */
235  std::vector<int> GetParamAsInts(const char *param, std::vector<int> def) const {
236  std::string vals = GetParamAsString(param, "");
237  std::vector<int> result;
238  std::istringstream stream(vals);
239  std::string str;
240  if (vals.empty())
241  return def;
242  while (getline(stream, str, ',')) {
243  try {
244  result.push_back(std::stoi(str));
245  } catch (...) {
246  THROW_IE_EXCEPTION << "Cannot parse parameter " << param << " " << str << " from IR for layer " << name
247  << ". Value " << vals << " cannot be casted to int.";
248  }
249  }
250  return result;
251  }
252 
253  /**
254  * @brief Returns a vector of int values for the given parameter
255  * @param param Name of the layer parameter
256  * @return vector of int values
257  */
258  std::vector<int> GetParamAsInts(const char *param) const {
259  std::string vals = GetParamAsString(param);
260  std::vector<int> result;
261  std::istringstream stream(vals);
262  std::string str;
263  while (getline(stream, str, ',')) {
264  try {
265  result.push_back(std::stoi(str));
266  } catch (...) {
267  THROW_IE_EXCEPTION << "Cannot parse parameter " << param << " " << str << " from IR for layer " << name
268  << ". Value " << vals << " cannot be casted to int.";
269  }
270  }
271  return result;
272  }
273  /**
274  * @brief Returns an unsigned integer value for the given parameter or returns the default value
275  * @param param Name of the layer parameter
276  * @param def Default value of the parameter if not found
277  * @return An unsigned integer value for the specified parameter
278  */
279  unsigned int GetParamAsUInt(const char *param, unsigned int def) const {
280  std::string val = GetParamAsString(param, std::to_string(def).c_str());
281  std::string message = "Cannot parse parameter " + std::string(param) + " from IR for layer " + name
282  + ". Value " + val + " cannot be casted to int.";
283  try {
284  int value = std::stoi(val);
285  if (value < 0) {
286  THROW_IE_EXCEPTION << message;
287  }
288  return static_cast<unsigned int>(value);
289  } catch (...) {
290  THROW_IE_EXCEPTION << message;
291  }
292  }
293 
294  /**
295  * @brief Returns an unsigned integer value for the given parameter
296  * @param param Name of the layer parameter
297  * @return An unsigned integer value for the specified parameter
298  */
299  unsigned int GetParamAsUInt(const char *param) const {
300  std::string val = GetParamAsString(param);
301  std::string message = "Cannot parse parameter " + std::string(param) + " from IR for layer " + name
302  + ". Value " + val + " cannot be casted to int.";
303  try {
304  int value = std::stoi(val);
305  if (value < 0) {
306  THROW_IE_EXCEPTION << message;
307  }
308  return static_cast<unsigned int>(value);
309  } catch (...) {
310  THROW_IE_EXCEPTION << message;
311  }
312  }
313 
314 
315  /**
316  * @brief Returns a vector of unsigned int values for the given parameter or returns the default value
317  * @param param Name of the layer parameter
318  * @param def Default value of the parameter if not found
319  * @return vector of unsigned int values
320  */
321  std::vector<unsigned int> GetParamAsUInts(const char *param, std::vector<unsigned int> def) const {
322  std::string vals = GetParamAsString(param, "");
323  std::vector<unsigned int> result;
324  std::istringstream stream(vals);
325  std::string str;
326  std::string message = "Cannot parse parameter " + std::string(param) + " " + str + " from IR for layer " + name
327  + ". Value " + vals + " cannot be casted to int.";
328  if (vals.empty())
329  return def;
330  while (getline(stream, str, ',')) {
331  try {
332  int value = std::stoi(str);
333  if (value < 0) {
334  THROW_IE_EXCEPTION << message;
335  }
336  result.push_back(static_cast<unsigned int>(value));
337  } catch (...) {
338  THROW_IE_EXCEPTION << message;
339  }
340  }
341  return result;
342  }
343 
344  /**
345  * @brief Returns a vector of unsigned int values for the given parameter
346  * @param param Name of the layer parameter
347  * @return vector of unsigned int values
348  */
349  std::vector<unsigned int> GetParamAsUInts(const char *param) const {
350  std::string vals = GetParamAsString(param);
351  std::vector<unsigned int> result;
352  std::istringstream stream(vals);
353  std::string str;
354  std::string message = "Cannot parse parameter " + std::string(param) + " " + str + " from IR for layer " + name
355  + ". Value " + vals + " cannot be casted to int.";
356  while (getline(stream, str, ',')) {
357  try {
358  int value = std::stoi(str);
359  if (value < 0) {
360  THROW_IE_EXCEPTION << message;
361  }
362  result.push_back(static_cast<unsigned int>(value));
363  } catch (...) {
364  THROW_IE_EXCEPTION << message;
365  }
366  }
367  return result;
368  }
369  /**
370  * @brief Returns an boolean value for the given parameter.
371  * The valid values are (true, false, 1, 0).
372  * @param param Name of the layer parameter
373  * @param def Default value of the parameter if not found
374  * @return An bool value for the specified parameter
375  */
376  bool GetParamsAsBool(const char *param, bool def) const {
377  std::string val = GetParamAsString(param, std::to_string(def).c_str());
378  std::string loweredCaseValue;
379  std::transform(val.begin(), val.end(), std::back_inserter(loweredCaseValue), [](char value) {
380  return std::tolower(value);
381  });
382 
383  bool result = false;
384 
385  if (!(std::istringstream(loweredCaseValue) >> std::boolalpha >> result)) {
386  // attempting parse using non alpha bool
387  return static_cast<bool>(GetParamAsInt(param, def));
388  }
389 
390  return result;
391  }
392 
393  /**
394  * @brief Returns a string value for the given parameter or returns the default one
395  * @param param Name of the layer parameter
396  * @param def Default value of the parameter if not found
397  * @return A string value
398  */
399  std::string GetParamAsString(const char *param, const char *def) const {
400  auto it = params.find(param);
401  if (it == params.end()) {
402  return def;
403  }
404  return (*it).second;
405  }
406 
407  /**
408  * @brief Returns a string value for the given parameter.
409  * Throws exception if parameter was not found.
410  * @param param Name of the layer parameter
411  * @return A string value
412  */
413  std::string GetParamAsString(const char *param) const {
414  auto it = params.find(param);
415  if (it == params.end()) {
416  THROW_IE_EXCEPTION << "No such parameter name '" << param << "' for layer " << name;
417  }
418  return (*it).second;
419  }
420 
421  /**
422  * @brief Map of pairs: (parameter name, parameter value)
423  */
424  std::map<std::string, std::string> params;
425  /**
426  * @brief Map of pairs: (name, weights/biases blob)
427  */
428  std::map<std::string, Blob::Ptr> blobs;
429 };
430 
431 /**
432  * @brief Alias for CNNLayer object
433  */
434 using GenericLayer = class CNNLayer;
435 
436 /**
437  * @brief This class represents a layer with Weights and/or Biases (e.g. Convolution/Fully Connected, etc.)
438  */
439 class WeightableLayer : public CNNLayer {
440 public:
441  /**
442  * @brief A default constructor. Constructs a WeightableLayer instance and initiates layer parameters with the given values
443  * @param prms Initial layer parameters
444  */
445  explicit WeightableLayer(const LayerParams &prms) : CNNLayer(prms) {}
446 
447  /**
448  * @brief A pointer to a weights blob
449  */
451  /**
452  * @brief A pointer to a biases blob
453  */
455 
456  /**
457  * @brief Constructs a WeightableLayer instance and initiates layer parameters with the given values
458  */
459  using CNNLayer::CNNLayer;
460 };
461 
462 /**
463  * @brief convinenent way to declare property with backward compatibility to 2D members
464  */
465 #define DEFINE_PROP(prop_name) \
466 PropertyVector<unsigned int> prop_name;\
467 unsigned int &prop_name##_x = prop_name.at(X_AXIS);\
468 unsigned int &prop_name##_y = prop_name.at(Y_AXIS);\
469 
470 /**
471  * @brief This class represents a standard 3D Convolution Layer
472  */
474 public:
475  /**
476  * @brief A convolution kernel array [X, Y, Z, ...]
477  */
478  DEFINE_PROP(_kernel);
479  /**
480  * @brief A convolution paddings begin array [X, Y, Z, ...]
481  */
482  DEFINE_PROP(_padding);
483  /**
484  * @brief A convolution paddings end array [X, Y, Z, ...]
485  */
487  /**
488  * @brief A convolution strides array [X, Y, Z, ...]
489  */
490  DEFINE_PROP(_stride);
491  /**
492  * @brief A convolution dilations array [X, Y, Z, ...]
493  */
494  DEFINE_PROP(_dilation);
495  /**
496  * @brief A number of output feature maps (size) generating the 3'rd output dimension
497  */
498  unsigned int _out_depth = 0u;
499  /**
500  * @brief Number of groups
501  */
502  unsigned int _group = 1u;
503  /**
504  * @brief Auto padding type
505  */
506  std::string _auto_pad;
507 
508  /**
509  * @brief Creates a new ConvolutionLayer instance.
510  */
512  _kernel(2, 0u), _padding(2, 0u), _stride(2, 1u), _dilation(2, 1u) {}
513  /**
514  * @brief assignment operator
515  */
516  ConvolutionLayer & operator = (const ConvolutionLayer & that) {
517  if (&that != this) {
518  WeightableLayer::operator=(that);
519  _kernel = that._kernel;
520  _padding = that._padding;
521  _pads_end = that._pads_end;
522  _stride = that._stride;
523  _dilation = that._dilation;
524  _out_depth = that._out_depth;
525  _group = that._group;
526  }
527  return *this;
528  }
529  /**
530  * @brief move assignment operator
531  */
532  ConvolutionLayer& operator = (ConvolutionLayer &&) = default;
533  /**
534  * @brief copy constructor
535  */
537  operator = (that);
538  }
539  /**
540  * @brief move constructor
541  */
542  ConvolutionLayer(ConvolutionLayer &&) = default;
543 };
544 
545 /**
546  * @brief This class represents a standard deconvolution layer
547  */
549  public:
551  using ConvolutionLayer::operator=;
552 };
553 
554 /**
555  * @brief This class represents a standard pooling layer
556  */
557 class PoolingLayer : public CNNLayer {
558 public:
559  /**
560  * @brief Pooling kernel array [X, Y, Z, ...]
561  */
562  DEFINE_PROP(_kernel);
563  /**
564  * @brief Pooling paddings begin array [X, Y, Z, ...]
565  */
566  DEFINE_PROP(_padding);
567  /**
568  * @brief Pooling paddings end array [X, Y, Z, ...]
569  */
571  /**
572  * @brief Pooling strides array [X, Y, Z, ...]
573  */
574  DEFINE_PROP(_stride);
575 
576  /**
577  * @enum PoolType
578  * @brief Defines available pooling types
579  */
580  enum PoolType {
581  MAX = 1,
582  AVG = 2,
583  STOCH = 3,
584  ROI = 4,
585  SPACIAL_PYRAMID = 5
586  };
587 
588  /**
589  * @brief A pooling type
590  */
591  PoolType _type = MAX;
592 
593  /**
594  * @brief A flag that indicates if padding is excluded or not
595  */
596  bool _exclude_pad = false;
597  /**
598  * @brief Auto padding type
599  */
600  std::string _auto_pad;
601 
602  /**
603  * @brief Creates a new PoolingLayer instance.
604  */
605  explicit PoolingLayer(const LayerParams &p) : CNNLayer(p),
606  _kernel(2, 0u), _padding(2, 0u), _stride(2, 0u) {}
607 
608  /**
609  * @brief assignment operator
610  */
611  PoolingLayer & operator = (const PoolingLayer & that) {
612  if (&that != this) {
613  CNNLayer::operator=(that);
614  _kernel = that._kernel;
615  _padding = that._padding;
616  _pads_end = that._pads_end;
617  _stride = that._stride;
618  _type = that._type;
619  _exclude_pad = that._exclude_pad;
620  }
621  return *this;
622  }
623  /**
624  * @brief move assignment operator
625  */
626  PoolingLayer& operator = (PoolingLayer &&) = default;
627 
628  /**
629  * @brief copy constructor
630  */
631  PoolingLayer(const PoolingLayer & that) : CNNLayer(that) {
632  operator=(that);
633  }
634 
635  /**
636  * @brief move constructor
637  */
638  PoolingLayer(PoolingLayer &&) = default;
639 };
640 
641 #undef DEFINE_PROP
642 
643 /**
644  * @brief This class represents a fully connected layer
645  */
647 public:
648  /**
649  * @brief A size of output
650  */
651  unsigned int _out_num = 0;
652 
653  /**
654  * @brief Creates a new FullyConnectedLayer instance and initializes layer parameters with the given values.
655  */
657 };
658 
659 /**
660  * @brief This class represents concatenation layer
661  * Takes as input several data elements and merges them to one using the supplied axis
662  */
663 class ConcatLayer : public CNNLayer {
664 public:
665  /**
666  * @brief An axis on which concatenation operation is performed
667  */
668  unsigned int _axis = 1;
669 
670  /**
671  * @brief Creates a new ConcatLayer instance and initializes layer parameters with the given values.
672  * If batch is used, then batch needs to be specified as an input dimension also
673  * In current implementation 1 means channels, 0 - batch
674  */
675  using CNNLayer::CNNLayer;
676 };
677 
678 /**
679  * @brief This class represents a layer that evenly splits the input into the supplied outputs
680  */
681 class SplitLayer : public CNNLayer {
682 public:
683  /**
684  * @brief An axis on which split operation is performed
685  */
686  unsigned int _axis = 1;
687 
688  /**
689  * @brief Creates a new SplitLayer instance.
690  */
691  using CNNLayer::CNNLayer;
692 };
693 
694 /**
695  * @brief This class represents a Linear Response Normalization (LRN) Layer
696  */
697 class NormLayer : public CNNLayer {
698 public:
699  /**
700  * @brief Response size
701  */
702  unsigned int _size = 0;
703  /**
704  * @deprecated
705  */
706  unsigned int _k = 1;
707  /**
708  * @brief Alpha coefficient
709  */
710  float _alpha = 0;
711  /**
712  * @brief Beta coefficient
713  */
714  float _beta = 0;
715  /**
716  * @brief Flag to specify normalization across feature maps (true) or across channels
717  */
718  bool _isAcrossMaps = false;
719 
720  /**
721  * @brief Creates a new NormLayer instance.
722  */
723  using CNNLayer::CNNLayer;
724 };
725 
726 /**
727  * @brief This class represents standard softmax Layer
728  */
729 class SoftMaxLayer : public CNNLayer {
730 public:
731  /**
732  * @brief Axis number for a softmax operation
733  */
734  int axis = 1;
735  /**
736  * @brief Creates a new SoftMaxLayer instance.
737  */
738  using CNNLayer::CNNLayer;
739 };
740 
741 /**
742  * @class GRNLayer
743  * @brief This class represents standard GRN Layer
744  */
745 class GRNLayer : public CNNLayer {
746 public:
747  /**
748  * @brief A default constructor. Creates a new GRNLayer instance and initializes layer parameters with the given values.
749  * @param prms Initial layer parameters
750  */
751  explicit GRNLayer(const LayerParams &prms) : CNNLayer(prms), bias(0.f) {}
752 
753  /**
754  * @brief Bias for squares sum
755  */
756  float bias = 0.f;
757 };
758 
759 /**
760  * @class MVNLayer
761  * @brief This class represents standard MVN Layer
762  */
763 class MVNLayer : public CNNLayer {
764 public:
765  /**
766  * @brief A default constructor. Creates a new MVNLayer instance and initializes layer parameters with the given values.
767  * @param prms Initial layer parameters
768  */
769  explicit MVNLayer(const LayerParams &prms) : CNNLayer(prms), across_channels(0), normalize(1) {}
770 
771  /**
772  * @brief Indicate that mean value is calculated across channels
773  */
775 
776  /**
777  * @brief Indicate that the result needs to be normalized
778  */
779  int normalize = 1;
780 };
781 
782 /**
783  * @brief This class represents a Rectified Linear activation layer
784  */
785 class ReLULayer : public CNNLayer {
786 public:
787  /**
788  * @brief Negative slope is used to takle negative inputs instead of setting them to 0
789  */
790  float negative_slope = 0.0f;
791 
792  /**
793  * @brief Creates a new ReLULayer instance.
794  */
795  using CNNLayer::CNNLayer;
796 };
797 
798 /**
799  * @brief This class represents a Clamp activation layer
800  * Clamps all tensor elements into the range [min_value, max_value]
801  */
802 class ClampLayer : public CNNLayer {
803 public:
804  /**
805  * @brief A minimum value
806  */
807  float min_value = 0.0f;
808 
809  /**
810  * @brief A maximum value
811  */
812  float max_value = 1.0f;
813  /**
814  * @brief Creates a new ClampLayer instance.
815  */
816  using CNNLayer::CNNLayer;
817 };
818 
819 /**
820  * @brief This class represents an element wise operation layer
821  */
822 class EltwiseLayer : public CNNLayer {
823 public:
824  /**
825  * @enum eOperation
826  * @brief Defines possible operations that can be used
827  */
828  enum eOperation {
829  Sum = 0, Prod, Max
830  };
831 
832  /**
833  * @brief A type of the operation to use
834  */
835  eOperation _operation = Sum;
836 
837  /**
838  * @brief A vector of coefficients to scale the operands
839  */
840  std::vector<float> coeff;
841 
842  /**
843  * @brief Creates a new EltwiseLayer instance.
844  */
845  using CNNLayer::CNNLayer;
846 };
847 
848 /**
849  * @brief This class represents a standard crop layer
850  */
851 class CropLayer : public CNNLayer {
852 public:
853  /**
854  * @brief A vector of dimensions for cropping
855  */
856  std::vector<int> axis;
857  /**
858  * @brief A vector of dimensions to be preserved
859  */
860  std::vector<int> dim;
861  /**
862  * @brief A vector of offsets for each dimension
863  */
864  std::vector<int> offset;
865 
866  /**
867  * @brief Creates a new CropLayer instance.
868  */
869  using CNNLayer::CNNLayer;
870 };
871 
872 /**
873  * @brief This class represents a standard reshape layer
874  */
875 class ReshapeLayer : public CNNLayer {
876 public:
877  /**
878  * @brief A vector of sizes of the shape
879  */
880  std::vector<int> shape;
881  /**
882  * @brief A number of axis to be taken for a reshape
883  */
884  int axis = 0;
885  /**
886  * @brief A number of first axises to be taken for a reshape
887  */
888  int num_axes = -1;
889 
890  /**
891  * @brief Creates a new ReshapeLayer instance.
892  */
893  using CNNLayer::CNNLayer;
894 };
895 
896 /**
897  * @brief This class represents a standard Tile Layer
898  */
899 class TileLayer : public CNNLayer {
900 public:
901  /**
902  * @brief An index of the axis to tile
903  */
904  int axis = -1;
905  /**
906  * @brief A number of copies to be made
907  */
908  int tiles = -1;
909 
910  /**
911  * @brief Creates a new TileLayer instance.
912  */
913  using CNNLayer::CNNLayer;
914 };
915 
916 
917 /**
918  * @brief This class represents a Layer which performs Scale and Shift
919  */
921 public:
922  /**
923  * @brief A flag that indicates if the same value is used for all the features. If false, the value is used pixel wise
924  */
925  unsigned int _broadcast = 0;
926 
927  /**
928  * @brief Creates a new ScaleShiftLayer instance.
929  */
931 };
932 
933 /**
934  * @brief This class represents TensorIterator layer
935  */
936 class TensorIterator : public CNNLayer {
937 public:
938  struct PortMap {
939  // Data map rule
940  int from; /**< Index of exteral data from ins/outs fields of CNNLayer */
941  int to; /**< Index of internal data in iterator body */
942 
943  // Iteration rule
944  int axis; /**< Axis to iterate throught */
945  int stride; /**< Stride to iterate throught */
946  int start; /**< Start index of iteration range */
947  int end; /**< Last index of iteration range */
948  int part_size; /**< Part size which will be transfered to body subnetwork */
949  };
950 
951  struct Body {
952  std::vector<DataPtr> inputs;
953  std::vector<DataPtr> outputs;
954  };
955 
956  std::vector<PortMap> input_port_map;
957  std::vector<PortMap> output_port_map;
958  std::vector<PortMap> back_edges;
959 
960  Body body;
961 
962  using CNNLayer::CNNLayer;
963 };
964 
965 /**
966 * @class PReLULayer
967 * @brief This class represents a Layer which performs Scale and Shift
968 */
969 class PReLULayer : public WeightableLayer {
970 public:
971  /**
972  * @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
973  */
975 
976 public:
977  /**
978  * @brief A default constructor. Creates a new PReLULayer instance and initializes layer parameters with the given values.
979  * @param prms Initial layer parameters
980  */
981  explicit PReLULayer(const LayerParams &prms) : WeightableLayer(prms), _channel_shared(false) {}
982 };
983 
984 /**
985  * @brief This class represents a standard Power Layer
986  * Formula is: output = (offset + scale * input) ^ power
987  */
988 class PowerLayer : public CNNLayer {
989 public:
990  /**
991  * @brief An exponent value
992  */
993  float power = 1.f;
994  /**
995  * @brief A scale factor
996  */
997  float scale = 1.f;
998  /**
999  * @brief An offset value
1000  */
1001  float offset = 0.f;
1002 
1003  /**
1004  * @brief Creates a new PowerLayer instance.
1005  */
1006  using CNNLayer::CNNLayer;
1007 };
1008 
1009 /**
1010  * @brief This class represents a Batch Normalization Layer
1011  */
1013 public:
1014  /**
1015  * @brief A small value to add to the variance estimate to avoid division by zero
1016  */
1017  float epsilon = 1e-3f;
1018 
1019  /**
1020  * @brief Creates a new BatchNormalizationLayer instance.
1021  */
1023 };
1024 
1025 /**
1026  * @brief This class represents a general matrix multiplication operation layer
1027  * Formula is: dst := alpha*src1*src2 + beta*src3
1028  */
1029 class GemmLayer : public CNNLayer {
1030 public:
1031  /**
1032  * @brief A scale factor of src1 matrix
1033  */
1034  float alpha = 1.f;
1035  /**
1036  * @brief A scale factor of src3 matrix
1037  */
1038  float beta = 1.f;
1039  /**
1040  * @brief A flag that indicates if the src1 matrix is to be transposed
1041  */
1042  bool transpose_a = false;
1043  /**
1044  * @brief A flag that indicates if the src2 matrix is to be transposed
1045  */
1046  bool transpose_b = false;
1047  /**
1048  * @brief Creates a new GemmLayer instance.
1049  */
1050  using CNNLayer::CNNLayer;
1051 };
1052 
1053 /**
1054  * @brief This class represents a standard Pad layer
1055  * Adds paddings to input tensor
1056  */
1057 class PadLayer : public CNNLayer {
1058 public:
1059  /**
1060  * @enum ePadMode
1061  * @brief Defines possible modes of pad operation
1062  */
1063  enum ePadMode {
1064  Constant = 0, Edge, Reflect, Symmetric
1065  };
1066 
1067  /**
1068  * @brief Size of padding in the beginning of each axis
1069  */
1071  /**
1072  * @brief Size of padding in the end of each axis
1073  */
1075  /**
1076  * @brief Mode of pad operation
1077  */
1078  ePadMode pad_mode = Constant;
1079  /**
1080  * @brief A pad value which is used for filling in Constant mode
1081  */
1082  float pad_value = 0.0f;
1083  /**
1084  * @brief Creates a new PadLayer instance.
1085  */
1086  using CNNLayer::CNNLayer;
1087 };
1088 
1089 /**
1090  * @brief This class represents a standard Gather layer
1091  * Gather slices from Dictionary according to Indexes
1092  */
1093 class GatherLayer : public CNNLayer {
1094 public:
1095  /**
1096  * @brief The axis in Dictionary to gather Indexes from
1097  */
1098  int axis = 0;
1099  /**
1100  * @brief Creates a new GatherLayer instance.
1101  */
1102  using CNNLayer::CNNLayer;
1103 };
1104 } // 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:203
std::shared_ptr< CNNLayer > Ptr
A shared pointer to CNNLayer.
Definition: ie_layers.h:45
#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:465
PoolingLayer(const PoolingLayer &that)
copy constructor
Definition: ie_layers.h:631
std::vector< int > axis
A vector of dimensions for cropping.
Definition: ie_layers.h:856
virtual const DataPtr input() const
Returns the first element of the input data for this layer.
Definition: ie_layers.h:105
This class represents a Layer which performs Scale and Shift.
Definition: ie_layers.h:969
std::string type
Layer type.
Definition: ie_layers.h:54
unsigned int _group
Number of groups.
Definition: ie_layers.h:502
PoolType _type
A pooling type.
Definition: ie_layers.h:591
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:279
PoolType
Defines available pooling types.
Definition: ie_layers.h:580
float GetParamAsFloat(const char *param, float def) const
Gets float value for the given parameter.
Definition: ie_layers.h:127
This class represents a standard crop layer.
Definition: ie_layers.h:851
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:784
PReLULayer(const LayerParams &prms)
A default constructor. Creates a new PReLULayer instance and initializes layer parameters with the gi...
Definition: ie_layers.h:981
This class represents a standard Power Layer Formula is: output = (offset + scale * input) ^ power...
Definition: ie_layers.h:988
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:235
std::vector< int > shape
A vector of sizes of the shape.
Definition: ie_layers.h:880
Definition: ie_argmax_layer.hpp:11
This is an internal common Layer parameter parsing arguments.
Definition: ie_layers.h:28
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:974
PropertyVector< unsigned int > _dilation
A convolution dilations array [X, Y, Z, ...].
Definition: ie_layers.h:490
PropertyVector< unsigned int > pads_begin
Size of padding in the beginning of each axis.
Definition: ie_layers.h:1070
This class represents a layer with Weights and/or Biases (e.g. Convolution/Fully Connected, etc.)
Definition: ie_layers.h:439
Blob::Ptr _weights
A pointer to a weights blob.
Definition: ie_layers.h:450
PropertyVector< unsigned int > _stride
A convolution strides array [X, Y, Z, ...].
Definition: ie_layers.h:490
WeightableLayer(const LayerParams &prms)
A default constructor. Constructs a WeightableLayer instance and initiates layer parameters with the ...
Definition: ie_layers.h:445
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:66
std::string _auto_pad
Auto padding type.
Definition: ie_layers.h:506
void fuse(Ptr &layer)
Sets a layer to be fused with.
Definition: ie_layers.h:97
A header file for Blob and generic TBlob<>
This class represents a standard deconvolution layer.
Definition: ie_layers.h:548
std::vector< unsigned int > GetParamAsUInts(const char *param) const
Returns a vector of unsigned int values for the given parameter.
Definition: ie_layers.h:349
int to
Definition: ie_layers.h:941
std::vector< int > offset
A vector of offsets for each dimension.
Definition: ie_layers.h:864
This class represents standard MVN Layer.
Definition: ie_layers.h:763
PropertyVector< unsigned int > _kernel
A convolution kernel array [X, Y, Z, ...].
Definition: ie_layers.h:478
int stride
Definition: ie_layers.h:945
Ptr _fusedWith
If suggested to fuse - a pointer to the layer which needs to be fused with this layer.
Definition: ie_layers.h:70
ConvolutionLayer(const ConvolutionLayer &that)
copy constructor
Definition: ie_layers.h:536
PropertyVector< unsigned int > _pads_end
Pooling paddings end array [X, Y, Z, ...].
Definition: ie_layers.h:566
std::string name
Layer name.
Definition: ie_layers.h:30
class CNNLayer GenericLayer
Alias for CNNLayer object.
Definition: ie_layers.h:434
std::string type
Layer type.
Definition: ie_layers.h:32
This class represents a Clamp activation layer Clamps all tensor elements into the range [min_value...
Definition: ie_layers.h:802
int part_size
Definition: ie_layers.h:948
This class represents a layer that evenly splits the input into the supplied outputs.
Definition: ie_layers.h:681
eOperation
Defines possible operations that can be used.
Definition: ie_layers.h:828
bool _exclude_pad
A flag that indicates if padding is excluded or not.
Definition: ie_layers.h:596
This class represents an element wise operation layer.
Definition: ie_layers.h:822
PropertyVector< unsigned int > pads_end
Size of padding in the end of each axis.
Definition: ie_layers.h:1074
This class represents standard GRN Layer.
Definition: ie_layers.h:745
This class represents a standard reshape layer.
Definition: ie_layers.h:875
UserValue userValue
Convenience user values to store in this object as extra data.
Definition: ie_layers.h:74
GRNLayer(const LayerParams &prms)
A default constructor. Creates a new GRNLayer instance and initializes layer parameters with the give...
Definition: ie_layers.h:751
CNNLayer(const LayerParams &prms)
A constructor. Creates a new CNNLayer instance and initializes layer parameters with the given values...
Definition: ie_layers.h:84
This class represents a fully connected layer.
Definition: ie_layers.h:646
ePadMode
Defines possible modes of pad operation.
Definition: ie_layers.h:1063
std::map< std::string, std::string > params
Map of pairs: (parameter name, parameter value)
Definition: ie_layers.h:424
PoolingLayer(const LayerParams &p)
Creates a new PoolingLayer instance.
Definition: ie_layers.h:605
std::shared_ptr< Blob > Ptr
A smart pointer containing Blob object.
Definition: ie_blob.h:38
std::vector< float > coeff
A vector of coefficients to scale the operands.
Definition: ie_layers.h:840
bool GetParamsAsBool(const char *param, bool def) const
Returns an boolean value for the given parameter. The valid values are (true, false, 1, 0).
Definition: ie_layers.h:376
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:321
unsigned int GetParamAsUInt(const char *param) const
Returns an unsigned integer value for the given parameter.
Definition: ie_layers.h:299
This class represents a Batch Normalization Layer.
Definition: ie_layers.h:1012
PropertyVector< unsigned int > _stride
Pooling strides array [X, Y, Z, ...].
Definition: ie_layers.h:574
This class represents a Layer which performs Scale and Shift.
Definition: ie_layers.h:920
This class represents standard softmax Layer.
Definition: ie_layers.h:729
unsigned int _out_depth
A number of output feature maps (size) generating the 3&#39;rd output dimension.
Definition: ie_layers.h:498
std::vector< float > GetParamAsFloats(const char *param) const
Returns a vector of float values for the given parameter.
Definition: ie_layers.h:181
This header file defines the main Data representation node.
int end
Definition: ie_layers.h:947
std::vector< int > GetParamAsInts(const char *param) const
Returns a vector of int values for the given parameter.
Definition: ie_layers.h:258
PropertyVector< unsigned int > _kernel
Pooling kernel array [X, Y, Z, ...].
Definition: ie_layers.h:562
float GetParamAsFloat(const char *param) const
Returns a float value for the given layer parameter.
Definition: ie_layers.h:142
PropertyVector< unsigned int > _padding
Pooling paddings begin array [X, Y, Z, ...].
Definition: ie_layers.h:562
Definition: ie_layers.h:951
int GetParamAsInt(const char *param) const
Returns an integer value for the given parameter.
Definition: ie_layers.h:218
int across_channels
Indicate that mean value is calculated across channels.
Definition: ie_layers.h:774
Precision precision
Layer base operating precision.
Definition: ie_layers.h:58
MVNLayer(const LayerParams &prms)
A default constructor. Creates a new MVNLayer instance and initializes layer parameters with the give...
Definition: ie_layers.h:769
This class represents a Rectified Linear activation layer.
Definition: ie_layers.h:785
This class represents a standard 3D Convolution Layer.
Definition: ie_layers.h:473
std::string _auto_pad
Auto padding type.
Definition: ie_layers.h:600
This class represents a standard Pad layer Adds paddings to input tensor.
Definition: ie_layers.h:1057
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:899
Precision precision
Layer precision.
Definition: ie_layers.h:34
PropertyVector< unsigned int > _pads_end
A convolution paddings end array [X, Y, Z, ...].
Definition: ie_layers.h:482
Blob::Ptr _biases
A pointer to a biases blob.
Definition: ie_layers.h:454
This class represents a Linear Response Normalization (LRN) Layer.
Definition: ie_layers.h:697
This class represents TensorIterator layer.
Definition: ie_layers.h:936
This class represents concatenation layer Takes as input several data elements and merges them to one...
Definition: ie_layers.h:663
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:158
This is a base abstraction Layer - all DNN Layers inherit from this class.
Definition: ie_layers.h:40
std::shared_ptr< Data > DataPtr
Smart pointer to Data.
Definition: ie_common.h:50
int start
Definition: ie_layers.h:946
std::string affinity
Layer affinity set by user.
Definition: ie_layers.h:78
This class represents a standard pooling layer.
Definition: ie_layers.h:557
Definition: ie_layers.h:938
This class represents a standard Gather layer Gather slices from Dictionary according to Indexes...
Definition: ie_layers.h:1093
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:413
PropertyVector< unsigned int > _padding
A convolution paddings begin array [X, Y, Z, ...].
Definition: ie_layers.h:478
std::map< std::string, Blob::Ptr > blobs
Map of pairs: (name, weights/biases blob)
Definition: ie_layers.h:428
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:399
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:62
int from
Definition: ie_layers.h:940
This class represents a general matrix multiplication operation layer Formula is: dst := alpha*src1*s...
Definition: ie_layers.h:1029
int axis
Definition: ie_layers.h:944
std::vector< int > dim
A vector of dimensions to be preserved.
Definition: ie_layers.h:860
std::string name
Layer name.
Definition: ie_layers.h:50
This is a header file with common inference engine definitions.
ConvolutionLayer(const LayerParams &p)
Creates a new ConvolutionLayer instance.
Definition: ie_layers.h:511
This class holds precision value and provides precision related operations.
Definition: ie_precision.hpp:19