Line data Source code
1 : // SPDX-License-Identifier: Apache-2.0
2 : /**
3 : * Copyright (C) 2020 Parichay Kapoor <pk.kapoor@samsung.com>
4 : *
5 : * @file preprocess_layer.h
6 : * @date 31 December 2020
7 : * @see https://github.com/nnstreamer/nntrainer
8 : * @author Parichay Kapoor <pk.kapoor@samsung.com>
9 : * @bug No known bugs except for NYI items
10 : * @brief This is Preprocess Translate Layer Class for Neural Network
11 : *
12 : */
13 :
14 : #ifndef __PREPROCESS_TRANSLATE_LAYER_H__
15 : #define __PREPROCESS_TRANSLATE_LAYER_H__
16 : #ifdef __cplusplus
17 :
18 : #include <random>
19 :
20 : #if defined(ENABLE_DATA_AUGMENTATION_OPENCV)
21 : #include <opencv2/highgui/highgui.hpp>
22 : #endif
23 :
24 : #include <common_properties.h>
25 : #include <layer_devel.h>
26 :
27 : namespace nntrainer {
28 :
29 : /**
30 : * @class PreprocessTranslate Layer
31 : * @brief Preprocess Translate Layer
32 : */
33 : class PreprocessTranslateLayer : public Layer {
34 : public:
35 : /**
36 : * @brief Constructor of Preprocess Translate Layer
37 : */
38 : PreprocessTranslateLayer();
39 :
40 : /**
41 : * @brief Destructor of Preprocess Translate Layer
42 : */
43 0 : ~PreprocessTranslateLayer() = default;
44 :
45 : /**
46 : * @brief Move constructor of PreprocessLayer.
47 : * @param[in] PreprocessLayer &&
48 : */
49 : PreprocessTranslateLayer(PreprocessTranslateLayer &&rhs) noexcept = default;
50 :
51 : /**
52 : * @brief Move assignment operator.
53 : * @parma[in] rhs PreprocessLayer to be moved.
54 : */
55 : PreprocessTranslateLayer &operator=(PreprocessTranslateLayer &&rhs) = default;
56 :
57 : /**
58 : * @copydoc Layer::finalize(InitLayerContext &context)
59 : */
60 : void finalize(InitLayerContext &context) override;
61 :
62 : /**
63 : * @copydoc Layer::forwarding(RunLayerContext &context, bool training)
64 : */
65 : void forwarding(RunLayerContext &context, bool training) override;
66 :
67 : /**
68 : * @copydoc Layer::calcDerivative(RunLayerContext &context)
69 : */
70 : void calcDerivative(RunLayerContext &context) override;
71 :
72 : /**
73 : * @copydoc bool supportBackwarding() const
74 : */
75 0 : bool supportBackwarding() const override { return false; };
76 :
77 : /**
78 : * @copydoc Layer::exportTo(Exporter &exporter, ml::train::ExportMethods
79 : * method)
80 : */
81 : void exportTo(Exporter &exporter,
82 : const ml::train::ExportMethods &method) const override;
83 :
84 : /**
85 : * @copydoc Layer::getType()
86 : */
87 0 : const std::string getType() const override {
88 0 : return PreprocessTranslateLayer::type;
89 : };
90 :
91 : /**
92 : * @copydoc Layer::setProperty(const std::vector<std::string> &values)
93 : */
94 : void setProperty(const std::vector<std::string> &values) override;
95 :
96 : static constexpr const char *type = "preprocess_translate";
97 :
98 : private:
99 : float epsilon;
100 :
101 : std::mt19937 rng; /**< random number generator */
102 : std::uniform_real_distribution<float>
103 : translate_dist; /**< uniform random distribution */
104 : std::tuple<props::RandomTranslate> preprocess_translate_props;
105 :
106 : #if defined(ENABLE_DATA_AUGMENTATION_OPENCV)
107 : cv::Mat affine_transform_mat;
108 : cv::Mat input_mat, output_mat;
109 : #endif
110 : };
111 :
112 : } // namespace nntrainer
113 :
114 : #endif /* __cplusplus */
115 : #endif /* __PREPROCESS_TRANSLATE_LAYER_H__ */
|