-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added a pow operation layer. there was an example of a pow layer in the custom layers, so I modified the key value of the custom pow layer to "custom_pow" in order to avoid duplication of layer key value. **Self evaluation:** 1. Build test: [X]Passed [ ]Failed [ ]Skipped 2. Run test: [X]Passed [ ]Failed [ ]Skipped Signed-off-by: Seungbaek Hong <[email protected]>
- Loading branch information
Showing
19 changed files
with
298 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
/** | ||
* Copyright (C) 2024 SeungBaek Hong <[email protected]> | ||
* | ||
* @file pow_layer.cpp | ||
* @date 20 Nov 2024 | ||
* @see https://github.com/nnstreamer/nntrainer | ||
* @author SeungBaek Hong <[email protected]> | ||
* @bug No known bugs except for NYI items | ||
* @brief This is pow layer class (operation layer) | ||
* | ||
*/ | ||
|
||
#include "common_properties.h" | ||
#include <nntrainer_error.h> | ||
#include <nntrainer_log.h> | ||
#include <node_exporter.h> | ||
#include <pow_layer.h> | ||
#include <util_func.h> | ||
|
||
#include <layer_context.h> | ||
|
||
namespace nntrainer { | ||
|
||
void PowLayer::finalize(InitLayerContext &context) { | ||
context.setOutputDimensions({context.getInputDimensions()[0]}); | ||
} | ||
|
||
void PowLayer::forwarding_operation(const Tensor &input, Tensor &hidden) { | ||
float exp = std::get<props::Exponent>(pow_props).get(); | ||
input.pow(exp, hidden); | ||
} | ||
|
||
void PowLayer::calcDerivative(RunLayerContext &context) { | ||
float exp = std::get<props::Exponent>(pow_props).get(); | ||
context.getOutgoingDerivative(0).copy( | ||
context.getIncomingDerivative(SINGLE_INOUT_IDX) | ||
.multiply(exp) | ||
.multiply(context.getInput(0).pow(exp - 1.0f))); | ||
} | ||
|
||
void PowLayer::setProperty(const std::vector<std::string> &values) { | ||
auto remain_props = loadProperties(values, pow_props); | ||
if (!remain_props.empty()) { | ||
std::string msg = "[PowLayer] Unknown Layer Properties count " + | ||
std::to_string(values.size()); | ||
throw exception::not_supported(msg); | ||
} | ||
} | ||
} /* namespace nntrainer */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
/** | ||
* Copyright (C) 2024 SeungBaek Hong <[email protected]> | ||
* | ||
* @file pow_layer.h | ||
* @date 20 Nov 2024 | ||
* @see https://github.com/nnstreamer/nntrainer | ||
* @author SeungBaek Hong <[email protected]> | ||
* @bug No known bugs except for NYI items | ||
* @brief This is pow layer class (operation layer) | ||
* | ||
*/ | ||
|
||
#ifndef __POW_LAYER_H__ | ||
#define __POW_LAYER_H__ | ||
#ifdef __cplusplus | ||
|
||
#include <common_properties.h> | ||
#include <layer_devel.h> | ||
#include <operation_layer.h> | ||
|
||
namespace nntrainer { | ||
|
||
/** | ||
* @class Pow Layer | ||
* @brief Pow Layer | ||
*/ | ||
class PowLayer : public UnaryOperationLayer { | ||
public: | ||
/** | ||
* @brief Constructor of Pow Layer | ||
*/ | ||
PowLayer() : | ||
UnaryOperationLayer(), | ||
pow_props(props::Print(), props::InPlaceProp(), props::Exponent()), | ||
support_backwarding(true) {} | ||
|
||
/** | ||
* @brief Destructor of Pow Layer | ||
*/ | ||
~PowLayer(){}; | ||
|
||
/** | ||
* @brief Move constructor of Pow Layer. | ||
* @param[in] PowLayer && | ||
*/ | ||
PowLayer(PowLayer &&rhs) noexcept = default; | ||
|
||
/** | ||
* @brief Move assignment operator. | ||
* @parma[in] rhs PowLayer to be moved. | ||
*/ | ||
PowLayer &operator=(PowLayer &&rhs) = default; | ||
|
||
/** | ||
* @copydoc Layer::finalize(InitLayerContext &context) | ||
*/ | ||
void finalize(InitLayerContext &context) final; | ||
|
||
/** | ||
* @brief forwarding operation for pow | ||
* | ||
* @param input input tensor | ||
* @param hidden tensor to store the result value | ||
*/ | ||
void forwarding_operation(const Tensor &input, Tensor &hidden) final; | ||
|
||
/** | ||
* @copydoc Layer::calcDerivative(RunLayerContext &context) | ||
*/ | ||
void calcDerivative(RunLayerContext &context) final; | ||
|
||
/** | ||
* @copydoc bool supportBackwarding() const | ||
*/ | ||
bool supportBackwarding() const final { return support_backwarding; }; | ||
|
||
/** | ||
* @brief Initialize the in-place settings of the layer | ||
* @return InPlaceType | ||
*/ | ||
InPlaceType initializeInPlace() final { | ||
if (std::get<props::InPlaceProp>(pow_props).empty() || | ||
!std::get<props::InPlaceProp>(pow_props).get()) { | ||
is_inplace = false; | ||
support_backwarding = true; | ||
} else { | ||
is_inplace = true; | ||
support_backwarding = false; | ||
} | ||
|
||
if (!supportInPlace()) | ||
return InPlaceType::NONE; | ||
else | ||
return InPlaceType::NON_RESTRICTING; | ||
} | ||
|
||
/** | ||
* @copydoc Layer::exportTo(Exporter &exporter, ml::train::ExportMethods | ||
* method) | ||
*/ | ||
void exportTo(Exporter &exporter, | ||
const ml::train::ExportMethods &method) const final {} | ||
|
||
/** | ||
* @copydoc Layer::setProperty(const std::vector<std::string> &values) | ||
*/ | ||
void setProperty(const std::vector<std::string> &values) final; | ||
|
||
/** | ||
* @copydoc Layer::getType() | ||
*/ | ||
const std::string getType() const final { return PowLayer::type; }; | ||
|
||
std::tuple<props::Print, props::InPlaceProp, props::Exponent> pow_props; | ||
bool support_backwarding; /**< support backwarding */ | ||
|
||
inline static const std::string type = "pow"; | ||
}; | ||
|
||
} // namespace nntrainer | ||
|
||
#endif /* __cplusplus */ | ||
#endif /* __POW_LAYER_H__ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Oops, something went wrong.