summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHanjoung Lee <hanjoung.lee@samsung.com>2020-10-13 18:28:21 +0900
committerGitHub <noreply@github.com>2020-10-13 18:28:21 +0900
commit522cce8232ecc8a683be6c6ecc076f803f2426c8 (patch)
tree29469eb950d3c360ac0e1374cf03bd61ba48e16a
parentba51587a0101dbdbc47a3218f97c1256a81528f2 (diff)
downloadnnfw-522cce8232ecc8a683be6c6ecc076f803f2426c8.tar.gz
nnfw-522cce8232ecc8a683be6c6ecc076f803f2426c8.tar.bz2
nnfw-522cce8232ecc8a683be6c6ecc076f803f2426c8.zip
[nnfeapi] Add one-op test for InstanceNorm (#4587)
Add basic one-op test for InstanceNorm. ONE-DCO-1.0-Signed-off-by: Hanjoung Lee <hanjoung.lee@samsung.com>
-rw-r--r--tests/nnfw_api/src/CircleGen.cc8
-rw-r--r--tests/nnfw_api/src/CircleGen.h2
-rw-r--r--tests/nnfw_api/src/one_op_tests/InstanceNorm.cc57
3 files changed, 67 insertions, 0 deletions
diff --git a/tests/nnfw_api/src/CircleGen.cc b/tests/nnfw_api/src/CircleGen.cc
index 211c07d3d..70a5bd325 100644
--- a/tests/nnfw_api/src/CircleGen.cc
+++ b/tests/nnfw_api/src/CircleGen.cc
@@ -264,6 +264,14 @@ uint32_t CircleGen::addOperatorIf(const OperatorParams &params, uint32_t then_su
circle::BuiltinOptions_IfOptions, options);
}
+uint32_t CircleGen::addOperatorInstanceNorm(const OperatorParams &params, float epsilon,
+ circle::ActivationFunctionType actfn)
+{
+ auto options = circle::CreateInstanceNormOptions(_fbb, epsilon, actfn).Union();
+ return addOperatorWithOptions(params, circle::BuiltinOperator_INSTANCE_NORM,
+ circle::BuiltinOptions_InstanceNormOptions, options);
+}
+
uint32_t CircleGen::addOperatorTranspose(const OperatorParams &params)
{
auto options = circle::CreateTransposeOptions(_fbb).Union();
diff --git a/tests/nnfw_api/src/CircleGen.h b/tests/nnfw_api/src/CircleGen.h
index 8ed17a10b..6cc881984 100644
--- a/tests/nnfw_api/src/CircleGen.h
+++ b/tests/nnfw_api/src/CircleGen.h
@@ -148,6 +148,8 @@ public:
uint32_t addOperatorEqual(const OperatorParams &params);
uint32_t addOperatorFullyConnected(const OperatorParams &params);
uint32_t addOperatorIf(const OperatorParams &params, uint32_t then_subg, uint32_t else_subg);
+ uint32_t addOperatorInstanceNorm(const OperatorParams &params, float epsilon,
+ circle::ActivationFunctionType actfn);
uint32_t addOperatorL2Normalization(const OperatorParams &params);
uint32_t addOperatorLeakyRelu(const OperatorParams &params, float alpha);
uint32_t addOperatorLess(const OperatorParams &params);
diff --git a/tests/nnfw_api/src/one_op_tests/InstanceNorm.cc b/tests/nnfw_api/src/one_op_tests/InstanceNorm.cc
new file mode 100644
index 000000000..6569ced21
--- /dev/null
+++ b/tests/nnfw_api/src/one_op_tests/InstanceNorm.cc
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "GenModelTest.h"
+
+TEST_F(GenModelTest, OneOp_InstanceNorm)
+{
+ CircleGen cgen;
+ uint32_t beta_buf = cgen.addBuffer(std::vector<float>{1});
+ uint32_t gamma_buf = cgen.addBuffer(std::vector<float>{2});
+ int beta = cgen.addTensor({{1}, circle::TensorType::TensorType_FLOAT32, beta_buf});
+ int gamma = cgen.addTensor({{1}, circle::TensorType::TensorType_FLOAT32, gamma_buf});
+ int in = cgen.addTensor({{1, 2, 2, 1}, circle::TensorType::TensorType_FLOAT32});
+ int out = cgen.addTensor({{1, 2, 2, 1}, circle::TensorType::TensorType_FLOAT32});
+
+ cgen.addOperatorInstanceNorm({{in, beta, gamma}, {out}}, 0, circle::ActivationFunctionType_NONE);
+ cgen.setInputsAndOutputs({in}, {out});
+
+ _context = std::make_unique<GenModelTestContext>(cgen.finish());
+ _context->addTestCase(uniformTCD<float>({{1, 1, 1, 1}}, {{2, 2, 2, 2}}));
+ _context->setBackends({"acl_cl", "acl_neon"});
+
+ SUCCEED();
+}
+
+TEST_F(GenModelTest, neg_OneOp_InstanceNorm_InvalidActivation)
+{
+ CircleGen cgen;
+ uint32_t beta_buf = cgen.addBuffer(std::vector<float>{1});
+ uint32_t gamma_buf = cgen.addBuffer(std::vector<float>{2});
+ int beta = cgen.addTensor({{1}, circle::TensorType::TensorType_FLOAT32, beta_buf});
+ int gamma = cgen.addTensor({{1}, circle::TensorType::TensorType_FLOAT32, gamma_buf});
+ int in = cgen.addTensor({{1, 2, 2, 1}, circle::TensorType::TensorType_FLOAT32});
+ int out = cgen.addTensor({{1, 2, 2, 1}, circle::TensorType::TensorType_FLOAT32});
+
+ cgen.addOperatorInstanceNorm({{in, beta, gamma}, {out}}, 0,
+ static_cast<circle::ActivationFunctionType>(128) /* Invalid value*/);
+ cgen.setInputsAndOutputs({in}, {out});
+
+ _context = std::make_unique<GenModelTestContext>(cgen.finish());
+ _context->expectFailModelLoad();
+
+ SUCCEED();
+}