Line data Source code
1 : // SPDX-License-Identifier: Apache-2.0
2 : /**
3 : * Copyright (C) 2020 Jihoon Lee <jhoon.it.lee@samsung.com>
4 : *
5 : * @file layer_impl.h
6 : * @date 21 June 2021
7 : * @brief This is base Optimizer implementation class
8 : * @see https://github.com/nnstreamer/nntrainer
9 : * @author Jihoon Lee <jhoon.it.lee@samsung.com>
10 : * @bug No known bugs except for NYI items
11 : *
12 : * @details LayerImpl forms the base class for all the layer with weights and
13 : * bias parameters. LayerImpl provides parsing of properties like Weight/bias
14 : * initializer and regularizers. LayerImpl also provides checks for double calls
15 : * to finalize function.
16 : *
17 : */
18 : #ifndef __LAYER_IMPL_H__
19 : #define __LAYER_IMPL_H__
20 : #ifdef __cplusplus
21 :
22 : #include <layer_devel.h>
23 : #include <weight.h>
24 :
25 : #include <memory>
26 : #include <tuple>
27 :
28 : namespace nntrainer {
29 :
30 : class InitLayerContext;
31 : class RunLayerContext;
32 : class Exporter;
33 :
34 : namespace props {
35 : class WeightRegularizer;
36 : class WeightRegularizerConstant;
37 : class WeightInitializer;
38 : class WeightDecay;
39 : class BiasDecay;
40 : class BiasInitializer;
41 : class DisableBias;
42 : class Print;
43 : } // namespace props
44 :
45 : /**
46 : * @class An abstract class to ease developing a layer
47 : * @brief An abstract class for all layers
48 : *
49 : */
50 : class LayerImpl : public virtual Layer {
51 :
52 : public:
53 : /**
54 : * @brief Constructor of Layer Class
55 : */
56 : LayerImpl();
57 :
58 : /**
59 : * @brief Destructor of Layer Class
60 : */
61 2086 : virtual ~LayerImpl() = default;
62 :
63 : /**
64 : * @brief Move constructor of LayerImpl Layer.
65 : * @param[in] LayerImpl &&
66 : */
67 : LayerImpl(LayerImpl &&rhs) noexcept = default;
68 :
69 : /**
70 : * @brief Move assignment operator.
71 : * @parma[in] rhs LayerImpl to be moved.
72 : */
73 : LayerImpl &operator=(LayerImpl &&rhs) = default;
74 :
75 : /**
76 : * @copydoc Layer::setProperty(const std::vector<std::string> &values)
77 : */
78 : virtual void setProperty(const std::vector<std::string> &values) override;
79 :
80 : /**
81 : * @copydoc Layer::getProperty(const std::string &key)
82 : */
83 : virtual std::string getProperty(const std::string &key) override;
84 :
85 : /**
86 : * @copydoc Layer::exportTo(Exporter &exporter, const ml::train::ExportMethods
87 : * &methods)
88 : */
89 : virtual void exportTo(Exporter &exporter,
90 : const ml::train::ExportMethods &method) const override;
91 :
92 : protected:
93 : std::unique_ptr<
94 : std::tuple<props::WeightRegularizer, props::WeightRegularizerConstant,
95 : props::WeightInitializer, props::WeightDecay, props::BiasDecay,
96 : props::BiasInitializer, props::DisableBias, props::Print>>
97 : layer_impl_props; /**< layer_impl_props */
98 : };
99 :
100 : } // namespace nntrainer
101 :
102 : #endif /* __cplusplus */
103 : #endif /* __LAYER_IMPL_H__ */
|