1 // SPDX-License-Identifier: Apache-2.0
3 * Copyright (C) 2020 Jihoon Lee <jhoon.it.lee@samsung.com>
5 * @file unittest_layers_fully_connected.cpp
7 * @brief Fully Connected Layer Test
8 * @see https://github.com/nnstreamer/nntrainer
9 * @author Jihoon Lee <jhoon.it.lee@samsung.com>
10 * @author Parichay Kapoor <pk.kapoor@samsung.com>
11 * @bug No known bugs except for NYI items
15 #include <gtest/gtest.h>
18 #include <layers_common_tests.h>
20 auto semantic_fc = LayerSemanticsParamType(
21 nntrainer::createLayer<nntrainer::FullyConnectedLayer>,
22 nntrainer::FullyConnectedLayer::type, {"unit=1"},
23 LayerCreateSetPropertyOptions::AVAILABLE_FROM_APP_CONTEXT, false, 1);
25 GTEST_PARAMETER_TEST(FullyConnected, LayerSemantics,
26 ::testing::Values(semantic_fc));
28 auto fc_basic_plain = LayerGoldenTestParamType(
29 nntrainer::createLayer<nntrainer::FullyConnectedLayer>, {"unit=5"},
30 "3:1:1:10", "fc_plain.nnlayergolden", LayerGoldenTestParamOptions::DEFAULT,
31 "nchw", "fp32", "fp32");
32 auto fc_basic_single_batch = LayerGoldenTestParamType(
33 nntrainer::createLayer<nntrainer::FullyConnectedLayer>, {"unit=4"},
34 "1:1:1:10", "fc_single_batch.nnlayergolden",
35 LayerGoldenTestParamOptions::DEFAULT, "nchw", "fp32", "fp32");
36 auto fc_basic_no_decay = LayerGoldenTestParamType(
37 nntrainer::createLayer<nntrainer::FullyConnectedLayer>,
38 {"unit=5", "weight_decay=0.0", "bias_decay=0.0"}, "3:1:1:10",
39 "fc_plain.nnlayergolden", LayerGoldenTestParamOptions::DEFAULT, "nchw",
42 auto fc_basic_plain_nhwc = LayerGoldenTestParamType(
43 nntrainer::createLayer<nntrainer::FullyConnectedLayer>, {"unit=5"},
44 "3:10:1:1", "fc_plain.nnlayergolden",
45 LayerGoldenTestParamOptions::SKIP_CALC_DERIV |
46 LayerGoldenTestParamOptions::SKIP_CALC_GRAD,
47 "nhwc", "fp32", "fp32");
49 auto fc_basic_single_batch_nhwc = LayerGoldenTestParamType(
50 nntrainer::createLayer<nntrainer::FullyConnectedLayer>, {"unit=4"},
51 "1:10:1:1", "fc_single_batch.nnlayergolden",
52 LayerGoldenTestParamOptions::SKIP_CALC_DERIV |
53 LayerGoldenTestParamOptions::SKIP_CALC_GRAD,
54 "nhwc", "fp32", "fp32");
56 auto fc_basic_no_decay_nhwc = LayerGoldenTestParamType(
57 nntrainer::createLayer<nntrainer::FullyConnectedLayer>,
58 {"unit=5", "weight_decay=0.0", "bias_decay=0.0"}, "3:10:1:1",
59 "fc_plain.nnlayergolden",
60 LayerGoldenTestParamOptions::SKIP_CALC_DERIV |
61 LayerGoldenTestParamOptions::SKIP_CALC_GRAD,
62 "nhwc", "fp32", "fp32");
64 auto fc_basic_plain_fp16fp16 = LayerGoldenTestParamType(
65 nntrainer::createLayer<nntrainer::FullyConnectedLayer>, {"unit=5"},
66 "3:1:1:10", "fc_plain_fp16fp16.nnlayergolden",
67 LayerGoldenTestParamOptions::DEFAULT, "nchw", "fp16", "fp16");
68 auto fc_basic_single_batch_fp16fp16 = LayerGoldenTestParamType(
69 nntrainer::createLayer<nntrainer::FullyConnectedLayer>, {"unit=4"},
70 "1:1:1:10", "fc_single_batch_fp16fp16.nnlayergolden",
71 LayerGoldenTestParamOptions::DEFAULT, "nchw", "fp16", "fp16");
72 auto fc_basic_no_decay_fp16fp16 = LayerGoldenTestParamType(
73 nntrainer::createLayer<nntrainer::FullyConnectedLayer>,
74 {"unit=5", "weight_decay=0.0", "bias_decay=0.0"}, "3:1:1:10",
75 "fc_plain_fp16fp16.nnlayergolden", LayerGoldenTestParamOptions::DEFAULT,
76 "nchw", "fp16", "fp16");
78 GTEST_PARAMETER_TEST(FullyConnected, LayerGoldenTest,
79 ::testing::Values(fc_basic_plain, fc_basic_single_batch,
80 fc_basic_no_decay, fc_basic_plain_nhwc,
81 fc_basic_single_batch_nhwc,
82 fc_basic_no_decay_nhwc,
83 fc_basic_plain_fp16fp16,
84 fc_basic_single_batch_fp16fp16,
85 fc_basic_no_decay_fp16fp16));