From 1c1e1387b54125a77cf5deb8055d2256b977dd14 Mon Sep 17 00:00:00 2001 From: "Efimov Alexander/AI Tools Lab/./Samsung Electronics" Date: Wed, 5 Sep 2018 21:02:19 +0300 Subject: [PATCH] Add absent layers for mobilenet (#1333) Add layers in Model IR: + batch norm + scale + dropout Signed-off-by: Efimov Alexander --- .../include/core/modelIR/operations/batch_norm.h | 60 ++++++++++++++++++++++ .../include/core/modelIR/operations/dropout_op.h | 33 ++++++++++++ .../nnc/include/core/modelIR/operations/scale_op.h | 40 +++++++++++++++ 3 files changed, 133 insertions(+) create mode 100644 contrib/nnc/include/core/modelIR/operations/batch_norm.h create mode 100644 contrib/nnc/include/core/modelIR/operations/dropout_op.h create mode 100644 contrib/nnc/include/core/modelIR/operations/scale_op.h diff --git a/contrib/nnc/include/core/modelIR/operations/batch_norm.h b/contrib/nnc/include/core/modelIR/operations/batch_norm.h new file mode 100644 index 0000000..d4c107f --- /dev/null +++ b/contrib/nnc/include/core/modelIR/operations/batch_norm.h @@ -0,0 +1,60 @@ +#ifndef _NNC_CORE_IR_MODEL_BATCH_NORM_H_ +#define _NNC_CORE_IR_MODEL_BATCH_NORM_H_ + +#include "core/modelIR/operations/operation.h" + +namespace nncc +{ +namespace contrib +{ +namespace core +{ +namespace IR +{ +namespace model +{ +namespace ops +{ + +class BatchNormOp : public OpDescription +{ +public: + explicit BatchNormOp(float movingAvgFraction, float eps, bool spatial) : + OpDescription(1, 1), + _movingAvgFraction(movingAvgFraction), + _eps(eps), + _spatial(spatial) + { + // EMPTY + } + + /** + * @return The epsilon value to use to avoid division by zero. + */ + float getEps() { return _eps; } + + /** + * @return Factor used in computing the running mean and variance. + * e.g., running_mean = running_mean * movingAvgFraction + mean * (1 - movingAvgFraction). + */ + float getMovingAvgFraction() { return _movingAvgFraction; } + + /** + * @return If true, compute the mean and variance across all spatial elements If false, compute the mean and variance per feature. + */ + bool getSpatial() { return _spatial; } + +private: + float _movingAvgFraction; + float _eps; + bool _spatial; +}; + +} // namespace ops +} // namespace model +} // namespace IR +} // namespace core +} // namespace contrib +} // namespace nncc + +#endif //_NNC_CORE_IR_MODEL_BATCH_NORM_H_ diff --git a/contrib/nnc/include/core/modelIR/operations/dropout_op.h b/contrib/nnc/include/core/modelIR/operations/dropout_op.h new file mode 100644 index 0000000..621e2e2 --- /dev/null +++ b/contrib/nnc/include/core/modelIR/operations/dropout_op.h @@ -0,0 +1,33 @@ +#ifndef _NNC_CORE_IR_MODEL_DROPOUT_H_ +#define _NNC_CORE_IR_MODEL_DROPOUT_H_ + +#include "core/modelIR/operations/operation.h" + +namespace nncc { +namespace contrib { +namespace core { +namespace IR { +namespace model { +namespace ops { + +class DropoutOp : public OpDescription { +public: + explicit DropoutOp(float rate) : OpDescription(1, 1), _rate(rate) {} + + /** + * @return The ratio of random dropout + */ + float getRate() const { return _rate; } + +private: + float _rate; +}; + +} // namespace ops +} // namespace model +} // namespace IR +} // namespace core +} // namespace contrib +} // namespace nncc + +#endif //_NNC_CORE_IR_MODEL_DROPOUT_H_ diff --git a/contrib/nnc/include/core/modelIR/operations/scale_op.h b/contrib/nnc/include/core/modelIR/operations/scale_op.h new file mode 100644 index 0000000..8d5a75c --- /dev/null +++ b/contrib/nnc/include/core/modelIR/operations/scale_op.h @@ -0,0 +1,40 @@ +#ifndef _NNC_CORE_IR_MODEL_SCALE_H_ +#define _NNC_CORE_IR_MODEL_SCALE_H_ + +#include "core/modelIR/operations/operation.h" + +namespace nncc +{ +namespace contrib +{ +namespace core +{ +namespace IR +{ +namespace model +{ +namespace ops +{ + +class ScaleOp : public OpDescription +{ +public: + explicit ScaleOp(const TensorVariant &weights) : OpDescription(1, 1), _weights(weights) {} + + /** + * @return The input 1-dimensional scale tensor. + */ + const TensorVariant &getWeights() const { return _weights; } + +private: + TensorVariant _weights; +}; + +} // namespace ops +} // namespace model +} // namespace IR +} // namespace core +} // namespace contrib +} // namespace nncc + +#endif //_NNC_CORE_IR_MODEL_SCALE_H_ -- 2.7.4