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 cross_entropy_loss_layer.h
6 : * @date 24 June 2021
7 : * @brief This is Cross Entropy Loss 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 __CROSS_ENTROPY_LOSS_LAYER_H__
15 : #define __CROSS_ENTROPY_LOSS_LAYER_H__
16 : #ifdef __cplusplus
17 :
18 : #include <loss_layer.h>
19 : #include <nntrainer_error.h>
20 :
21 : namespace nntrainer {
22 :
23 : /**
24 : * @class CrossEntropyLossLayer
25 : * @brief Cross Entropy Loss Layer
26 : */
27 : class CrossEntropyLossLayer : public LossLayer {
28 : public:
29 : /**
30 : * @brief Constructor of Cross Entropy Loss Layer
31 : */
32 19 : CrossEntropyLossLayer() : LossLayer() {}
33 :
34 : /**
35 : * @brief Destructor of Cross Entropy Loss Layer
36 : */
37 19 : ~CrossEntropyLossLayer() = default;
38 :
39 : /**
40 : * @copydoc Layer::forwarding(RunLayerContext &context, bool training)
41 : */
42 4 : void finalize(InitLayerContext &context) override {
43 : throw exception::not_supported(
44 8 : "Cross Entropy not supported without softmax or sigmoid");
45 : }
46 :
47 : /**
48 : * @copydoc Layer::forwarding(RunLayerContext &context, bool training)
49 : */
50 0 : void forwarding(RunLayerContext &context, bool training) override {
51 : throw exception::not_supported(
52 0 : "Cross Entropy not supported without softmax or sigmoid");
53 : }
54 :
55 : /**
56 : * @copydoc Layer::calcDerivative(RunLayerContext &context)
57 : */
58 0 : void calcDerivative(RunLayerContext &context) override {
59 : throw exception::not_supported(
60 0 : "Cross Entropy not supported without softmax or sigmoid");
61 : }
62 :
63 : /**
64 : * @copydoc Layer::getType()
65 : */
66 22 : const std::string getType() const override {
67 22 : return CrossEntropyLossLayer::type;
68 : };
69 :
70 : static constexpr const char *type = "cross";
71 : };
72 : } // namespace nntrainer
73 :
74 : #endif /* __cplusplus */
75 : #endif /* __CROSS_ENTROPY_LOSS_LAYER_H__ */
|