diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 897e78865ac7..14a714fd6ff0 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -72,6 +72,7 @@ ncnn_add_layer_test(Bias) ncnn_add_layer_test(BinaryOp) ncnn_add_layer_test(BNLL) ncnn_add_layer_test(Cast) +ncnn_add_layer_test(Celu) ncnn_add_layer_test(Clip) ncnn_add_layer_test(Concat) ncnn_add_layer_test(Convolution) diff --git a/tests/test_celu.cpp b/tests/test_celu.cpp new file mode 100644 index 000000000000..d7f51f8f24b5 --- /dev/null +++ b/tests/test_celu.cpp @@ -0,0 +1,87 @@ +// Tencent is pleased to support the open source community by making ncnn available. +// +// Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. +// +// Licensed under the BSD 3-Clause License (the "License"); you may not use this file except +// in compliance with the License. You may obtain a copy of the License at +// +// https://opensource.org/licenses/BSD-3-Clause +// +// 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 "layer/celu.h" +#include "testutil.h" + +static int test_celu(const ncnn::Mat& a, float alpha) +{ + ncnn::ParamDict pd; + pd.set(0, alpha); //alpha + + std::vector weights(0); + + int ret = test_layer("CeLU", pd, weights, a); + if (ret != 0) + { + fprintf(stderr, "test_celu failed a.dims=%d a=(%d %d %d %d) slope=%f\n", a.dims, a.w, a.h, a.d, a.c, slope); + } + + return ret; +} + +static int test_celu_0() +{ + return 0 + || test_celu(RandomMat(3, 8, 12, 18), 1.f) + || test_celu(RandomMat(4, 7, 9, 16), 0.1f) + || test_celu(RandomMat(3, 5, 12, 16), 1.f) + || test_celu(RandomMat(9, 6, 7, 14), 0.1f) + || test_celu(RandomMat(5, 6, 9, 10), 1.f) + || test_celu(RandomMat(6, 8, 2, 15), 0.1f); +} + +static int test_celu_1() +{ + return 0 + || test_celu(RandomMat(7, 6, 18), 1.f) + || test_celu(RandomMat(9, 6, 15), 0.1f) + || test_celu(RandomMat(9, 7, 16), 1.f) + || test_celu(RandomMat(6, 10, 15), 0.1f) + || test_celu(RandomMat(2, 7, 11), 1.f) + || test_celu(RandomMat(6, 10, 7), 0.1f); +} + +static int test_celu_2() +{ + return 0 + || test_celu(RandomMat(12, 18), 1.f) + || test_celu(RandomMat(18, 12), 0.1f) + || test_celu(RandomMat(23, 27), 1.f) + || test_celu(RandomMat(18, 16), 0.1f) + || test_celu(RandomMat(18, 16), 1.f) + || test_celu(RandomMat(20, 16), 0.1f); +} + +static int test_celu_3() +{ + return 0 + || test_celu(RandomMat(256), 1.f) + || test_celu(RandomMat(64), 0.1f) + || test_celu(RandomMat(128), 1.f) + || test_celu(RandomMat(96), 0.1f) + || test_celu(RandomMat(128), 1.f) + || test_celu(RandomMat(128), 0.1f); +} + +int main() +{ + SRAND(7767517); + + return 0 + || test_celu_0() + || test_celu_1() + || test_celu_2() + || test_celu_3(); +}