-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added basic onnx application example. It loads `add_example.onnx` file and create nntrainer network graph. (network structure is "input + bias = output") Output of this example is as below: ================================================================================ Layer name Layer type Output dimension Input layer ================================================================================ input input 1:1:1:2 -------------------------------------------------------------------------------- bias weight 1:1:1:2 -------------------------------------------------------------------------------- add add 1:1:1:2 input bias ================================================================================ **Self evaluation:** Build test: [x]Passed [ ]Failed [ ]Skipped Run test: [x]Passed [ ]Failed [ ]Skipped Signed-off-by: Seungbaek Hong <[email protected]>
- Loading branch information
Showing
7 changed files
with
157 additions
and
47 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
LOCAL_PATH := $(call my-dir) | ||
|
||
include $(CLEAR_VARS) | ||
|
||
# ndk path | ||
ifndef ANDROID_NDK | ||
$(error ANDROID_NDK is not defined!) | ||
endif | ||
|
||
ifndef NNTRAINER_ROOT | ||
NNTRAINER_ROOT := $(LOCAL_PATH)/../../.. | ||
endif | ||
|
||
ML_API_COMMON_INCLUDES := ${NNTRAINER_ROOT}/ml_api_common/include | ||
NNTRAINER_INCLUDES := $(NNTRAINER_ROOT)/nntrainer \ | ||
$(NNTRAINER_ROOT)/nntrainer/dataset \ | ||
$(NNTRAINER_ROOT)/nntrainer/models \ | ||
$(NNTRAINER_ROOT)/nntrainer/layers \ | ||
$(NNTRAINER_ROOT)/nntrainer/compiler \ | ||
$(NNTRAINER_ROOT)/nntrainer/graph \ | ||
$(NNTRAINER_ROOT)/nntrainer/optimizers \ | ||
$(NNTRAINER_ROOT)/nntrainer/tensor \ | ||
$(NNTRAINER_ROOT)/nntrainer/utils \ | ||
$(NNTRAINER_ROOT)/nntrainer/converter \ | ||
$(NNTRAINER_ROOT)/api \ | ||
$(NNTRAINER_ROOT)/api/ccapi/include \ | ||
${ML_API_COMMON_INCLUDES} | ||
|
||
LOCAL_MODULE := nntrainer | ||
LOCAL_SRC_FILES := $(NNTRAINER_ROOT)/libs/$(TARGET_ARCH_ABI)/libnntrainer.so | ||
|
||
include $(PREBUILT_SHARED_LIBRARY) | ||
|
||
include $(CLEAR_VARS) | ||
|
||
LOCAL_MODULE := ccapi-nntrainer | ||
LOCAL_SRC_FILES := $(NNTRAINER_ROOT)/libs/$(TARGET_ARCH_ABI)/libccapi-nntrainer.so | ||
|
||
include $(PREBUILT_SHARED_LIBRARY) | ||
|
||
include $(CLEAR_VARS) | ||
|
||
LOCAL_ARM_NEON := true | ||
LOCAL_CFLAGS += -std=c++17 -Ofast -mcpu=cortex-a53 -Ilz4-nougat/lib | ||
LOCAL_LDFLAGS += -Llz4-nougat/lib/obj/local/$(TARGET_ARCH_ABI)/ | ||
LOCAL_CXXFLAGS += -std=c++17 -frtti | ||
LOCAL_CFLAGS += -pthread -fexceptions -fopenmp | ||
LOCAL_LDFLAGS += -fexceptions | ||
LOCAL_MODULE_TAGS := optional | ||
LOCAL_ARM_MODE := arm | ||
LOCAL_MODULE := nntrainer_onnx_example | ||
LOCAL_LDLIBS := -llog -landroid -fopenmp | ||
|
||
LOCAL_SRC_FILES := main.cpp | ||
|
||
LOCAL_SHARED_LIBRARIES := nntrainer ccapi-nntrainer | ||
|
||
LOCAL_C_INCLUDES += $(NNTRAINER_INCLUDES) | ||
|
||
include $(BUILD_EXECUTABLE) |
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,4 @@ | ||
APP_ABI := arm64-v8a | ||
APP_STL := c++_shared | ||
APP_PLATFORM := android-29 | ||
APP_SUPPORT_FLEXIBLE_PAGE_SIZES := 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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
pytorch2.3.1:{ | ||
|
||
input | ||
biasoutput/Add"Add | ||
main_graph*BbiasJ�B�?ɉ.�Z | ||
input | ||
|
||
b | ||
output | ||
B |
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,47 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
/** | ||
* Copyright (C) 2025 Seungbaek Hong <[email protected]> | ||
* | ||
* @file main.cpp | ||
* @date 26 Feb 2025 | ||
* @brief onnx example using nntrainer-onnx-api | ||
* @see https://github.com/nnstreamer/nntrainer | ||
* @author Seungbaek Hong <[email protected]> | ||
* @bug No known bugs except for NYI items | ||
*/ | ||
|
||
#include <iostream> | ||
#include <layer.h> | ||
#include <model.h> | ||
#include <nntrainer-api-common.h> | ||
#include <onnx.h> | ||
#include <optimizer.h> | ||
#include <sstream> | ||
#include <util_func.h> | ||
|
||
using ModelHandle = std::unique_ptr<ml::train::Model>; | ||
|
||
int main() { | ||
ModelHandle model = ml::train::loadONNX("../../../../Applications/ONNX/" | ||
"jni/add_example.onnx"); | ||
|
||
model->setProperty({nntrainer::withKey("batch_size", 1)}); | ||
|
||
try { | ||
model->compile(); | ||
} catch (const std::exception &e) { | ||
std::cerr << "Error during compile: " << e.what() << "\n"; | ||
return 1; | ||
} | ||
|
||
try { | ||
model->initialize(); | ||
} catch (const std::exception &e) { | ||
std::cerr << "Error during initialize: " << e.what() << "\n"; | ||
return 1; | ||
} | ||
|
||
model->summarize(std::cout, ML_TRAIN_SUMMARY_MODEL); | ||
|
||
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,21 @@ | ||
onnx_example_sources = [ | ||
'main.cpp', | ||
] | ||
|
||
onnx_example_dependencies = [app_utils_dep, | ||
iniparser_dep, | ||
nntrainer_dep, | ||
nntrainer_ccapi_dep | ||
] | ||
|
||
if get_option('enable-test') | ||
onnx_example_dependencies += [gtest_dep] | ||
endif | ||
|
||
e = executable('nntrainer_onnx_example', | ||
onnx_example_sources, | ||
include_directories: [include_directories('.')], | ||
dependencies: onnx_example_dependencies, | ||
install: get_option('install-app'), | ||
install_dir: application_install_dir | ||
) |
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