-
Notifications
You must be signed in to change notification settings - Fork 5
Onnx model parser #45
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
base: main
Are you sure you want to change the base?
Changes from all commits
ab5dbf5
9eb09a6
f051a74
be3a143
02b7e35
cdd7ff7
554db69
6977b62
4c948ba
6d9ece4
7ac774e
96ea4d2
0ea25ea
97c7d81
b9b143e
02adfb2
a00ccf7
be78e1d
523e8c6
4961374
b6fa564
6fa0e8e
9de6597
c63661e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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: | ||
|
@@ -82,6 +88,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 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
add_subdirectory(example) | ||
add_subdirectory(frontend) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
cmake_minimum_required(VERSION 3.10) | ||
project(ModelParser) | ||
|
||
find_package(Protobuf REQUIRED) | ||
set(ONNX_GENERATED_DIR "${CMAKE_SOURCE_DIR}/app/frontend/build/generated") | ||
|
||
|
||
set(SETUP_SCRIPT "${CMAKE_SOURCE_DIR}/app/frontend/GetModel.sh") | ||
|
||
set(GENERATED_FILES | ||
"${ONNX_GENERATED_DIR}/onnx.pb.cc" | ||
"${ONNX_GENERATED_DIR}/onnx.pb.h" | ||
"${ONNX_GENERATED_DIR}/yolo11x.onnx" | ||
) | ||
|
||
|
||
add_custom_command( | ||
OUTPUT ${GENERATED_FILES} | ||
COMMAND ${CMAKE_COMMAND} -E make_directory "${ONNX_GENERATED_DIR}" | ||
COMMAND ${CMAKE_COMMAND} -E chdir ${ONNX_GENERATED_DIR} bash ${SETUP_SCRIPT} "${ONNX_GENERATED_DIR}" | ||
WORKING_DIRECTORY "${ONNX_GENERATED_DIR}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We cannot set directory to So it seems we will need to add
|
||
DEPENDS ${SETUP_SCRIPT} | ||
COMMENT "Create directory, generate ONNX-files and get YOLO model" | ||
) | ||
|
||
add_custom_target(generate_output ALL | ||
DEPENDS ${GENERATED_FILES} | ||
) | ||
|
||
set(ONNX_GENERATED_DIR "${CMAKE_SOURCE_DIR}/app/frontend/build/generated") | ||
|
||
set_source_files_properties( | ||
"${ONNX_GENERATED_DIR}/onnx.pb.cc" | ||
"${ONNX_GENERATED_DIR}/onnx.pb.h" | ||
"${ONNX_GENERATED_DIR}/yolo11x.onnx" | ||
PROPERTIES GENERATED TRUE | ||
) | ||
|
||
add_executable(ModelParser | ||
main.cpp | ||
"${ONNX_GENERATED_DIR}/onnx.pb.cc" | ||
) | ||
add_dependencies(ModelParser generate_output) | ||
target_include_directories(ModelParser PRIVATE | ||
"${ONNX_GENERATED_DIR}" | ||
${Protobuf_INCLUDE_DIRS} | ||
) | ||
|
||
target_link_libraries(ModelParser | ||
${Protobuf_LIBRARIES} | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/bash | ||
|
||
protoc --proto_path=3rdparty/onnx/onnx --cpp_out=$1 onnx.proto | ||
yolo export model=$1/yolo11x.pt format=onnx |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#include <fstream> | ||
#include <iostream> | ||
#include <string> | ||
#include <vector> | ||
|
||
#include "./generated/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; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ultralytics >= 8.3.107 |
Uh oh!
There was an error while loading. Please reload this page.