generated from embedded-dev-research/cpp-project-template
-
Notifications
You must be signed in to change notification settings - Fork 5
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
ONNX model parser #21
Open
AlKurpiakov
wants to merge
30
commits into
embedded-dev-research:main
Choose a base branch
from
AlKurpiakov:ONNX-Model-Parser
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 all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
fd08fba
Update README.md (add ONNX instuction
AlKurpiakov 0e1f207
Update README.md
AlKurpiakov 37ff96b
Update README.md
AlKurpiakov 806a3c3
Update README.md
AlKurpiakov 53bf405
Update README.md
AlKurpiakov cbc9cdf
Update README.md
AlKurpiakov 4b160ba
Update README.md
AlKurpiakov 96ce9fc
Update README.md
AlKurpiakov a9686c2
Merge branch 'embedded-dev-research:main' into ONNX-Model-Parser
AlKurpiakov 520427b
Create GetModel.sh
AlKurpiakov 732ee43
Add files via upload
AlKurpiakov e26e9a3
Update main.cpp
AlKurpiakov 38b07cb
Update main.cpp
AlKurpiakov aa881e2
Update main.cpp
AlKurpiakov 85dd29d
Update main.cpp
AlKurpiakov ac2c881
Update main.cpp
AlKurpiakov 36d4602
Update main.cpp
AlKurpiakov f5dc582
Merge branch 'embedded-dev-research:main' into ONNX-Model-Parser
AlKurpiakov 4f91c0c
update frontend directiry
AlKurpiakov 1f33397
Update main.cpp
AlKurpiakov 2ade40b
Update main.cpp
AlKurpiakov 6986dde
Update main.cpp
AlKurpiakov 743eb7a
update frontend directiry
AlKurpiakov 42a0455
Merge branch 'embedded-dev-research:main' into ONNX-Model-Parser
AlKurpiakov b62749d
update frontend directiry
AlKurpiakov 39215c4
include requirements.txt in main.yml
AlKurpiakov 8cbff3d
update requirements.txt
AlKurpiakov 57b5052
update requirements.txt and main.yml
AlKurpiakov 589371c
update main.yml
AlKurpiakov d26736e
change CMakeLists.txt (add source file properties)
AlKurpiakov 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 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 |
---|---|---|
|
@@ -16,6 +16,9 @@ jobs: | |
- name: Install dependencies | ||
run: | | ||
sudo apt-get install -y cmake ninja-build ccache scons | ||
sudo apt-get install python3-dev libprotobuf-dev protobuf-compiler | ||
python -m pip install --upgrade pip | ||
python -m pip install -r requirements.txt | ||
- name: ccache | ||
uses: hendrikmuhs/[email protected] | ||
with: | ||
|
@@ -38,6 +41,9 @@ jobs: | |
- name: Install dependencies | ||
run: | | ||
sudo apt-get install -y cmake ninja-build ccache scons | ||
sudo apt-get install python3-dev libprotobuf-dev protobuf-compiler | ||
python -m pip install --upgrade pip | ||
python -m pip install -r requirements.txt | ||
- name: ccache | ||
uses: hendrikmuhs/[email protected] | ||
with: | ||
|
@@ -59,7 +65,20 @@ jobs: | |
submodules: recursive | ||
- name: Install dependencies | ||
run: | | ||
brew install ninja scons | ||
brew install ninja scons | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
python -m pip install --upgrade pip | ||
python -m pip install -r requirements.txt | ||
- name: ccache | ||
uses: hendrikmuhs/[email protected] | ||
with: | ||
|
@@ -82,6 +101,9 @@ jobs: | |
- name: Install dependencies | ||
run: | | ||
sudo apt-get install -y cmake ninja-build ccache gcovr lcov scons | ||
sudo apt-get install python3-dev libprotobuf-dev protobuf-compiler | ||
python -m pip install --upgrade pip | ||
python -m pip install -r requirements.txt | ||
- uses: actions/checkout@v4 | ||
with: | ||
submodules: true | ||
|
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
add_subdirectory(frontend) | ||
add_subdirectory(example) |
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,49 @@ | ||
cmake_minimum_required(VERSION 3.10) | ||
project(ModelParser) | ||
|
||
set(CMAKE_CXX_STANDARD 11) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
|
||
find_package(Protobuf REQUIRED) | ||
|
||
set(ONNX_GENERATED_DIR "${CMAKE_SOURCE_DIR}/generated") | ||
|
||
set(ONNX_PROTO_SRCS | ||
"${ONNX_GENERATED_DIR}/onnx.pb.cc" | ||
) | ||
|
||
set(ONNX_GENERATED_HEADER | ||
"${ONNX_GENERATED_DIR}/onnx.pb.h" | ||
) | ||
|
||
set(SRC_FILES | ||
main.cpp | ||
${ONNX_PROTO_SRCS} | ||
) | ||
|
||
set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/generated/onnx.pb.h PROPERTIES GENERATED TRUE) | ||
set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/generated/onnx.pb.cc PROPERTIES GENERATED TRUE) | ||
set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/generated/yolo11x.onnx PROPERTIES GENERATED TRUE) | ||
|
||
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/generated) | ||
|
||
set(YOLO_SRC "${CMAKE_SOURCE_DIR}/generated/yolo11x.onnx") | ||
set(YOLO_DST "${CMAKE_CURRENT_BINARY_DIR}/generated/yolo11x.onnx") | ||
|
||
if(EXISTS "${YOLO_SRC}") | ||
configure_file(${YOLO_SRC} ${YOLO_DST} COPYONLY) | ||
else() | ||
file(WRITE "${YOLO_DST}" "") | ||
endif() | ||
|
||
add_executable(ModelParser ${SRC_FILES}) | ||
|
||
target_include_directories(ModelParser PRIVATE | ||
${ONNX_GENERATED_DIR} | ||
${Protobuf_INCLUDE_DIRS} | ||
) | ||
|
||
target_link_libraries(ModelParser | ||
${Protobuf_LIBRARIES} | ||
${ONNX_GENERATED_HEADER} | ||
) |
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,7 @@ | ||
#!/bin/bash | ||
|
||
mkdir generated | ||
protoc --proto_path=../../3rdparty/onnx/onnx --cpp_out=./generated onnx.proto | ||
yolo export model=yolo11x.pt format=onnx save_dir=./generated | ||
|
||
|
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,19 @@ | ||
## __How to run yolov11x model parser__ | ||
|
||
1. Build the project. | ||
|
||
2. Get a network model using Ultralytics CLI | ||
|
||
- Give "executable mode" to the script GetModel.sh | ||
``` | ||
chmod +x GetModel.sh | ||
``` | ||
- Run script | ||
``` | ||
bash GetModel.sh | ||
``` | ||
|
||
3. Run the project | ||
``` | ||
./ModelParser | ||
``` |
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,35 @@ | ||
#include <fstream> | ||
#include <iostream> | ||
#include <string> | ||
#include <vector> | ||
|
||
#include "onnx.pb.h" | ||
|
||
int main() { | ||
std::ifstream model_file("generated/yolo11x.onnx", std::ios::binary); | ||
|
||
if (!model_file.is_open()) { | ||
std::cerr << "Failed to open model" << std::endl; | ||
return 1; | ||
} | ||
|
||
onnx::ModelProto model; | ||
if (!model.ParseFromIstream(&model_file)) { | ||
std::cerr << "Model parsing error" << std::endl; | ||
return 1; | ||
} | ||
model_file.close(); | ||
|
||
std::vector<std::string> layer; | ||
|
||
for (int i = 0; i < model.graph().node_size(); ++i) { | ||
const onnx::NodeProto& node = model.graph().node(i); | ||
layer.emplace_back(node.op_type()); | ||
} | ||
|
||
for (auto it : layer) { | ||
std::cout << it << std::endl; | ||
} | ||
|
||
return 0; | ||
} |
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 @@ | ||
ultralytics>=8.3.32 |
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.
Please, add
add_subdirectory(frontend)
inapp/CMakeLists.txt