Line data Source code
1 : // SPDX-License-Identifier: Apache-2.0
2 : /**
3 : * Copyright (C) 2020 Jijoong Moon <jijoong.moon@samsung.com>
4 : *
5 : * @file dropout.h
6 : * @date 05 July 2021
7 : * @see https://github.com/nnstreamer/nntrainer
8 : * @author Jijoong Moon <jijoong.moon@samsung.com>
9 : * @bug No known bugs except for NYI items
10 : * @brief This is DropOut Layer Class for Neural Network
11 : *
12 : */
13 :
14 : #ifndef __DROPOUT_H__
15 : #define __DROPOUT_H__
16 : #ifdef __cplusplus
17 :
18 : #include <common_properties.h>
19 : #include <layer_devel.h>
20 :
21 : namespace nntrainer {
22 :
23 : /**
24 : * @class DropOut Layer
25 : * @brief DropOut Layer
26 : */
27 : class DropOutLayer : public Layer {
28 : public:
29 : /**
30 : * @brief Constructor of DropOut Layer
31 : */
32 23 : DropOutLayer(float dropout = 0.0f) :
33 23 : Layer(), dropout_rate(props::DropOutRate(dropout)), epsilon(1e-3f) {}
34 :
35 : /**
36 : * @brief Destructor of DropOut Layer
37 : */
38 46 : ~DropOutLayer() = default;
39 :
40 : /**
41 : * @brief Move constructor of DropOutLayer.
42 : * @param[in] DropOutLayer &&
43 : */
44 : DropOutLayer(DropOutLayer &&rhs) noexcept = default;
45 :
46 : /**
47 : * @brief Move assignment operator.
48 : * @parma[in] rhs DropOutLayer to be moved.
49 : */
50 : DropOutLayer &operator=(DropOutLayer &&rhs) = default;
51 :
52 : /**
53 : * @copydoc Layer::finalize(InitLayerContext &context)
54 : */
55 : void finalize(InitLayerContext &context) override;
56 :
57 : /**
58 : * @copydoc Layer::forwarding(RunLayerContext &context, bool training)
59 : */
60 : void forwarding(RunLayerContext &context, bool training) override;
61 :
62 : /**
63 : * @copydoc Layer::calcDerivative(RunLayerContext &context)
64 : */
65 : void calcDerivative(RunLayerContext &context) override;
66 :
67 : /**
68 : * @copydoc Layer::exportTo(Exporter &exporter, ml::train::ExportMethods
69 : * method)
70 : */
71 0 : void exportTo(Exporter &exporter,
72 0 : const ml::train::ExportMethods &method) const override {}
73 :
74 : /**
75 : * @copydoc Layer::getType()
76 : */
77 56 : const std::string getType() const override { return DropOutLayer::type; };
78 :
79 : /**
80 : * @copydoc Layer::supportBackwarding()
81 : */
82 4 : bool supportBackwarding() const override { return true; }
83 :
84 : /**
85 : * @copydoc Layer::setProperty(const PropertyType type, const std::string
86 : * &value)
87 : */
88 : void setProperty(const std::vector<std::string> &values) override;
89 :
90 : static constexpr const char *type = "dropout";
91 :
92 : private:
93 : std::tuple<props::DropOutRate> dropout_rate;
94 : std::vector<unsigned int> mask_idx;
95 : float epsilon;
96 : };
97 :
98 : } // namespace nntrainer
99 :
100 : #endif /* __cplusplus */
101 : #endif /* __DROPOUT_H__ */
|