1 // Copyright (C) 2018-2019 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
6 * @brief a header file for internal Layers structure to describe layers information
18 #include "ie_common.h"
21 #include "ie_device.hpp"
22 #include "ie_layers_property.hpp"
24 namespace InferenceEngine {
26 * @brief This is an internal common Layer parameter parsing arguments
33 /// @brief Layer precision
38 * @brief This is a base abstraction Layer - all DNN Layers inherit from this class
43 * @brief A shared pointer to CNNLayer
45 using Ptr = std::shared_ptr<CNNLayer>;
56 * @brief Layer base operating precision
60 * @brief A vector of pointers to the output data elements of this layer in the di-graph (order matters)
62 std::vector<DataPtr> outData;
64 * @brief A vector of weak pointers to the input data elements of this layer in the di-graph (order matters)
66 std::vector<DataWeakPtr> insData;
68 * @brief If suggested to fuse - a pointer to the layer which needs to be fused with this layer
72 * @brief Convenience user values to store in this object as extra data
76 * @brief Layer affinity set by user.
81 * @brief A constructor. Creates a new CNNLayer instance and initializes layer parameters with the given values.
82 * @param prms Basic common parsing parameters
84 explicit CNNLayer(const LayerParams &prms) : name(prms.name), type(prms.type),
85 precision(prms.precision), userValue({0}) {
89 * @brief A virtual destructor
91 virtual ~CNNLayer() = default;
94 * @brief Sets a layer to be fused with
95 * @param layer Reference to the layer to be fused with
97 void fuse(Ptr &layer) {
102 * @brief Returns the first element of the input data for this layer
103 * @return A smart pointer to the input data element
105 virtual const DataPtr input() const {
106 if (insData.empty()) {
107 THROW_IE_EXCEPTION << "Internal error: input data is empty";
109 auto lockedFirstInsData = insData[0].lock();
110 if (!lockedFirstInsData) {
111 THROW_IE_EXCEPTION << "Internal error: unable to lock weak_ptr\n";
113 return lockedFirstInsData;
117 * @brief Checks if the input data and layer data are legitimate
119 INFERENCE_ENGINE_API_CPP(void) validateLayer();
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
127 float GetParamAsFloat(const char* param, float def) const {
128 std::string val = GetParamAsString(param, std::to_string(def).c_str());
130 return std::stof(val);
132 THROW_IE_EXCEPTION << "Cannot parse parameter " << param << " from IR for layer " << name
133 << ". Value " << val << " cannot be casted to float.";
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
142 float GetParamAsFloat(const char *param) const {
143 std::string val = GetParamAsString(param);
145 return std::stof(val);
147 THROW_IE_EXCEPTION << "Cannot parse parameter " << param << " from IR for layer " << name
148 << ". Value " << val << " cannot be casted to float.";
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
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);
165 while (getline(stream, str, ',')) {
167 result.push_back(std::stof(str));
169 THROW_IE_EXCEPTION << "Cannot parse parameter " << param << " " << str << " from IR for layer " << name
170 << ". Value " << vals << " cannot be casted to floats.";
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
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);
186 while (getline(stream, str, ',')) {
188 result.push_back(std::stof(str));
190 THROW_IE_EXCEPTION << "Cannot parse parameter " << param << " " << str << " from IR for layer " << name
191 << ". Value " << vals << " cannot be casted to floats.";
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
203 int GetParamAsInt(const char *param, int def) const {
204 std::string val = GetParamAsString(param, std::to_string(def).c_str());
206 return std::stoi(val);
208 THROW_IE_EXCEPTION << "Cannot parse parameter " << param << " from IR for layer " << name
209 << ". Value " << val << " cannot be casted to int.";
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
218 int GetParamAsInt(const char *param) const {
219 std::string val = GetParamAsString(param);
221 return std::stoi(val);
223 THROW_IE_EXCEPTION << "Cannot parse parameter " << param << " from IR for layer " << name
224 << ". Value " << val << " cannot be casted to int.";
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
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);
242 while (getline(stream, str, ',')) {
244 result.push_back(std::stoi(str));
246 THROW_IE_EXCEPTION << "Cannot parse parameter " << param << " " << str << " from IR for layer " << name
247 << ". Value " << vals << " cannot be casted to int.";
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
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);
263 while (getline(stream, str, ',')) {
265 result.push_back(std::stoi(str));
267 THROW_IE_EXCEPTION << "Cannot parse parameter " << param << " " << str << " from IR for layer " << name
268 << ". Value " << vals << " cannot be casted to int.";
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
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.";
284 int value = std::stoi(val);
286 THROW_IE_EXCEPTION << message;
288 return static_cast<unsigned int>(value);
290 THROW_IE_EXCEPTION << message;
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
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.";
304 int value = std::stoi(val);
306 THROW_IE_EXCEPTION << message;
308 return static_cast<unsigned int>(value);
310 THROW_IE_EXCEPTION << message;
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
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);
326 std::string message = "Cannot parse parameter " + std::string(param) + " " + str + " from IR for layer " + name
327 + ". Value " + vals + " cannot be casted to int.";
330 while (getline(stream, str, ',')) {
332 int value = std::stoi(str);
334 THROW_IE_EXCEPTION << message;
336 result.push_back(static_cast<unsigned int>(value));
338 THROW_IE_EXCEPTION << message;
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
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);
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, ',')) {
358 int value = std::stoi(str);
360 THROW_IE_EXCEPTION << message;
362 result.push_back(static_cast<unsigned int>(value));
364 THROW_IE_EXCEPTION << message;
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
376 bool GetParamAsBool(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);
385 if (!(std::istringstream(loweredCaseValue) >> std::boolalpha >> result)) {
386 // attempting parse using non alpha bool
387 return (GetParamAsInt(param, def) != 0);
393 * @deprecated Use GetParamAsBool function for that functionality
395 bool GetParamsAsBool(const char *param, bool def) const {
396 return GetParamAsBool(param, def);
400 * @brief Returns a string value for the given parameter or returns the default one
401 * @param param Name of the layer parameter
402 * @param def Default value of the parameter if not found
403 * @return A string value
405 std::string GetParamAsString(const char *param, const char *def) const {
406 auto it = params.find(param);
407 if (it == params.end() || it->second.empty()) {
414 * @brief Checks the param presence in the layer
415 * @param param Name of the layer parameter
416 * @return a bool depending param presence
418 bool CheckParamPresence(const char *param) const {
419 auto it = params.find(param);
420 if (it == params.end()) {
427 * @brief Returns a string value for the given parameter.
428 * Throws exception if parameter was not found.
429 * @param param Name of the layer parameter
430 * @return A string value
432 std::string GetParamAsString(const char *param) const {
433 auto it = params.find(param);
434 if (it == params.end()) {
435 THROW_IE_EXCEPTION << "No such parameter name '" << param << "' for layer " << name;
440 std::vector<std::string> GetParamAsStrings(const char *param, std::vector<std::string> def) const {
441 std::string vals = GetParamAsString(param, "");
442 std::vector<std::string> result;
443 std::istringstream stream(vals);
447 while (getline(stream, str, ',')) {
449 result.push_back(str);
451 THROW_IE_EXCEPTION << "Cannot parse parameter " << param << " from IR for layer " << name << ".";
458 * @brief Map of pairs: (parameter name, parameter value)
460 std::map<std::string, std::string> params;
463 * @brief Map of pairs: (name, weights/biases blob)
465 std::map<std::string, Blob::Ptr> blobs;
469 * @brief Alias for CNNLayer object
471 using GenericLayer = class CNNLayer;
474 * @brief This class represents a layer with Weights and/or Biases (e.g. Convolution/Fully Connected, etc.)
476 class WeightableLayer : public CNNLayer {
479 * @brief A default constructor. Constructs a WeightableLayer instance and initiates layer parameters with the given values
480 * @param prms Initial layer parameters
482 explicit WeightableLayer(const LayerParams &prms) : CNNLayer(prms) {}
485 * @brief A pointer to a weights blob
489 * @brief A pointer to a biases blob
494 * @brief Constructs a WeightableLayer instance and initiates layer parameters with the given values
496 using CNNLayer::CNNLayer;
500 * @brief convinenent way to declare property with backward compatibility to 2D members
502 #define DEFINE_PROP(prop_name) \
503 PropertyVector<unsigned int> prop_name;\
504 unsigned int &prop_name##_x = prop_name.at(X_AXIS);\
505 unsigned int &prop_name##_y = prop_name.at(Y_AXIS);\
508 * @brief This class represents a standard 3D Convolution Layer
510 class ConvolutionLayer : public WeightableLayer {
513 * @brief A convolution kernel array [X, Y, Z, ...]
515 DEFINE_PROP(_kernel);
517 * @brief A convolution paddings begin array [X, Y, Z, ...]
519 DEFINE_PROP(_padding);
521 * @brief A convolution paddings end array [X, Y, Z, ...]
523 PropertyVector<unsigned int> _pads_end;
525 * @brief A convolution strides array [X, Y, Z, ...]
527 DEFINE_PROP(_stride);
529 * @brief A convolution dilations array [X, Y, Z, ...]
531 DEFINE_PROP(_dilation);
533 * @brief A number of output feature maps (size) generating the 3'rd output dimension
535 unsigned int _out_depth = 0u;
537 * @brief Number of groups
539 unsigned int _group = 1u;
541 * @brief Auto padding type
543 std::string _auto_pad;
546 * @brief Creates a new ConvolutionLayer instance.
548 explicit ConvolutionLayer(const LayerParams &p) : WeightableLayer(p),
549 _kernel(2, 0u), _padding(2, 0u), _stride(2, 1u), _dilation(2, 1u) {}
551 * @brief assignment operator
553 ConvolutionLayer & operator = (const ConvolutionLayer & that) {
555 WeightableLayer::operator=(that);
556 _kernel = that._kernel;
557 _padding = that._padding;
558 _pads_end = that._pads_end;
559 _stride = that._stride;
560 _dilation = that._dilation;
561 _out_depth = that._out_depth;
562 _group = that._group;
567 * @brief move assignment operator
569 ConvolutionLayer& operator = (ConvolutionLayer &&) = default;
571 * @brief copy constructor
573 ConvolutionLayer(const ConvolutionLayer & that) : WeightableLayer(that) {
577 * @brief move constructor
579 ConvolutionLayer(ConvolutionLayer &&) = default;
583 * @brief This class represents a standard deconvolution layer
585 class DeconvolutionLayer : public ConvolutionLayer {
587 using ConvolutionLayer::ConvolutionLayer;
588 using ConvolutionLayer::operator=;
592 * @brief This class represents a standard pooling layer
594 class PoolingLayer : public CNNLayer {
597 * @brief Pooling kernel array [X, Y, Z, ...]
599 DEFINE_PROP(_kernel);
601 * @brief Pooling paddings begin array [X, Y, Z, ...]
603 DEFINE_PROP(_padding);
605 * @brief Pooling paddings end array [X, Y, Z, ...]
607 PropertyVector<unsigned int> _pads_end;
609 * @brief Pooling strides array [X, Y, Z, ...]
611 DEFINE_PROP(_stride);
615 * @brief Defines available pooling types
626 * @brief A pooling type
628 PoolType _type = MAX;
631 * @brief A flag that indicates if padding is excluded or not
633 bool _exclude_pad = false;
635 * @brief Auto padding type
637 std::string _auto_pad;
640 * @brief Creates a new PoolingLayer instance.
642 explicit PoolingLayer(const LayerParams &p) : CNNLayer(p),
643 _kernel(2, 0u), _padding(2, 0u), _stride(2, 0u) {}
646 * @brief assignment operator
648 PoolingLayer & operator = (const PoolingLayer & that) {
650 CNNLayer::operator=(that);
651 _kernel = that._kernel;
652 _padding = that._padding;
653 _pads_end = that._pads_end;
654 _stride = that._stride;
656 _exclude_pad = that._exclude_pad;
661 * @brief move assignment operator
663 PoolingLayer& operator = (PoolingLayer &&) = default;
666 * @brief copy constructor
668 PoolingLayer(const PoolingLayer & that) : CNNLayer(that) {
673 * @brief move constructor
675 PoolingLayer(PoolingLayer &&) = default;
679 * @brief This class represents a standard binary convolution layer
681 class BinaryConvolutionLayer : public WeightableLayer {
684 * @enum eBinaryConvolutionMode
685 * @brief Defines possible modes of binary convolution operation
687 enum eBinaryConvolutionMode {
692 * @brief Mode of binary convolution operation
694 eBinaryConvolutionMode _mode = xnor_popcount;
697 * @brief A number of input feature maps (size) generating the 3'rd input dimension
699 unsigned int _in_depth = 0u;
702 * @brief A pad value which is used to fill pad area
704 float _pad_value = -1.0f;
707 * @brief A convolution kernel array [X, Y, Z, ...]
709 DEFINE_PROP(_kernel);
711 * @brief A convolution paddings begin array [X, Y, Z, ...]
713 DEFINE_PROP(_padding);
715 * @brief A convolution paddings end array [X, Y, Z, ...]
717 PropertyVector<unsigned int> _pads_end;
719 * @brief A convolution strides array [X, Y, Z, ...]
721 DEFINE_PROP(_stride);
723 * @brief A convolution dilations array [X, Y, Z, ...]
725 DEFINE_PROP(_dilation);
727 * @brief A number of output feature maps (size) generating the 3'rd output dimension
729 unsigned int _out_depth = 0u;
731 * @brief Number of groups
733 unsigned int _group = 1u;
735 * @brief Auto padding type
737 std::string _auto_pad;
740 * @brief Creates a new BinaryConvolutionLayer instance.
742 explicit BinaryConvolutionLayer(const LayerParams &p) : WeightableLayer(p),
743 _kernel(2, 0u), _padding(2, 0u), _stride(2, 1u), _dilation(2, 1u) {}
745 * @brief assignment operator
747 BinaryConvolutionLayer & operator = (const BinaryConvolutionLayer & that) {
749 WeightableLayer::operator=(that);
750 _kernel = that._kernel;
751 _padding = that._padding;
752 _pads_end = that._pads_end;
753 _stride = that._stride;
754 _dilation = that._dilation;
755 _out_depth = that._out_depth;
756 _group = that._group;
758 _in_depth = that._in_depth;
759 _pad_value = that._pad_value;
764 * @brief move assignment operator
766 BinaryConvolutionLayer& operator = (BinaryConvolutionLayer &&) = default;
768 * @brief copy constructor
770 BinaryConvolutionLayer(const BinaryConvolutionLayer & that) : WeightableLayer(that) {
774 * @brief move constructor
776 BinaryConvolutionLayer(BinaryConvolutionLayer &&) = default;
782 * @brief This class represents a fully connected layer
784 class FullyConnectedLayer : public WeightableLayer {
787 * @brief A size of output
789 unsigned int _out_num = 0;
792 * @brief Creates a new FullyConnectedLayer instance and initializes layer parameters with the given values.
794 using WeightableLayer::WeightableLayer;
798 * @brief This class represents concatenation layer
799 * Takes as input several data elements and merges them to one using the supplied axis
801 class ConcatLayer : public CNNLayer {
804 * @brief An axis on which concatenation operation is performed
806 unsigned int _axis = 1;
809 * @brief Creates a new ConcatLayer instance and initializes layer parameters with the given values.
810 * If batch is used, then batch needs to be specified as an input dimension also
811 * In current implementation 1 means channels, 0 - batch
813 using CNNLayer::CNNLayer;
817 * @brief This class represents a layer that evenly splits the input into the supplied outputs
819 class SplitLayer : public CNNLayer {
822 * @brief An axis on which split operation is performed
824 unsigned int _axis = 1;
827 * @brief Creates a new SplitLayer instance.
829 using CNNLayer::CNNLayer;
833 * @brief This class represents a Linear Response Normalization (LRN) Layer
835 class NormLayer : public CNNLayer {
838 * @brief Response size
840 unsigned int _size = 0;
846 * @brief Alpha coefficient
850 * @brief Beta coefficient
854 * @brief Flag to specify normalization across feature maps (true) or across channels
856 bool _isAcrossMaps = false;
859 * @brief Creates a new NormLayer instance.
861 using CNNLayer::CNNLayer;
865 * @brief This class represents standard softmax Layer
867 class SoftMaxLayer : public CNNLayer {
870 * @brief Axis number for a softmax operation
874 * @brief Creates a new SoftMaxLayer instance.
876 using CNNLayer::CNNLayer;
881 * @brief This class represents standard GRN Layer
883 class GRNLayer : public CNNLayer {
886 * @brief A default constructor. Creates a new GRNLayer instance and initializes layer parameters with the given values.
887 * @param prms Initial layer parameters
889 explicit GRNLayer(const LayerParams &prms) : CNNLayer(prms), bias(0.f) {}
892 * @brief Bias for squares sum
899 * @brief This class represents standard MVN Layer
901 class MVNLayer : public CNNLayer {
904 * @brief A default constructor. Creates a new MVNLayer instance and initializes layer parameters with the given values.
905 * @param prms Initial layer parameters
907 explicit MVNLayer(const LayerParams &prms) : CNNLayer(prms), across_channels(0), normalize(1) {}
910 * @brief Indicate that mean value is calculated across channels
915 * @brief Indicate that the result needs to be normalized
921 * @brief This class represents a Rectified Linear activation layer
923 class ReLULayer : public CNNLayer {
926 * @brief Negative slope is used to takle negative inputs instead of setting them to 0
928 float negative_slope = 0.0f;
931 * @brief Creates a new ReLULayer instance.
933 using CNNLayer::CNNLayer;
937 * @brief This class represents a Clamp activation layer
938 * Clamps all tensor elements into the range [min_value, max_value]
940 class ClampLayer : public CNNLayer {
943 * @brief A minimum value
945 float min_value = 0.0f;
948 * @brief A maximum value
950 float max_value = 1.0f;
952 * @brief Creates a new ClampLayer instance.
954 using CNNLayer::CNNLayer;
959 * @brief This class represents a ReLU6 activation layer
960 * Clamps all tensor elements into the range [0, 6.0]
962 class ReLU6Layer : public ClampLayer {
964 explicit ReLU6Layer(const LayerParams &prms) : ClampLayer(prms) {
968 using ClampLayer::ClampLayer;
973 * @brief This class represents an element wise operation layer
975 class EltwiseLayer : public CNNLayer {
979 * @brief Defines possible operations that can be used
982 Sum = 0, Prod, Max, Sub, Min, Div, Squared_diff, Floor_mod, Pow,
983 Equal, Not_equal, Less, Less_equal, Greater, Greater_equal,
984 Logical_AND, Logical_OR, Logical_XOR
988 * @brief A type of the operation to use
990 eOperation _operation = Sum;
993 * @brief A vector of coefficients to scale the operands
995 std::vector<float> coeff;
998 * @brief Creates a new EltwiseLayer instance.
1000 using CNNLayer::CNNLayer;
1004 * @brief This class represents a standard crop layer
1006 class CropLayer : public CNNLayer {
1009 * @brief A vector of dimensions for cropping
1011 std::vector<int> axis;
1013 * @brief A vector of dimensions to be preserved
1015 std::vector<int> dim;
1017 * @brief A vector of offsets for each dimension
1019 std::vector<int> offset;
1022 * @brief Creates a new CropLayer instance.
1024 using CNNLayer::CNNLayer;
1028 * @brief This class represents a standard reshape layer
1030 class ReshapeLayer : public CNNLayer {
1033 * @brief A vector of sizes of the shape
1035 std::vector<int> shape;
1037 * @brief A number of axis to be taken for a reshape
1041 * @brief A number of first axises to be taken for a reshape
1046 * @brief Creates a new ReshapeLayer instance.
1048 using CNNLayer::CNNLayer;
1052 * @brief This class represents a standard Tile Layer
1054 class TileLayer : public CNNLayer {
1057 * @brief An index of the axis to tile
1061 * @brief A number of copies to be made
1066 * @brief Creates a new TileLayer instance.
1068 using CNNLayer::CNNLayer;
1073 * @brief This class represents a Layer which performs Scale and Shift
1075 class ScaleShiftLayer : public WeightableLayer {
1078 * @brief A flag that indicates if the same value is used for all the features. If false, the value is used pixel wise
1080 unsigned int _broadcast = 0;
1083 * @brief Creates a new ScaleShiftLayer instance.
1085 using WeightableLayer::WeightableLayer;
1089 * @brief This class represents TensorIterator layer
1091 class TensorIterator : public CNNLayer {
1095 int from; /**< Index of exteral data from ins/outs fields of CNNLayer */
1096 int to; /**< Index of internal data in iterator body */
1099 int axis; /**< Axis to iterate throught */
1100 int stride; /**< Stride to iterate throught */
1101 int start; /**< Start index of iteration range */
1102 int end; /**< Last index of iteration range */
1103 int part_size; /**< Part size which will be transfered to body subnetwork */
1107 std::vector<DataPtr> inputs;
1108 std::vector<DataPtr> outputs;
1111 std::vector<PortMap> input_port_map;
1112 std::vector<PortMap> output_port_map;
1113 std::vector<PortMap> back_edges;
1117 using CNNLayer::CNNLayer;
1121 * @brief Base class for recurrent cell layers
1123 class RNNCellBase : public WeightableLayer {
1125 using WeightableLayer::WeightableLayer;
1128 * @brief Direct type of recurrent cell (including subtypes)
1129 * Description of particular cell semantics is in LSTMCell, GRUCell, RNNCell.
1132 LSTM, /**< Original LSTM cell */
1133 GRU, /**< Original GRU cell */
1134 RNN, /**< Original RNN cell */
1135 GRU_LBR, /**< GRU cell modification. "Linear before reset" */
1138 /** @copybrief CellType */
1139 CellType cellType = LSTM;
1142 * @brief Size of hidden state data
1144 * In case of batch output state tensor will have shape [N, hidden_size]
1146 int hidden_size = 0;
1149 * @brief Clip data into range [-clip, clip] on input of activations
1151 * clip==0.0f means no clipping
1155 * @brief Activations used inside recurrent cell
1157 * Valid values: sigmoid, tanh, relu
1159 std::vector<std::string> activations;
1162 * @brief Alpha parameters of activations
1164 * Respective to activation list.
1166 std::vector<float> activation_alpha;
1169 * @brief Beta parameters of activations
1171 * Respective to activation list.
1173 std::vector<float> activation_beta;
1177 * @brief LSTM Cell layer
1179 * G - number of gates (=4)
1181 * S - state size (=hidden_size)
1184 * [N,D] Xt - input data
1185 * [N,S] Ht-1 - initial hidden state
1186 * [N,S] Ct-1 - initial cell state
1189 * [N,S] Ht - out hidden state
1190 * [N,S] Ct - out cell state
1193 * - weights [G,S,D+S]
1195 * NB! gates order is FICO {forget, input, candidate, output}
1197 * activations is {_f, _g, _h}
1198 * default: {_f=sigm, _g=tanh, _h=tanh}
1203 * (.) - eltwise mult
1204 * [,] - concatenation
1206 * - ft = _f(Wf*[Ht-1, Xt] + Bf)
1207 * - it = _f(Wi*[Ht-1, Xt] + Bi)
1208 * - ct = _g(Wc*[Ht-1, Xt] + Bc)
1209 * - ot = _f(Wo*[Ht-1, Xt] + Bo)
1210 * - Ct = ft (.) Ct-1 + it (.) ct
1211 * - Ht = ot (.) _h(Ct)
1213 using LSTMCell = RNNCellBase;
1216 * @brief GRU Cell layer
1218 * G - number of gates (=3)
1220 * S - state size (=hidden_size)
1223 * [N,D] Xt - input data
1224 * [N,S] Ht-1 - initial hidden state
1227 * [N,S] Ht - out hidden state
1230 * - weights [G,S,D+S]
1232 * NB! gates order is ZRH {update, reset, output}
1234 * activations is {_f, _g}
1235 * default: {_f=sigm, _g=tanh}
1240 * (.) - eltwise mult
1241 * [,] - concatenation
1243 * - zt = _f(Wz*[Ht-1, Xt] + Bz)
1244 * - rt = _f(Wr*[Ht-1, Xt] + Br)
1245 * - ht = _g(Wh*[rt (.) Ht-1, Xt] + Bh)
1246 * - Ht = (1 - zt) (.) ht + zt (.) Ht-1
1248 using GRUCell = RNNCellBase;
1251 * @brief RNN Cell layer
1253 * G - number of gates (=1)
1255 * S - state size (=hidden_size)
1258 * [N,D] Xt - input data
1259 * [N,S] Ht-1 - initial hidden state
1262 * [N,S] Ht - out hidden state
1265 * - weights [G,S,D+S]
1268 * activations is {_f}
1269 * default: {_f=tanh}
1274 * [,] - concatenation
1276 * - Ht = _f(Wi*[Ht-1, Xt] + Bi)
1278 using RNNCell = RNNCellBase;
1281 * @brief Sequence of recurrent cells
1285 * S - state size (=hidden_size)
1286 * NS - num of state tensors (LSTM=2, GRU/RNN=1)
1287 * ND - num of direction (BDR=2, WFD/BWD=1)
1290 * [N,T,D] Xt - input data
1291 * [ND,N,S] Ht-1 - initial hidden state
1292 * [ND,N,S] Ct-1 - initial cell state // if NS==2
1295 * [ND,N,T,S] Xt - input data
1296 * [ND,N,S] Ht-1 - initial hidden state
1297 * [ND,N,S] Ct-1 - initial cell state // if NS==2
1299 * NB! if axis==0 batch and sequense dimensions are swapped (N <-> T) for input and output tensors
1302 * - weights [ND,G,S,D+S]
1304 * NB! if ND==2 weights are concatenated cell weights [forward_cell_weights, backward_cell_weights]
1307 class RNNSequenceLayer : public RNNCellBase {
1309 using RNNCellBase::RNNCellBase;
1312 * @brief An axis by which iteration is performed
1313 * axis=0 means first input/output data blob dimension is sequence
1314 * axis=1 means first input/output data blob dimension is batch
1316 unsigned int axis = 1;
1319 * @brief Direction of iteration through sequence dimension
1322 FWD, /**< Forward mode. Iterate starts from index 0 with step 1. */
1323 BWD, /**< Backward mode. Iterate starts from last index with step -1. */
1324 BDR /**< Bidirectional mode. First is forward pass, second is backward. */
1327 /** @copybrief Direction */
1328 Direction direction = FWD;
1332 * @brief This class represents a Layer which performs Scale and Shift
1334 class PReLULayer : public WeightableLayer {
1337 * @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
1339 bool _channel_shared;
1343 * @brief A default constructor. Creates a new PReLULayer instance and initializes layer parameters with the given values.
1344 * @param prms Initial layer parameters
1346 explicit PReLULayer(const LayerParams &prms) : WeightableLayer(prms), _channel_shared(false) {}
1350 * @brief This class represents a standard Power Layer
1351 * Formula is: output = (offset + scale * input) ^ power
1353 class PowerLayer : public CNNLayer {
1356 * @brief An exponent value
1360 * @brief A scale factor
1364 * @brief An offset value
1369 * @brief Creates a new PowerLayer instance.
1371 using CNNLayer::CNNLayer;
1375 * @brief This class represents a Batch Normalization Layer
1377 class BatchNormalizationLayer : public WeightableLayer {
1380 * @brief A small value to add to the variance estimate to avoid division by zero
1382 float epsilon = 1e-3f;
1385 * @brief Creates a new BatchNormalizationLayer instance.
1387 using WeightableLayer::WeightableLayer;
1391 * @brief This class represents a general matrix multiplication operation layer
1392 * Formula is: dst := alpha*src1*src2 + beta*src3
1394 class GemmLayer : public CNNLayer {
1397 * @brief A scale factor of src1 matrix
1401 * @brief A scale factor of src3 matrix
1405 * @brief A flag that indicates if the src1 matrix is to be transposed
1407 bool transpose_a = false;
1409 * @brief A flag that indicates if the src2 matrix is to be transposed
1411 bool transpose_b = false;
1413 * @brief Creates a new GemmLayer instance.
1415 using CNNLayer::CNNLayer;
1419 * @brief This class represents a standard Pad layer
1420 * Adds paddings to input tensor
1422 class PadLayer : public CNNLayer {
1426 * @brief Defines possible modes of pad operation
1429 Constant = 0, Edge, Reflect, Symmetric
1433 * @brief Size of padding in the beginning of each axis
1435 PropertyVector<unsigned int> pads_begin;
1437 * @brief Size of padding in the end of each axis
1439 PropertyVector<unsigned int> pads_end;
1441 * @brief Mode of pad operation
1443 ePadMode pad_mode = Constant;
1445 * @brief A pad value which is used for filling in Constant mode
1447 float pad_value = 0.0f;
1449 * @brief Creates a new PadLayer instance.
1451 using CNNLayer::CNNLayer;
1455 * @brief This class represents a standard Gather layer
1456 * Gather slices from Dictionary according to Indexes
1458 class GatherLayer : public CNNLayer {
1461 * @brief The axis in Dictionary to gather Indexes from
1465 * @brief Creates a new GatherLayer instance.
1467 using CNNLayer::CNNLayer;
1471 * @brief This class represents a standard Strided Slice layer
1472 * Strided Slice picks from input tensor according parameters
1474 class StridedSliceLayer : public CNNLayer {
1477 * @brief The begin_mask is a bitmask where bit i being 0 means
1478 * to ignore the begin value and instead use the default value
1480 std::string begin_mask;
1482 * @brief Analogous to begin_mask
1484 std::string end_mask;
1486 * @brief The ellipsis_mask is a bitmask where bit i being 1 means
1487 * the i-th is actually an ellipsis
1489 std::string ellipsis_mask;
1491 * @brief The new_axis_mask_ is a bitmask where bit i being 1 means
1492 * the i-th position creates a new 1 dimension shape
1494 std::string new_axis_mask;
1496 * @brief The shrink_axis_mask is a bitmask where bit i being 1 means
1497 * the i-th position shrinks the dimensionality
1499 std::string shrink_axis_mask;
1502 * @brief Creates a new StridedSliceLayer instance.
1504 using CNNLayer::CNNLayer;
1508 * @brief This class represents a standard Shuffle Channels layer
1509 * Shuffle Channels picks from input tensor according parameters
1511 class ShuffleChannelsLayer : public CNNLayer {
1514 * @brief The axis in tensor to shuffle channels
1519 * @brief The group of output shuffled channels
1521 unsigned int group = 1;
1524 * @brief Creates a new ShuffleChannelsLayer instance.
1526 using CNNLayer::CNNLayer;
1531 * @brief This class represents a standard Depth To Space layer
1532 * Depth To Space picks from input tensor according parameters
1534 class DepthToSpaceLayer : public CNNLayer {
1537 * @brief The group of output shuffled channels
1539 unsigned int block_size = 1;
1542 * @brief Creates a new DepthToSpaceLayer instance.
1544 using CNNLayer::CNNLayer;
1549 * @brief This class represents a standard Space To Depth layer
1550 * Depth To Space picks from input tensor according parameters
1552 class SpaceToDepthLayer : public CNNLayer {
1555 * @brief The group of output Space To Depth
1557 unsigned int block_size = 1;
1560 * @brief Creates a new SpaceToDepthLayer instance.
1562 using CNNLayer::CNNLayer;
1567 * @brief This class represents a standard Reverse Sequence layer
1568 * Reverse Sequence modifies input tensor according parameters
1570 class ReverseSequenceLayer : public CNNLayer {
1573 * @brief The seq_axis dimension in tensor which is partially reversed
1578 * @brief The batch_axis dimension in tensor along which reversal is performed
1583 * @brief Creates a new ReverseSequence instance.
1585 using CNNLayer::CNNLayer;
1590 * @brief This class represents a standard Squeeze layer
1591 * Squeeze modifies input tensor dimensions according parameters
1593 class SqueezeLayer : public CNNLayer {
1596 * @brief Creates a new Squeeze instance.
1598 using CNNLayer::CNNLayer;
1603 * @brief This class represents a standard Unsqueeze layer
1604 * Unsqueeze modifies input tensor dimensions according parameters
1606 class UnsqueezeLayer : public CNNLayer {
1609 * @brief Creates a new Unsqueeze instance.
1611 using CNNLayer::CNNLayer;
1616 * @brief This class represents a standard RangeLayer layer
1617 * RangeLayer modifies input tensor dimensions according parameters
1619 class RangeLayer : public CNNLayer {
1622 * @brief Creates a new RangeLayer instance.
1624 using CNNLayer::CNNLayer;
1629 * @brief This class represents a standard Fill layer
1630 * RFill modifies input tensor according parameters
1632 class FillLayer : public CNNLayer {
1635 * @brief Creates a new Fill instance.
1637 using CNNLayer::CNNLayer;
1642 * @brief This class represents a standard Expand layer
1643 * Expand modifies input tensor dimensions according parameters
1645 class ExpandLayer : public CNNLayer {
1648 * @brief Creates a new Expand instance.
1650 using CNNLayer::CNNLayer;
1654 * @brief This class represents a quantization operation layer
1655 * Element-wise linear quantization of floating point input values into a descrete set of floating point values
1657 class QuantizeLayer : public CNNLayer {
1660 * @brief The number of quantization levels
1665 * @brief Creates a new QuantizeLayer instance.
1667 using CNNLayer::CNNLayer;
1670 } // namespace InferenceEngine