Line data Source code
1 : // SPDX-License-Identifier: Apache-2.0
2 : /**
3 : * Copyright (C) 2021 Parichay Kapoor <pk.kapoor@samsung.com>
4 : *
5 : * @file lstmcell.h
6 : * @date 31 March 2021
7 : * @brief This is LSTMCell Layer Class of Neural Network
8 : * @see https://github.com/nnstreamer/nntrainer
9 : * @author Parichay Kapoor <pk.kapoor@samsung.com>
10 : * @bug No known bugs except for NYI items
11 : *
12 : */
13 :
14 : #ifndef __LSTMCELL_H__
15 : #define __LSTMCELL_H__
16 : #ifdef __cplusplus
17 :
18 : #include <acti_func.h>
19 : #include <common_properties.h>
20 : #include <lstmcell_core.h>
21 :
22 : namespace nntrainer {
23 :
24 : /**
25 : * @class LSTMCellLayer
26 : * @brief LSTMCellLayer
27 : */
28 : class LSTMCellLayer : public LSTMCore {
29 : public:
30 : /**
31 : * @brief Constructor of LSTMCellLayer
32 : */
33 : LSTMCellLayer();
34 :
35 : /**
36 : * @brief Destructor of LSTMCellLayer
37 : */
38 219 : ~LSTMCellLayer() = default;
39 :
40 : /**
41 : * @copydoc Layer::finalize(InitLayerContext &context)
42 : */
43 : void finalize(InitLayerContext &context) override;
44 :
45 : /**
46 : * @copydoc Layer::forwarding(RunLayerContext &context, bool training)
47 : */
48 : void forwarding(RunLayerContext &context, bool training) override;
49 :
50 : /**
51 : * @copydoc Layer::calcDerivative(RunLayerContext &context)
52 : */
53 : void calcDerivative(RunLayerContext &context) override;
54 :
55 : /**
56 : * @copydoc Layer::calcGradient(RunLayerContext &context)
57 : */
58 : void calcGradient(RunLayerContext &context) override;
59 :
60 : /**
61 : * @copydoc Layer::exportTo(Exporter &exporter, ml::train::ExportMethods
62 : * method)
63 : */
64 : void exportTo(Exporter &exporter,
65 : const ml::train::ExportMethods &method) const override;
66 :
67 : /**
68 : * @copydoc Layer::getType()
69 : */
70 639 : const std::string getType() const override { return LSTMCellLayer::type; };
71 :
72 : /**
73 : * @copydoc Layer::supportBackwarding()
74 : */
75 54 : bool supportBackwarding() const override { return true; }
76 :
77 : /**
78 : * @copydoc Layer::setProperty(const PropertyType type, const std::string
79 : * &value)
80 : */
81 : void setProperty(const std::vector<std::string> &values) override;
82 :
83 : /**
84 : * @copydoc Layer::setBatch(RunLayerContext &context, unsigned int batch)
85 : */
86 : void setBatch(RunLayerContext &context, unsigned int batch) override;
87 :
88 : static constexpr const char *type = "lstmcell";
89 :
90 : private:
91 : static constexpr unsigned int NUM_GATE = 4;
92 : enum INOUT_INDEX {
93 : INPUT = 0,
94 : INPUT_HIDDEN_STATE = 1,
95 : INPUT_CELL_STATE = 2,
96 : OUTPUT_HIDDEN_STATE = 0,
97 : OUTPUT_CELL_STATE = 1
98 : };
99 :
100 : /** common properties like Unit, IntegrateBias, HiddenStateActivation and
101 : * RecurrentActivation are in lstmcore_props */
102 :
103 : /**
104 : * DropOutRate: dropout rate
105 : *
106 : * */
107 : std::tuple<props::DropOutRate> lstmcell_props;
108 :
109 : std::array<unsigned int, 7> wt_idx; /**< indices of the weights */
110 : };
111 : } // namespace nntrainer
112 :
113 : #endif /* __cplusplus */
114 : #endif /* __LSTMCELL_H__ */
|