Add absent layers for mobilenet (#1333)
authorEfimov Alexander/AI Tools Lab/./Samsung Electronics <a.efimov@samsung.com>
Wed, 5 Sep 2018 18:02:19 +0000 (21:02 +0300)
committerРоман Михайлович Русяев/AI Tools Lab /SRR/Staff Engineer/삼성전자 <r.rusyaev@samsung.com>
Wed, 5 Sep 2018 18:02:19 +0000 (21:02 +0300)
Add layers in Model IR:
+ batch norm
+ scale
+ dropout

Signed-off-by: Efimov Alexander <a.efimov@samsung.com>
contrib/nnc/include/core/modelIR/operations/batch_norm.h [new file with mode: 0644]
contrib/nnc/include/core/modelIR/operations/dropout_op.h [new file with mode: 0644]
contrib/nnc/include/core/modelIR/operations/scale_op.h [new file with mode: 0644]

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 (file)
index 0000000..d4c107f
--- /dev/null
@@ -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 (file)
index 0000000..621e2e2
--- /dev/null
@@ -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 (file)
index 0000000..8d5a75c
--- /dev/null
@@ -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_