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 conv2d_layer.h
6 : * @date 01 June 2020
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 Convolution Layer Class for Neural Network
11 : *
12 : */
13 :
14 : #ifndef __CONV2D_LAYER_H_
15 : #define __CONV2D_LAYER_H_
16 : #ifdef __cplusplus
17 :
18 : #include <memory.h>
19 :
20 : #include <common_properties.h>
21 : #include <layer_impl.h>
22 :
23 : namespace nntrainer {
24 :
25 : constexpr const unsigned int CONV2D_DIM = 2;
26 :
27 : /**
28 : * @class Convolution 2D Layer
29 : * @brief Convolution 2D Layer
30 : */
31 : class Conv2DLayer : public LayerImpl {
32 : public:
33 : /**
34 : * @brief Constructor of Conv 2D Layer
35 : */
36 : Conv2DLayer(const std::array<unsigned int, CONV2D_DIM * 2> &padding_ = {
37 : 0, 0, 0, 0});
38 :
39 : /**
40 : * @brief Destructor of Conv 2D Layer
41 : */
42 384 : ~Conv2DLayer() = default;
43 :
44 : /**
45 : * @brief Move constructor of Conv 2D Layer.
46 : * @param[in] Conv2dLayer &&
47 : */
48 : Conv2DLayer(Conv2DLayer &&rhs) noexcept = default;
49 :
50 : /**
51 : * @brief Move assignment operator.
52 : * @parma[in] rhs Conv2DLayer to be moved.
53 : */
54 : Conv2DLayer &operator=(Conv2DLayer &&rhs) = default;
55 :
56 : /**
57 : * @copydoc Layer::finalize(InitLayerContext &context)
58 : */
59 : void finalize(InitLayerContext &context) override;
60 :
61 : /**
62 : * @copydoc Layer::forwarding(RunLayerContext &context, bool training)
63 : */
64 : void forwarding(RunLayerContext &context, bool training) override;
65 :
66 : /**
67 : * @copydoc Layer::calcDerivative(RunLayerContext &context)
68 : */
69 : void calcDerivative(RunLayerContext &context) override;
70 :
71 : /**
72 : * @copydoc Layer::calcGradient(RunLayerContext &context)
73 : */
74 : void calcGradient(RunLayerContext &context) override;
75 :
76 : /**
77 : * @copydoc Layer::exportTo(Exporter &exporter, ml::train::ExportMethods
78 : * method)
79 : */
80 : void exportTo(Exporter &exporter,
81 : const ml::train::ExportMethods &method) const override;
82 :
83 : /**
84 : * @copydoc Layer::getType()
85 : */
86 3275 : const std::string getType() const override { return Conv2DLayer::type; };
87 :
88 : /**
89 : * @copydoc Layer::supportBackwarding()
90 : */
91 143 : bool supportBackwarding() const override { return true; }
92 :
93 : using Layer::setProperty;
94 :
95 : /**
96 : * @copydoc Layer::setProperty(const PropertyType type, const std::string
97 : * &value)
98 : */
99 : void setProperty(const std::vector<std::string> &values) override;
100 :
101 : /* TO DO : support keras type of padding */
102 : /* enum class PaddingType { */
103 : /* full = 0, */
104 : /* same = 1, */
105 : /* valid = 2, */
106 : /* unknown = 3, */
107 : /* }; */
108 :
109 : static constexpr const char *type = "conv2d";
110 :
111 : private:
112 : std::array<unsigned int, CONV2D_DIM * 2> padding;
113 : std::tuple<props::FilterSize, std::array<props::KernelSize, CONV2D_DIM>,
114 : std::array<props::Stride, CONV2D_DIM>, props::Padding2D,
115 : std::array<props::Dilation, CONV2D_DIM>>
116 : conv_props;
117 :
118 : std::array<unsigned int, 5> wt_idx; /**< indices of the weights and tensors */
119 : };
120 :
121 : } // namespace nntrainer
122 :
123 : #endif /* __cplusplus */
124 : #endif /* __CONV2D_LAYER_H__ */
|