generated from embedded-dev-research/cpp-project-template
-
Notifications
You must be signed in to change notification settings - Fork 5
Add a elementwise layer example #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
chekalexey
wants to merge
8
commits into
embedded-dev-research:main
Choose a base branch
from
chekalexey:Add_a_ElementwiseLayer_example
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
5f1561b
Add layer examples
chekalexey 58a016c
Add layer examples
chekalexey a19ca04
fixed
chekalexey 6f75b73
correction of inclusions
chekalexey 968c92a
Update cmakelist
chekalexey 7c87d3d
Add a ElementwiseLayer Example
chekalexey f30aac7
Fixed Add layer
chekalexey cfa750a
Update CMakeLists
chekalexey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
---|---|---|
@@ -1 +1,2 @@ | ||
add_subdirectory(example) | ||
add_subdirectory(layer_example) |
This file contains hidden or 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 |
---|---|---|
@@ -1 +1 @@ | ||
add_executable(example main.cpp) | ||
add_executable(example main.cpp) |
This file contains hidden or 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,11 @@ | ||
set(ARM_DIR "${CMAKE_SOURCE_DIR}/3rdparty/ComputeLibrary") | ||
|
||
add_executable(ConvolutionLayer ConvolutionLayer.cpp) | ||
add_executable(ElementwiseLayer ElementwiseLayer.cpp) | ||
|
||
include_directories(${ARM_DIR}) | ||
include_directories(${ARM_DIR/include}) | ||
link_directories(${ARM_DIR}/build) | ||
|
||
target_link_libraries(ConvolutionLayer arm_compute) | ||
target_link_libraries(ElementwiseLayer arm_compute) |
This file contains hidden or 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,40 @@ | ||
#include "arm_compute/runtime/NEON/NEFunctions.h" | ||
#include "utils/Utils.h" | ||
|
||
#include <iostream> | ||
using namespace arm_compute; | ||
using namespace utils; | ||
|
||
int main(){ | ||
Tensor input; | ||
Tensor weight; | ||
Tensor bias; | ||
Tensor output; | ||
|
||
const unsigned int N = 1; | ||
const unsigned int Hin = 3; | ||
const unsigned int Win = 3; | ||
const unsigned int Cin = 1; | ||
|
||
const unsigned int Hf = 3; | ||
const unsigned int Wf = 3; | ||
|
||
const unsigned int Hout = Hin - Hf + 1; | ||
const unsigned int Wout = Win - Wf + 1; | ||
const unsigned int Cout = 1; | ||
|
||
input.allocator()->init(TensorInfo(TensorShape(Hin, Win, Cin), 1, DataType::F32)); | ||
weight.allocator()->init(TensorInfo(TensorShape(Hf, Wf, Cin, Cout), 1, DataType::F32)); | ||
output.allocator()->init(TensorInfo(TensorShape(Hout, Wout, Cout), 1, DataType::F32)); | ||
|
||
input.allocator()->allocate(); | ||
weight.allocator()->allocate(); | ||
output.allocator()->allocate(); | ||
|
||
NEConvolutionLayer conv; | ||
conv.configure(&input, &weight, nullptr, &output, PadStrideInfo(1, 1, 0, 0)); | ||
|
||
conv.run(); | ||
|
||
output.print(std::cout); | ||
} |
This file contains hidden or 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,76 @@ | ||
#include "arm_compute/runtime/NEON/NEFunctions.h" | ||
#include "utils/Utils.h" | ||
|
||
#include <iostream> | ||
using namespace arm_compute; | ||
using namespace utils; | ||
|
||
class ElementwiseLayer { | ||
const int input_width = 5; | ||
const int input_height = 5; | ||
|
||
Tensor input1, input2, output; | ||
|
||
public: | ||
void fill() { | ||
input1.allocator()->init(TensorInfo(TensorShape(input_width, input_height, 1), 1, DataType::F32)); | ||
input2.allocator()->init(TensorInfo(TensorShape(input_width, input_height, 1), 1, DataType::F32)); | ||
output.allocator()->init(TensorInfo(TensorShape(input_width, input_height, 1), 1, DataType::F32)); | ||
|
||
input1.allocator()->allocate(); | ||
input2.allocator()->allocate(); | ||
output.allocator()->allocate(); | ||
|
||
fill_random_tensor(input1, 0.f, 1.f); | ||
fill_random_tensor(input2, 0.f, 1.f); | ||
} | ||
|
||
void SquaredDiff() { | ||
NEElementwiseSquaredDiff elementwise; | ||
elementwise.configure(&input1, &input2, &output); | ||
elementwise.run(); | ||
} | ||
|
||
void Division() { | ||
NEElementwiseDivision elementwise; | ||
elementwise.configure(&input1, &input2, &output); | ||
elementwise.run(); | ||
} | ||
|
||
void Addition() { | ||
NEArithmeticAddition add; | ||
add.configure(&input1, &input2, &output); | ||
add.run(); | ||
} | ||
|
||
void Swish() { | ||
NEActivationLayer act; | ||
act.configure(&input1, &input2, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::SWISH)); | ||
act.run(); | ||
} | ||
|
||
void Abs() { | ||
NEActivationLayer act; | ||
act.configure(&input1, &input2, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::ABS)); | ||
act.run(); | ||
} | ||
|
||
void Sigmoid() { | ||
NEActivationLayer act; | ||
act.configure(&input1, &input2, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LOGISTIC)); | ||
act.run(); | ||
} | ||
|
||
void print() { | ||
output.print(std::cout); | ||
} | ||
}; | ||
|
||
int main() { | ||
ElementwiseLayer a; | ||
a.fill(); | ||
a.Addition(); | ||
a.print(); | ||
|
||
return 0; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.