Skip to content

Commit

Permalink
add onnx-runtime
Browse files Browse the repository at this point in the history
Former-commit-id: c09e21e
  • Loading branch information
gordinmitya committed Sep 24, 2020
1 parent 6e8acda commit 814fd59
Show file tree
Hide file tree
Showing 105 changed files with 12,835 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ mace/src/main/assets/mace/*.data filter=lfs diff=lfs merge=lfs -text
mace/src/main/assets/mace/*.pb filter=lfs diff=lfs merge=lfs -text
mace/src/main/jniLibs/*/*.so filter=lfs diff=lfs merge=lfs -text
snpe/src/main/assets/snpe/*.dlc filter=lfs diff=lfs merge=lfs -text
onnxruntime/src/main/assets/*.onnx filter=lfs diff=lfs merge=lfs -text
onnxruntime/src/main/jniLibs/*/*.so filter=lfs diff=lfs merge=lfs -text
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,5 @@ dependencies {
implementation project(path: ':opencv')
implementation project(path: ':mace')
implementation project(path: ':snpe')
implementation project(path: ':onnxruntime')
}
14 changes: 8 additions & 6 deletions app/src/main/java/ru/gordinmitya/dnnbenchmark/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import ru.gordinmitya.common.segmentation.DeepLabModel
import ru.gordinmitya.mace.MACEFramework
import ru.gordinmitya.mnn.MNNFramework
import ru.gordinmitya.ncnn.NCNNFramework
import ru.gordinmitya.onnxruntime.ONNXFramework
import ru.gordinmitya.opencv.OpenCVFramework
import ru.gordinmitya.pytorch.PytorchFramework
import ru.gordinmitya.snpe.SNPEFramework
Expand All @@ -25,21 +26,22 @@ class App : Application() {
super.onCreate()
instance = this
frameworks = listOf(
MNNFramework(),
TFLiteFramework(),
ONNXFramework(),
// MNNFramework(),
// TFLiteFramework(),
// MACEFramework(),
// SNPEFramework(),
OpenCVFramework(),
// OpenCVFramework(),
// TFMobileFramework(),
PytorchFramework(),
NCNNFramework()
// PytorchFramework(),
// NCNNFramework()
)
}

@Suppress("SimplifyBooleanWithConstants")
companion object {
val DEBUG = true && BuildConfig.DEBUG
val USE_PROCESS = true || !DEBUG
val USE_PROCESS = false || !DEBUG

lateinit var instance: App
}
Expand Down
1 change: 1 addition & 0 deletions onnxruntime/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
47 changes: 47 additions & 0 deletions onnxruntime/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion rootProject.compileSdkVersion

defaultConfig {
minSdkVersion rootProject.minSdkVersion
targetSdkVersion rootProject.targetSdkVersion
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"

ndk {
abiFilters 'arm64-v8a', 'armeabi-v7a'
}

externalNativeBuild {
cmake {
arguments "-DANDROID_ARM_NEON=TRUE", "-DANDROID_PLATFORM=android-24", "-DANDROID_STL=c++_shared"
}
}
}

externalNativeBuild {
cmake {
version "3.10.2"
path "src/main/cpp/CMakeLists.txt"
}
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

implementation project(path: ':common')
}
Empty file added onnxruntime/consumer-rules.pro
Empty file.
21 changes: 21 additions & 0 deletions onnxruntime/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
5 changes: 5 additions & 0 deletions onnxruntime/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ru.gordinmitya.onnxruntime">

/
</manifest>
File renamed without changes.
29 changes: 29 additions & 0 deletions onnxruntime/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
cmake_minimum_required(VERSION 3.4.1)

set(lib_DIR "${CMAKE_SOURCE_DIR}/../jniLibs")
include_directories(${CMAKE_SOURCE_DIR}/includes)
include_directories(${CMAKE_SOURCE_DIR}/includes/onnxruntime/core/session)

add_library(
onnxcore
SHARED
onnxjni.cpp onnxruntime_inference.cpp
)

add_library(libonnxruntime STATIC IMPORTED)
set_target_properties(
libonnxruntime
PROPERTIES IMPORTED_LOCATION
${lib_DIR}/${ANDROID_ABI}/libonnxruntime.so
)

find_library(log-lib log)
find_library(jnigraphics-lib jnigraphics)

target_link_libraries(
onnxcore
libonnxruntime

${log-lib}
${jnigraphics-lib}
)
105 changes: 105 additions & 0 deletions onnxruntime/src/main/cpp/imageresizer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
//
// Created by rohith on 7/24/18.
//

#ifndef TFLITENATIVE_IMAGERESIZER_H
#define TFLITENATIVE_IMAGERESIZER_H

#include "logs.h"

#include <cstdint>


/**
*center crop and resize the image
*
*/
void cropResizeImage(unsigned char *inputpixel, int w_image, int h_image ,int ch_image, uint8_t* output, int w_network, int h_network)
{
LOGV("in width %d, in height %d",w_image, h_image);

if(h_image >= w_image)//portrait mode
{
LOGE("portrait");
const int skipheight = (h_image - w_image) / 2;
LOGE("skipheight %d", skipheight);

int croped_width = w_image;
int croped_height = w_image;

unsigned char* start_address = inputpixel + (skipheight*croped_width)*ch_image;
uint8_t* rgb_in = output;

for(int y =0;y<h_network; y++)
{

const int in_y = y * (croped_height) / h_network; // 0 = 0x1356/224, 6 = 1x1356/224 ,12 = 2x1356/224, 18 = 3x1356/224.....1349 = 113x1356/224 [total height = 2392 ]


unsigned char* in_row = start_address + in_y * w_image*ch_image;
uint8_t* out_row = rgb_in+ (y*w_network*3); //ou_input + (0*224*3), (1*224*3) ,(2*224*3), (3*224*3) ....(223*224*3)

for(int x=0;x<w_network;x++)
{

const int in_x = (x * croped_width) / w_network; // 0 = 0x1356/224, 6 = 1x1356/224 ,12 = 2x1356/224, 18 = 3x1356/224.....1349 = 113x1356/224 [total width = 1356 ]


unsigned char* inpixel = in_row +in_x*ch_image;

uint8_t* out_pixel = out_row +(x*3);//out_row +(0x3), (1x3) ,(2x3), (3x3), (4x3)...(223x3)

out_pixel[0] = inpixel[0];
out_pixel[1] = inpixel[1];
out_pixel[2] = inpixel[2];

}
}

}
else
{
LOGE("Landscape");

const int skipwidth = (w_image - h_image) / 2;
LOGE("skipheight %d", skipwidth);

int croped_width = h_image;
int croped_height = h_image;


unsigned char* start_address = inputpixel;

uint8_t* rgb_in = output;
for(int y =0;y<h_network; y++)
{

const int in_y = y * (h_image) / h_network;

unsigned char* in_row = start_address + in_y*w_image*ch_image;
uint8_t* out_row = rgb_in+ (y*w_network*3); //ou_input + (0*224*3), (1*224*3) ,(2*224*3), (3*224*3) ....(223*224*3)

for(int x=0;x<w_network;x++)
{


const int in_x = (x * h_image) / w_network;

unsigned char* inpixel = in_row +in_x*ch_image+skipwidth*ch_image;

uint8_t* out_pixel = out_row +(x*3);//out_row +(0x3), (1x3) ,(2x3), (3x3), (4x3)...(223x3)


out_pixel[0] = inpixel[0];
out_pixel[1] = inpixel[1];
out_pixel[2] = inpixel[2];

}
}



}
}

#endif //TFLITENATIVE_IMAGERESIZER_H
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

#pragma once

#include <sstream>
#include <string>
#include <vector>

namespace onnxruntime {
/**
CodeLocation captures information on where in the source code a message came from.
*/
struct CodeLocation {
/**
@param file_path Usually the value of __FILE__
@param line Usually the value of __LINE__
@param func Usually the value of __PRETTY_FUNCTION__ or __FUNCTION__
*/
CodeLocation(const char* file_path, const int line, const char* func)
: file_and_path{file_path}, line_num{line}, function{func} {
}

/**
@param file_path Usually the value of __FILE__
@param line Usually the value of __LINE__
@param func Usually the value of __PRETTY_FUNCTION__ or __FUNCTION__
@param stacktrace Stacktrace from source of message.
*/
CodeLocation(const char* file_path, const int line, const char* func, const std::vector<std::string>& stacktrace)
: file_and_path{file_path}, line_num{line}, function{func}, stacktrace(stacktrace) {
}

std::string FileNoPath() const {
// assuming we always have work to do, so not trying to avoid creating a new string if
// no path was removed.
return file_and_path.substr(file_and_path.find_last_of("/\\") + 1);
}

enum Format {
kFilename,
kFilenameAndPath
};

std::string ToString(Format format = Format::kFilename) const {
std::ostringstream out;
out << (format == Format::kFilename ? FileNoPath() : file_and_path) << ":" << line_num << " " << function;
return out.str();
}

const std::string file_and_path;
const int line_num;
const std::string function;
const std::vector<std::string> stacktrace;
};

} // namespace onnxruntime
Loading

0 comments on commit 814fd59

Please sign in to comment.