1 // SPDX-License-Identifier: Apache-2.0
3 * Copyright (C) 2021 Parichay Kapoor <pk.kapoor@samsung.com>
5 * @file unittest_models_v2.cpp
7 * @brief unittest models for v2 version
8 * @see https://github.com/nnstreamer/nntrainer
9 * @author Parichay Kapoor <pk.kapoor@samsung.com>
10 * @bug No known bugs except for NYI items
13 #include <gtest/gtest.h>
17 #include <ini_wrapper.h>
18 #include <neuralnet.h>
19 #include <nntrainer_test_util.h>
21 #include <models_golden_test.h>
23 using namespace nntrainer;
25 static inline constexpr const int NOT_USED_ = 1;
27 static IniSection nn_base("model", "type = NeuralNetwork");
28 static std::string fc_base = "type = Fully_connected";
29 static std::string red_mean_base = "type = reduce_mean";
30 static IniSection sgd_base("optimizer", "Type = sgd");
31 static IniSection constant_loss("loss", "type = constant_derivative");
33 IniWrapper reduce_mean_last("reduce_mean_last",
35 nn_base + "batch_size=3",
36 sgd_base + "learning_rate=0.1",
37 IniSection("fc_1") + fc_base +
38 "unit=7 | input_shape=1:1:2",
39 IniSection("red_mean") + red_mean_base + "axis=3",
43 static std::unique_ptr<NeuralNetwork> makeMolAttention() {
44 std::unique_ptr<NeuralNetwork> nn(new NeuralNetwork());
45 nn->setProperty({"batch_size=3"});
47 auto outer_graph = makeGraph({
48 {"input", {"name=in3", "input_shape=1:1:5"}},
49 {"input", {"name=in2", "input_shape=1:4:6"}},
50 {"input", {"name=in1", "input_shape=1:1:6"}},
52 {"name=mol", "input_layers=in1,in2,in3", "unit=8", "mol_k=5"}},
53 {"constant_derivative", {"name=loss", "input_layers=mol"}},
56 for (auto &node : outer_graph) {
60 nn->setOptimizer(ml::train::createOptimizer("sgd", {"learning_rate = 0.1"}));
64 INSTANTIATE_TEST_CASE_P(
65 model, nntrainerModelTest,
67 mkModelIniTc(reduce_mean_last, DIM_UNUSED, NOT_USED_,
68 ModelTestOption::COMPARE_V2),
69 mkModelTc_V2(makeMolAttention, "mol_attention",
70 ModelTestOption::COMPARE_V2),
72 [](const testing::TestParamInfo<nntrainerModelTest::ParamType> &info) {
73 return std::get<1>(info.param);