From fd08fba69cbc474ec8ceb39b9328d9a4f7df981a Mon Sep 17 00:00:00 2001 From: Aleksei Kurpiakov <166383450+AlKurpiakov@users.noreply.github.com> Date: Wed, 11 Dec 2024 18:08:19 +0300 Subject: [PATCH 01/30] Update README.md (add ONNX instuction --- README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/README.md b/README.md index b33148b..f9388fb 100644 --- a/README.md +++ b/README.md @@ -3,3 +3,16 @@ [![CodeQL](https://github.com/embedded-dev-research/itlab_2024/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/embedded-dev-research/itlab_2024/actions/workflows/codeql-analysis.yml) # itlab_2024 + +## __How to build ONNX library__ + + 1. Instal package manager *pip*. + 2. Open directory where you want to save the library. + 3. Open a terminal and execute these commands: +\```txt +git clone +cd onnx +git submodule update --init --recursive +pip install -e . -v +\``` + 4. Open the code editor and run the examples. From 0e1f20747a043c5515f4ba14a20c0dcc95a57252 Mon Sep 17 00:00:00 2001 From: Aleksei Kurpiakov <166383450+AlKurpiakov@users.noreply.github.com> Date: Wed, 11 Dec 2024 18:09:49 +0300 Subject: [PATCH 02/30] Update README.md --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index f9388fb..fe797e0 100644 --- a/README.md +++ b/README.md @@ -6,13 +6,13 @@ ## __How to build ONNX library__ - 1. Instal package manager *pip*. - 2. Open directory where you want to save the library. - 3. Open a terminal and execute these commands: +1. Instal package manager *pip*. +2. Open directory where you want to save the library. +3. Open a terminal and execute these commands: \```txt git clone cd onnx git submodule update --init --recursive pip install -e . -v \``` - 4. Open the code editor and run the examples. +4. Open the code editor and run the examples. From 37ff96b3461f0cfe05d47834ea78e59746fd655b Mon Sep 17 00:00:00 2001 From: Aleksei Kurpiakov <166383450+AlKurpiakov@users.noreply.github.com> Date: Wed, 11 Dec 2024 18:10:15 +0300 Subject: [PATCH 03/30] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index fe797e0..5c5f81e 100644 --- a/README.md +++ b/README.md @@ -9,10 +9,10 @@ 1. Instal package manager *pip*. 2. Open directory where you want to save the library. 3. Open a terminal and execute these commands: -\```txt +/```txt git clone cd onnx git submodule update --init --recursive pip install -e . -v -\``` +/``` 4. Open the code editor and run the examples. From 806a3c3401b2d0ccfae1820e676ede9572ad695b Mon Sep 17 00:00:00 2001 From: Aleksei Kurpiakov <166383450+AlKurpiakov@users.noreply.github.com> Date: Wed, 11 Dec 2024 18:14:57 +0300 Subject: [PATCH 04/30] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5c5f81e..8ade4fd 100644 --- a/README.md +++ b/README.md @@ -9,10 +9,10 @@ 1. Instal package manager *pip*. 2. Open directory where you want to save the library. 3. Open a terminal and execute these commands: -/```txt +``` git clone cd onnx git submodule update --init --recursive pip install -e . -v -/``` +``` 4. Open the code editor and run the examples. From 53bf40554db011c5f8c1c7f73413a9e8a6e689c5 Mon Sep 17 00:00:00 2001 From: Aleksei Kurpiakov <166383450+AlKurpiakov@users.noreply.github.com> Date: Wed, 11 Dec 2024 18:15:16 +0300 Subject: [PATCH 05/30] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8ade4fd..0fe3418 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ 2. Open directory where you want to save the library. 3. Open a terminal and execute these commands: ``` -git clone +git clone https://github.com/onnx/onnx.git cd onnx git submodule update --init --recursive pip install -e . -v From cbc9cdfda0cdb52a16240c92ff4d41b63f6499ea Mon Sep 17 00:00:00 2001 From: Aleksei Kurpiakov <166383450+AlKurpiakov@users.noreply.github.com> Date: Wed, 11 Dec 2024 18:15:44 +0300 Subject: [PATCH 06/30] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0fe3418..f719176 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ 2. Open directory where you want to save the library. 3. Open a terminal and execute these commands: ``` -git clone https://github.com/onnx/onnx.git +git clone [https://github.com/onnx/onnx.git](https://github.com/onnx/onnx.git) cd onnx git submodule update --init --recursive pip install -e . -v From 4b160bae0eea156f35f6306bdcca18faca4ea90c Mon Sep 17 00:00:00 2001 From: Aleksei Kurpiakov <166383450+AlKurpiakov@users.noreply.github.com> Date: Wed, 11 Dec 2024 18:16:27 +0300 Subject: [PATCH 07/30] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f719176..f8a9a6d 100644 --- a/README.md +++ b/README.md @@ -7,10 +7,10 @@ ## __How to build ONNX library__ 1. Instal package manager *pip*. -2. Open directory where you want to save the library. +2. Open directory where you want to save the [library](https://github.com/onnx/onnx.git). 3. Open a terminal and execute these commands: ``` -git clone [https://github.com/onnx/onnx.git](https://github.com/onnx/onnx.git) +git clone https://github.com/onnx/onnx.git cd onnx git submodule update --init --recursive pip install -e . -v From 96ce9fc182da509aeedbacd3b321013fb64b112a Mon Sep 17 00:00:00 2001 From: Aleksei Kurpiakov <166383450+AlKurpiakov@users.noreply.github.com> Date: Wed, 11 Dec 2024 18:19:09 +0300 Subject: [PATCH 08/30] Update README.md --- README.md | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/README.md b/README.md index f8a9a6d..b33148b 100644 --- a/README.md +++ b/README.md @@ -3,16 +3,3 @@ [![CodeQL](https://github.com/embedded-dev-research/itlab_2024/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/embedded-dev-research/itlab_2024/actions/workflows/codeql-analysis.yml) # itlab_2024 - -## __How to build ONNX library__ - -1. Instal package manager *pip*. -2. Open directory where you want to save the [library](https://github.com/onnx/onnx.git). -3. Open a terminal and execute these commands: -``` -git clone https://github.com/onnx/onnx.git -cd onnx -git submodule update --init --recursive -pip install -e . -v -``` -4. Open the code editor and run the examples. From 520427be38f1c71915d80d495ac13dcc2c792271 Mon Sep 17 00:00:00 2001 From: Aleksei Kurpiakov <166383450+AlKurpiakov@users.noreply.github.com> Date: Thu, 20 Feb 2025 23:56:06 +0300 Subject: [PATCH 09/30] Create GetModel.sh --- app/frontend/GetModel.sh | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 app/frontend/GetModel.sh diff --git a/app/frontend/GetModel.sh b/app/frontend/GetModel.sh new file mode 100644 index 0000000..c7a4178 --- /dev/null +++ b/app/frontend/GetModel.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +python3 -m venv env +source env/bin/activate +pip install ultralytics +yolo export model=yolo11x.pt format=onnx +deactivate +rm -rf env +rm -rf yolo11x.pt From 732ee43b981ed9860400278bb6c9aafeb62eae46 Mon Sep 17 00:00:00 2001 From: Aleksei Kurpiakov <166383450+AlKurpiakov@users.noreply.github.com> Date: Fri, 21 Feb 2025 00:28:37 +0300 Subject: [PATCH 10/30] Add files via upload --- app/frontend/CMakeLists.txt | 27 +++++++++++++++++++++++++++ app/frontend/README.md | 32 ++++++++++++++++++++++++++++++++ app/frontend/main.cpp | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 95 insertions(+) create mode 100644 app/frontend/CMakeLists.txt create mode 100644 app/frontend/README.md create mode 100644 app/frontend/main.cpp diff --git a/app/frontend/CMakeLists.txt b/app/frontend/CMakeLists.txt new file mode 100644 index 0000000..ee9c4bd --- /dev/null +++ b/app/frontend/CMakeLists.txt @@ -0,0 +1,27 @@ +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 "") + +set(ONNX_PROTO_SRCS + "/onnx.pb.cc" +) + +set(SRC_FILES + main.cpp + ${ONNX_PROTO_SRCS} +) + +add_executable(ModelParser main.cpp ${ONNX_PROTO_SRCS}) + +target_include_directories(ModelParser : + ${ONNX_GENERATED_DIR} + ${Protobuf_INCLUDE_DIRS} +) + +target_link_libraries(ModelParser ${Protobuf_LIBRARIES}) diff --git a/app/frontend/README.md b/app/frontend/README.md new file mode 100644 index 0000000..d77ecbb --- /dev/null +++ b/app/frontend/README.md @@ -0,0 +1,32 @@ +## __How to run yolov11x model parser__ + +1. Create a directory in which the files necessary for the script will be stored + ``` + mkdir generated + ``` + +2. Generate necessary files + ``` + protoc --proto_path=/onnx --cpp_out= onnx.proto + ``` + +3. Get a network model using Ultralytics CLI + +- Give "executable mode" to the script GetModel.sh + ``` + chmod +x GetModel.sh + ``` +- Run script + ``` + bash GetModel.sh + ``` + +4. In CMakeLists.txt and main.cpp change path to generated files and model file + +5. Build and run the project + ``` + mkdir build && cd build + cmake .. + cmake --build build + ./ModelParser + ``` diff --git a/app/frontend/main.cpp b/app/frontend/main.cpp new file mode 100644 index 0000000..be098f0 --- /dev/null +++ b/app/frontend/main.cpp @@ -0,0 +1,36 @@ +#include +#include +#include +#include +#include "onnx.pb.h" + +int main() { + + std::ifstream model_file("", std::ios::binary); ///write/absolute/path/to/model + + 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 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; +} From e26e9a3d5eca330e70c41beec1db352e771b49c8 Mon Sep 17 00:00:00 2001 From: Aleksei Kurpiakov <166383450+AlKurpiakov@users.noreply.github.com> Date: Fri, 21 Feb 2025 00:39:22 +0300 Subject: [PATCH 11/30] Update main.cpp --- app/frontend/main.cpp | 44 ++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/app/frontend/main.cpp b/app/frontend/main.cpp index be098f0..752d388 100644 --- a/app/frontend/main.cpp +++ b/app/frontend/main.cpp @@ -1,36 +1,38 @@ #include #include -#include #include +#include + #include "onnx.pb.h" int main() { - std::ifstream model_file("", std::ios::binary); ///write/absolute/path/to/model + std::ifstream model_file("", + std::ios::binary); - if (!model_file.is_open()) { - std::cerr << "Failed to open model" << std::endl; - return 1; - } + 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(); + onnx::ModelProto model; + if (!model.ParseFromIstream(&model_file)) { + std::cerr << "Model parsing error" << std::endl; + return 1; + } + model_file.close(); - std::vector Layer; + std::vector 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 (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; - } + for (auto it : Layer){ + std::cout << it << std::endl; + } - return 0; + return 0; } From 38b07cbc8a5fc1db66fd6309c2ba9241fdd0293a Mon Sep 17 00:00:00 2001 From: Aleksei Kurpiakov <166383450+AlKurpiakov@users.noreply.github.com> Date: Fri, 21 Feb 2025 00:42:03 +0300 Subject: [PATCH 12/30] Update main.cpp --- app/frontend/main.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/frontend/main.cpp b/app/frontend/main.cpp index 752d388..5560009 100644 --- a/app/frontend/main.cpp +++ b/app/frontend/main.cpp @@ -7,8 +7,7 @@ int main() { - std::ifstream model_file("", - std::ios::binary); + std::ifstream model_file("", std::ios::binary); if (!model_file.is_open()) { std::cerr << "Failed to open model" << std::endl; @@ -29,7 +28,7 @@ int main() { Layer.emplace_back(node.op_type()); } - for (auto it : Layer){ + for (auto it : Layer) { std::cout << it << std::endl; } From aa881e293f7b15afcfe48249cb1766f9e1226552 Mon Sep 17 00:00:00 2001 From: Aleksei Kurpiakov <166383450+AlKurpiakov@users.noreply.github.com> Date: Fri, 21 Feb 2025 00:43:24 +0300 Subject: [PATCH 13/30] Update main.cpp --- app/frontend/main.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/app/frontend/main.cpp b/app/frontend/main.cpp index 5560009..4a3ccce 100644 --- a/app/frontend/main.cpp +++ b/app/frontend/main.cpp @@ -6,7 +6,6 @@ #include "onnx.pb.h" int main() { - std::ifstream model_file("", std::ios::binary); if (!model_file.is_open()) { From 85dd29d38d64e7660ac390eeba3cd96b83736630 Mon Sep 17 00:00:00 2001 From: Aleksei Kurpiakov <166383450+AlKurpiakov@users.noreply.github.com> Date: Fri, 21 Feb 2025 00:45:08 +0300 Subject: [PATCH 14/30] Update main.cpp --- app/frontend/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/frontend/main.cpp b/app/frontend/main.cpp index 4a3ccce..a75b6b8 100644 --- a/app/frontend/main.cpp +++ b/app/frontend/main.cpp @@ -6,6 +6,7 @@ #include "onnx.pb.h" int main() { + std::ifstream model_file("", std::ios::binary); if (!model_file.is_open()) { @@ -31,6 +32,5 @@ int main() { std::cout << it << std::endl; } - return 0; } From ac2c8814851d3df3a95659ae562074777f620db7 Mon Sep 17 00:00:00 2001 From: Aleksei Kurpiakov <166383450+AlKurpiakov@users.noreply.github.com> Date: Fri, 21 Feb 2025 00:45:59 +0300 Subject: [PATCH 15/30] Update main.cpp --- app/frontend/main.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/frontend/main.cpp b/app/frontend/main.cpp index a75b6b8..7597dc2 100644 --- a/app/frontend/main.cpp +++ b/app/frontend/main.cpp @@ -6,6 +6,7 @@ #include "onnx.pb.h" int main() { + std::ifstream model_file("", std::ios::binary); @@ -13,7 +14,8 @@ int main() { 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; From 36d4602580b7b28d8aa744a801e4696f8aca6249 Mon Sep 17 00:00:00 2001 From: Aleksei Kurpiakov <166383450+AlKurpiakov@users.noreply.github.com> Date: Tue, 25 Feb 2025 19:13:06 +0300 Subject: [PATCH 16/30] Update main.cpp --- app/frontend/main.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/frontend/main.cpp b/app/frontend/main.cpp index 7597dc2..8784867 100644 --- a/app/frontend/main.cpp +++ b/app/frontend/main.cpp @@ -6,8 +6,6 @@ #include "onnx.pb.h" int main() { - - std::ifstream model_file("", std::ios::binary); if (!model_file.is_open()) { @@ -15,7 +13,7 @@ int main() { return 1; } - + onnx::ModelProto model; if (!model.ParseFromIstream(&model_file)) { std::cerr << "Model parsing error" << std::endl; From 4f91c0cb7c32444a2537c65eef2b9ccc594d01a4 Mon Sep 17 00:00:00 2001 From: AlKurpiakov Date: Tue, 4 Mar 2025 11:46:32 +0300 Subject: [PATCH 17/30] update frontend directiry --- .gitmodules | 3 +++ 3rdparty/onnx | 1 + app/frontend/CMakeLists.txt | 10 +++++++--- app/frontend/GetModel.sh | 12 +++++------- app/frontend/README.md | 19 +++---------------- app/frontend/main.cpp | 5 ++++- 6 files changed, 23 insertions(+), 27 deletions(-) create mode 160000 3rdparty/onnx diff --git a/.gitmodules b/.gitmodules index 255b72b..002f14b 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,3 +4,6 @@ [submodule "3rdparty/ComputeLibrary"] path = 3rdparty/ComputeLibrary url = https://github.com/embedded-dev-research/ComputeLibrary +[submodule "3rdparty/onnx"] + path = 3rdparty/onnx + url = https://github.com/onnx/onnx diff --git a/3rdparty/onnx b/3rdparty/onnx new file mode 160000 index 0000000..c403175 --- /dev/null +++ b/3rdparty/onnx @@ -0,0 +1 @@ +Subproject commit c4031757d77487dd59bad35ad7a596413903ef07 diff --git a/app/frontend/CMakeLists.txt b/app/frontend/CMakeLists.txt index ee9c4bd..3c9ad6d 100644 --- a/app/frontend/CMakeLists.txt +++ b/app/frontend/CMakeLists.txt @@ -6,10 +6,10 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) find_package(Protobuf REQUIRED) -set(ONNX_GENERATED_DIR "") +set(ONNX_GENERATED_DIR "./generated") set(ONNX_PROTO_SRCS - "/onnx.pb.cc" + "./generated/onnx.pb.cc" ) set(SRC_FILES @@ -17,9 +17,13 @@ set(SRC_FILES ${ONNX_PROTO_SRCS} ) +configure_file(${CMAKE_SOURCE_DIR}/generated/yolo11x.onnx + ${CMAKE_CURRENT_BINARY_DIR}/generated/yolo11x.onnx + COPYONLY) + add_executable(ModelParser main.cpp ${ONNX_PROTO_SRCS}) -target_include_directories(ModelParser : +target_include_directories(ModelParser PRIVATE ${ONNX_GENERATED_DIR} ${Protobuf_INCLUDE_DIRS} ) diff --git a/app/frontend/GetModel.sh b/app/frontend/GetModel.sh index c7a4178..546243a 100644 --- a/app/frontend/GetModel.sh +++ b/app/frontend/GetModel.sh @@ -1,9 +1,7 @@ #!/bin/bash -python3 -m venv env -source env/bin/activate -pip install ultralytics -yolo export model=yolo11x.pt format=onnx -deactivate -rm -rf env -rm -rf yolo11x.pt +mkdir generated +protoc --proto_path=../../3rdparty/onnx/onnx --cpp_out=./generated onnx.proto +yolo export model=yolo11x.pt format=onnx save_dir=./generated + + diff --git a/app/frontend/README.md b/app/frontend/README.md index d77ecbb..b41db91 100644 --- a/app/frontend/README.md +++ b/app/frontend/README.md @@ -1,16 +1,8 @@ ## __How to run yolov11x model parser__ -1. Create a directory in which the files necessary for the script will be stored - ``` - mkdir generated - ``` - -2. Generate necessary files - ``` - protoc --proto_path=/onnx --cpp_out= onnx.proto - ``` +1. Build the project. -3. Get a network model using Ultralytics CLI +2. Get a network model using Ultralytics CLI - Give "executable mode" to the script GetModel.sh ``` @@ -21,12 +13,7 @@ bash GetModel.sh ``` -4. In CMakeLists.txt and main.cpp change path to generated files and model file - -5. Build and run the project +3. Run the project ``` - mkdir build && cd build - cmake .. - cmake --build build ./ModelParser ``` diff --git a/app/frontend/main.cpp b/app/frontend/main.cpp index 8784867..9ed7263 100644 --- a/app/frontend/main.cpp +++ b/app/frontend/main.cpp @@ -2,12 +2,15 @@ #include #include #include +#include + #include "onnx.pb.h" int main() { - std::ifstream model_file("", std::ios::binary); + 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; From 1f33397883d0031bfc79b577beef2406af3cf1f9 Mon Sep 17 00:00:00 2001 From: Aleksei Kurpiakov <166383450+AlKurpiakov@users.noreply.github.com> Date: Tue, 4 Mar 2025 17:58:31 +0300 Subject: [PATCH 18/30] Update main.cpp --- app/frontend/main.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/frontend/main.cpp b/app/frontend/main.cpp index 9ed7263..6721b35 100644 --- a/app/frontend/main.cpp +++ b/app/frontend/main.cpp @@ -2,7 +2,6 @@ #include #include #include -#include #include "onnx.pb.h" @@ -10,7 +9,7 @@ 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; From 2ade40b335c8515a9cfad1e54e807270111dbe10 Mon Sep 17 00:00:00 2001 From: Aleksei Kurpiakov <166383450+AlKurpiakov@users.noreply.github.com> Date: Tue, 4 Mar 2025 17:59:39 +0300 Subject: [PATCH 19/30] Update main.cpp --- app/frontend/main.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/frontend/main.cpp b/app/frontend/main.cpp index 6721b35..f8cec47 100644 --- a/app/frontend/main.cpp +++ b/app/frontend/main.cpp @@ -7,7 +7,7 @@ #include "onnx.pb.h" int main() { - std::ifstream model_file("generated/yolo11x.onnx", std::ios::binary); + std::ifstream model_file("generated/yolo11x.onnx", std::ios::binary); if (!model_file.is_open()) { @@ -15,7 +15,6 @@ int main() { return 1; } - onnx::ModelProto model; if (!model.ParseFromIstream(&model_file)) { std::cerr << "Model parsing error" << std::endl; From 6986dde225aaf740d3dbb9b988e4326a4fcbe6fb Mon Sep 17 00:00:00 2001 From: Aleksei Kurpiakov <166383450+AlKurpiakov@users.noreply.github.com> Date: Tue, 4 Mar 2025 18:01:33 +0300 Subject: [PATCH 20/30] Update main.cpp --- app/frontend/main.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/frontend/main.cpp b/app/frontend/main.cpp index f8cec47..9d9029c 100644 --- a/app/frontend/main.cpp +++ b/app/frontend/main.cpp @@ -3,13 +3,11 @@ #include #include - #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; From 743eb7ab38a3195f21615cdde27432335d9465ec Mon Sep 17 00:00:00 2001 From: AlKurpiakov Date: Tue, 4 Mar 2025 18:35:26 +0300 Subject: [PATCH 21/30] update frontend directiry --- app/frontend/CMakeLists.txt | 3 +++ app/frontend/main.cpp | 6 +++--- requirements.txt | 1 + 3 files changed, 7 insertions(+), 3 deletions(-) create mode 100644 requirements.txt diff --git a/app/frontend/CMakeLists.txt b/app/frontend/CMakeLists.txt index 3c9ad6d..6f93835 100644 --- a/app/frontend/CMakeLists.txt +++ b/app/frontend/CMakeLists.txt @@ -12,6 +12,8 @@ set(ONNX_PROTO_SRCS "./generated/onnx.pb.cc" ) +set(ONNX_GENERATED_HEADER "./generated/onnx.pb.h") + set(SRC_FILES main.cpp ${ONNX_PROTO_SRCS} @@ -26,6 +28,7 @@ add_executable(ModelParser main.cpp ${ONNX_PROTO_SRCS}) target_include_directories(ModelParser PRIVATE ${ONNX_GENERATED_DIR} ${Protobuf_INCLUDE_DIRS} + ${ONNX_GENERATED_HEADER} ) target_link_libraries(ModelParser ${Protobuf_LIBRARIES}) diff --git a/app/frontend/main.cpp b/app/frontend/main.cpp index 9d9029c..71736c2 100644 --- a/app/frontend/main.cpp +++ b/app/frontend/main.cpp @@ -20,14 +20,14 @@ int main() { } model_file.close(); - std::vector Layer; + std::vector 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()); + layer.emplace_back(node.op_type()); } - for (auto it : Layer) { + for (auto it : layer) { std::cout << it << std::endl; } diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..33bf75c --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +ultralytics>=8.3.32 From b62749d545ccc04a7bb5af4ca65146332894c0de Mon Sep 17 00:00:00 2001 From: AlKurpiakov Date: Tue, 4 Mar 2025 18:53:47 +0300 Subject: [PATCH 22/30] update frontend directiry --- app/frontend/CMakeLists.txt | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/app/frontend/CMakeLists.txt b/app/frontend/CMakeLists.txt index 6f93835..ff6396a 100644 --- a/app/frontend/CMakeLists.txt +++ b/app/frontend/CMakeLists.txt @@ -12,7 +12,9 @@ set(ONNX_PROTO_SRCS "./generated/onnx.pb.cc" ) -set(ONNX_GENERATED_HEADER "./generated/onnx.pb.h") +set(ONNX_GENERATED_HEADER + "./generated/onnx.pb.h" +) set(SRC_FILES main.cpp @@ -28,7 +30,9 @@ add_executable(ModelParser main.cpp ${ONNX_PROTO_SRCS}) target_include_directories(ModelParser PRIVATE ${ONNX_GENERATED_DIR} ${Protobuf_INCLUDE_DIRS} - ${ONNX_GENERATED_HEADER} ) -target_link_libraries(ModelParser ${Protobuf_LIBRARIES}) +target_link_libraries(ModelParser + ${Protobuf_LIBRARIES} + ${ONNX_GENERATED_HEADER} +) From 39215c48e50b4212316c38e55f89d402d347807c Mon Sep 17 00:00:00 2001 From: AlKurpiakov Date: Mon, 10 Mar 2025 19:23:16 +0300 Subject: [PATCH 23/30] include requirements.txt in main.yml --- .github/workflows/main.yml | 8 ++++++++ app/CMakeLists.txt | 1 + 2 files changed, 9 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 31adbd5..dd042cd 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -16,6 +16,8 @@ jobs: - name: Install dependencies run: | sudo apt-get install -y cmake ninja-build ccache scons + python -m pip install --upgrade pip + python -m pip install -r requirements.txt - name: ccache uses: hendrikmuhs/ccache-action@v1.2 with: @@ -38,6 +40,8 @@ jobs: - name: Install dependencies run: | sudo apt-get install -y cmake ninja-build ccache scons + python -m pip install --upgrade pip + python -m pip install -r requirements.txt - name: ccache uses: hendrikmuhs/ccache-action@v1.2 with: @@ -60,6 +64,8 @@ jobs: - name: Install dependencies run: | brew install ninja scons + python -m pip install --upgrade pip + python -m pip install -r requirements.txt - name: ccache uses: hendrikmuhs/ccache-action@v1.2 with: @@ -82,6 +88,8 @@ jobs: - name: Install dependencies run: | sudo apt-get install -y cmake ninja-build ccache gcovr lcov scons + python -m pip install --upgrade pip + python -m pip install -r requirements.txt - uses: actions/checkout@v4 with: submodules: true diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index a5c4dce..4845528 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -1 +1,2 @@ +add_subdirectory(frontend) add_subdirectory(example) From 8cbff3d4b5726357d8a65f02cc5121bfa6d169d9 Mon Sep 17 00:00:00 2001 From: AlKurpiakov Date: Mon, 10 Mar 2025 19:32:45 +0300 Subject: [PATCH 24/30] update requirements.txt --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index 33bf75c..40410fb 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ ultralytics>=8.3.32 +protobuf>=4.25.1 From 57b50528f053a0d7bb2fb504e453e6457e6d4ee5 Mon Sep 17 00:00:00 2001 From: AlKurpiakov Date: Mon, 10 Mar 2025 19:48:04 +0300 Subject: [PATCH 25/30] update requirements.txt and main.yml --- .github/workflows/main.yml | 3 +++ requirements.txt | 1 - 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index dd042cd..d92b12a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -42,6 +42,7 @@ jobs: sudo apt-get install -y cmake ninja-build ccache scons python -m pip install --upgrade pip python -m pip install -r requirements.txt + python -m pip install protobuf==5.29.2 - name: ccache uses: hendrikmuhs/ccache-action@v1.2 with: @@ -66,6 +67,7 @@ jobs: brew install ninja scons python -m pip install --upgrade pip python -m pip install -r requirements.txt + python -m pip install protobuf==5.29.2 - name: ccache uses: hendrikmuhs/ccache-action@v1.2 with: @@ -90,6 +92,7 @@ jobs: sudo apt-get install -y cmake ninja-build ccache gcovr lcov scons python -m pip install --upgrade pip python -m pip install -r requirements.txt + python -m pip install protobuf==5.29.2 - uses: actions/checkout@v4 with: submodules: true diff --git a/requirements.txt b/requirements.txt index 40410fb..33bf75c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1 @@ ultralytics>=8.3.32 -protobuf>=4.25.1 From 589371c4d2d3705697ca7cd95fe9c4ce5689c893 Mon Sep 17 00:00:00 2001 From: AlKurpiakov Date: Tue, 18 Mar 2025 10:26:14 +0300 Subject: [PATCH 26/30] update main.yml --- .github/workflows/main.yml | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d92b12a..c08c9d6 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -16,6 +16,7 @@ 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 @@ -40,9 +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 - python -m pip install protobuf==5.29.2 - name: ccache uses: hendrikmuhs/ccache-action@v1.2 with: @@ -64,10 +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 - python -m pip install protobuf==5.29.2 - name: ccache uses: hendrikmuhs/ccache-action@v1.2 with: @@ -90,9 +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 - python -m pip install protobuf==5.29.2 - uses: actions/checkout@v4 with: submodules: true From d26736e4b79cd56745c439dad283dbeb07fd4177 Mon Sep 17 00:00:00 2001 From: AlKurpiakov Date: Tue, 1 Apr 2025 10:51:59 +0300 Subject: [PATCH 27/30] change CMakeLists.txt (add source file properties) --- app/frontend/CMakeLists.txt | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/app/frontend/CMakeLists.txt b/app/frontend/CMakeLists.txt index ff6396a..4cf6228 100644 --- a/app/frontend/CMakeLists.txt +++ b/app/frontend/CMakeLists.txt @@ -6,14 +6,14 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) find_package(Protobuf REQUIRED) -set(ONNX_GENERATED_DIR "./generated") +set(ONNX_GENERATED_DIR "${CMAKE_SOURCE_DIR}/generated") set(ONNX_PROTO_SRCS - "./generated/onnx.pb.cc" + "${ONNX_GENERATED_DIR}/onnx.pb.cc" ) set(ONNX_GENERATED_HEADER - "./generated/onnx.pb.h" + "${ONNX_GENERATED_DIR}/onnx.pb.h" ) set(SRC_FILES @@ -21,11 +21,22 @@ set(SRC_FILES ${ONNX_PROTO_SRCS} ) -configure_file(${CMAKE_SOURCE_DIR}/generated/yolo11x.onnx - ${CMAKE_CURRENT_BINARY_DIR}/generated/yolo11x.onnx - COPYONLY) +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) -add_executable(ModelParser main.cpp ${ONNX_PROTO_SRCS}) +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} From 1cb055328a945744325aefd2c07c3f9c7609d077 Mon Sep 17 00:00:00 2001 From: Aleksei Kurpiakov <166383450+AlKurpiakov@users.noreply.github.com> Date: Tue, 8 Apr 2025 18:08:13 +0300 Subject: [PATCH 28/30] Create IR.h --- IR/IR.h | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 IR/IR.h diff --git a/IR/IR.h b/IR/IR.h new file mode 100644 index 0000000..d3d8ec3 --- /dev/null +++ b/IR/IR.h @@ -0,0 +1,69 @@ +#include "graph.h" +#include "map" + +class AnyLayer : protected Layer +{ +private: + std::string _name; + std::map _attribute; + std::vector weights; + std::vector bias; + +public: + AnyLayer(); + ~AnyLayer() = default; + + void addNeighbor(Layer* neighbor); + void removeNeighbor(Layer* neighbor); + std::list neighbors_; +}; + + + +enum Model{ONNX, YOLO, OPENCV}; + +class IR +{ +private: + std::string _fileName; + Graph _graph; + Model _model; + + void _ONNX_modelParser(std::string filename); + void _YOLO_modelParser(std::string filename); + void _OPENCV_modelParser(std::string filename); +public: + + IR(std::string filename, Model model): _graph(){ + _fileName = filename; + _model = model; + switch (_model) + { + case Model::ONNX: + _ONNX_modelParser(_fileName); + break; + + case Model::OPENCV: + _OPENCV_modelParser(_fileName); + break; + + case Model::YOLO: + _YOLO_modelParser(_fileName); + break; + + default: + break; + } + } + + void ChangeModelType(Model model){ + _model = model; + } + + void ChangeFile(std::string filename){ + _fileName = filename; + } + + ~IR() = default; +}; + From f6f49c368bc0a4f40be3364440f79a2da52db5d5 Mon Sep 17 00:00:00 2001 From: Aleksei Kurpiakov <166383450+AlKurpiakov@users.noreply.github.com> Date: Tue, 8 Apr 2025 18:09:48 +0300 Subject: [PATCH 29/30] Add files via upload --- IR/IR.cpp | 1 + 1 file changed, 1 insertion(+) create mode 100644 IR/IR.cpp diff --git a/IR/IR.cpp b/IR/IR.cpp new file mode 100644 index 0000000..ee722d6 --- /dev/null +++ b/IR/IR.cpp @@ -0,0 +1 @@ +#include "IR.h" \ No newline at end of file From 28cacbdcf149436dbf5bf9de8038786ecb51c620 Mon Sep 17 00:00:00 2001 From: AlKurpiakov Date: Sat, 12 Apr 2025 21:54:02 +0300 Subject: [PATCH 30/30] update IR.h --- IR/IR.cpp | 35 +++++++++++++++++++++++++- IR/IR.h | 73 ++++++++++++++++++++++++++++++------------------------- 2 files changed, 74 insertions(+), 34 deletions(-) diff --git a/IR/IR.cpp b/IR/IR.cpp index ee722d6..62fef69 100644 --- a/IR/IR.cpp +++ b/IR/IR.cpp @@ -1 +1,34 @@ -#include "IR.h" \ No newline at end of file +#include "IR.h" + +IR::IR(std::string filename, Model model): _graph(){ + _fileName = filename; + _model = model; + switch (_model) + { + case Model::ONNX: + _modelParser = new ONNX_ModelParser(_fileName); + break; + + case Model::OPENCV: + _modelParser = new OPENCV_ModelParser(_fileName); + break; + + // case Model::PYTORCH: + // _modelParser = new OPENCV_ModelParser(_fileName); + // break; + default: + break; + } + + _graph = _modelParser->Parse(); +} + +const bool IR::operator==(const Graph& const) const { + return 0; +} + + +IR::~IR(){ + delete _modelParser; + _modelParser = nullptr; +} \ No newline at end of file diff --git a/IR/IR.h b/IR/IR.h index d3d8ec3..40644ff 100644 --- a/IR/IR.h +++ b/IR/IR.h @@ -18,9 +18,36 @@ class AnyLayer : protected Layer std::list neighbors_; }; +enum Model{ONNX, PYTORCH, OPENCV}; +class ModelParser { +protected: + std::string _fileName; + +public: + explicit ModelParser(std::string filename) : _fileName(std::move(filename)) {} + virtual ~ModelParser() = default; + virtual Graph Parse() = 0; +}; + +class ONNX_ModelParser : public ModelParser { +public: + explicit ONNX_ModelParser(std::string filename) : ModelParser(std::move(filename)) {} + Graph Parse() override; +}; + +class OPENCV_ModelParser : public ModelParser { +public: + explicit OPENCV_ModelParser(std::string filename) : ModelParser(std::move(filename)) {} + Graph Parse() override; +}; + +// class PYTORCH_ModelParser : ModelParser{ +// public: + // explicit OPENCV_ModelParser(std::string filename) : ModelParser(std::move(filename)) {} + // Graph Parse() override; +// }; -enum Model{ONNX, YOLO, OPENCV}; class IR { @@ -28,42 +55,22 @@ class IR std::string _fileName; Graph _graph; Model _model; + ModelParser* _modelParser; - void _ONNX_modelParser(std::string filename); - void _YOLO_modelParser(std::string filename); - void _OPENCV_modelParser(std::string filename); public: - IR(std::string filename, Model model): _graph(){ - _fileName = filename; - _model = model; - switch (_model) - { - case Model::ONNX: - _ONNX_modelParser(_fileName); - break; - - case Model::OPENCV: - _OPENCV_modelParser(_fileName); - break; - - case Model::YOLO: - _YOLO_modelParser(_fileName); - break; - - default: - break; - } - } - - void ChangeModelType(Model model){ - _model = model; - } + IR(std::string filename, Model model); + + const bool operator==(const Graph& graph) const; + + // void ChangeModelType(Model model){ + // _model = model; + // } - void ChangeFile(std::string filename){ - _fileName = filename; - } + // void ChangeFile(std::string filename){ + // _fileName = filename; + // } - ~IR() = default; + ~IR(); };