[Padding] Add padding2d prop header
authorJihoon Lee <jhoon.it.lee@samsung.com>
Mon, 5 Jul 2021 05:35:27 +0000 (14:35 +0900)
committerJijoong Moon <jijoong.moon@samsung.com>
Wed, 7 Jul 2021 05:01:28 +0000 (14:01 +0900)
This patch adds padding2d property header.

Padding2D prop will be saved as a string and compute the integer when it
is needed

**Self evaluation:**
1. Build test: [X]Passed [ ]Failed [ ]Skipped
2. Run test: [X]Passed [ ]Failed [ ]Skipped

Signed-off-by: Jihoon Lee <jhoon.it.lee@samsung.com>
nntrainer/layers/common_properties.h

index 09dbc0356bcdf2b4e0403723a55a801b9b3b8617..d4812c0ed1fbaec0fb87ab4925ca9afb29f452ec 100644 (file)
@@ -19,6 +19,9 @@
 #define __COMMON_PROPERTIES_H__
 
 namespace nntrainer {
+
+class TensorDim;
+
 namespace props {
 
 /**
@@ -189,6 +192,40 @@ public:
   bool isValid(const ConnectionSpec &v) const override;
 };
 
+/**
+ * @brief Padding2D property, this is used to calculate padding2D
+ * @details Padding2D is saved as a string. Upon calling Padding2D::compute,
+ * returns std::vector<unsigned int> which has computed padding2Ds, below
+ * formats are accepted valid
+ * 1. "same" (case insensitive literal string)
+ * 2. "valid" (case insensitive literal string)
+ * 3. "padding2D_all", eg) padding=1
+ * 4. "padding2D_height, padding2D_width" eg) padding=1,1
+ * 5. "padding2D_top, padding2D_bottom, padding2D_left, padding2D_right" eg)
+ * padding=1,1,1,1
+ *
+ */
+class Padding2D final : public nntrainer::Property<std::string> {
+public:
+  /**
+   * @brief Construct a new Padding2D object
+   *
+   */
+  Padding2D(const std::string &value = "valid") :
+    nntrainer::Property<std::string>(value) {} /**< default value if any */
+  bool isValid(const std::string &v) const override;
+
+  /**
+   * @brief compute actual padding2D from the underlying data
+   *
+   * @param input input dimension
+   * @param kernel kernel dimension
+   * @return std::vector<unsigned int> list of unsigned padding
+   */
+  std::vector<unsigned int> compute(const TensorDim &input,
+                                    const TensorDim &kernel);
+};
+
 } // namespace props
 } // namespace nntrainer