-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 89a1c26
Showing
55 changed files
with
3,198 additions
and
0 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,15 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea | ||
/.idea/caches | ||
/.idea/libraries | ||
/.idea/modules.xml | ||
/.idea/workspace.xml | ||
/.idea/navEditor.xml | ||
/.idea/assetWizardSettings.xml | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild | ||
.cxx |
Large diffs are not rendered by default.
Oops, something went wrong.
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,17 @@ | ||
# YOLOv5 NCNN Implementation | ||
|
||
This repo provides C++ implementation of [YOLOv5 model](https://github.com/ultralytics/yolov5) using | ||
Tencent's NCNN framework. | ||
|
||
# Notes | ||
|
||
Currently NCNN does not support Slice operations with steps, therefore I removed the Slice operation | ||
and replaced the input with a downscaled image and stacked it to match the channel number. This | ||
may slightly reduce the accuracy. | ||
|
||
# Credits | ||
|
||
* [YOLOv5 by Ultralytics](https://github.com/ultralytics/yolov5) | ||
* [NCNN by Tencent](https://github.com/tencent/ncnn) | ||
|
||
仅供学习。 |
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 @@ | ||
/build |
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,75 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
android { | ||
compileSdkVersion 29 | ||
buildToolsVersion "29.0.3" | ||
defaultConfig { | ||
applicationId "com.rangi.nanodet" | ||
minSdkVersion 26 | ||
targetSdkVersion 29 | ||
versionCode 1 | ||
versionName "1.0" | ||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | ||
externalNativeBuild { | ||
cmake { | ||
cppFlags "" | ||
arguments '-DANDROID_PLATFORM=android-24', '-DANDROID_STL=c++_static', '-DANDROID_STL=c++_shared' | ||
} | ||
} | ||
|
||
ndk { | ||
moduleName "WztNcnnJniLog" //编译后会生成 .so | ||
ldLibs "log", "z", "m" | ||
abiFilters "armeabi-v7a", "arm64-v8a" // opencv库太大只留需要的 | ||
} | ||
|
||
multiDexEnabled true | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
externalNativeBuild { | ||
cmake { | ||
path "src/main/cpp/CMakeLists.txt" | ||
version "3.10.2" | ||
} | ||
} | ||
sourceSets { | ||
main { | ||
jniLibs.srcDirs = ['libs'] | ||
} | ||
} | ||
|
||
repositories { | ||
flatDir { | ||
dirs 'libs' | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation fileTree(dir: 'libs', include: ['*.jar']) | ||
implementation 'androidx.appcompat:appcompat:1.1.0' | ||
implementation 'androidx.constraintlayout:constraintlayout:1.1.3' | ||
testImplementation 'junit:junit:4.12' | ||
androidTestImplementation 'androidx.test.ext:junit:1.1.1' | ||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' | ||
|
||
// Use the most recent version of CameraX, currently that is alpha04 | ||
def camerax_version = "1.0.0-alpha05" | ||
//noinspection GradleDependency | ||
implementation "androidx.camera:camera-core:${camerax_version}" | ||
//noinspection GradleDependency | ||
implementation "androidx.camera:camera-camera2:${camerax_version}" | ||
|
||
implementation 'com.android.support:multidex:1.0.3' | ||
// crash | ||
implementation 'com.zxy.android:recovery:1.0.0' | ||
// photoview | ||
implementation 'com.github.chrisbanes:PhotoView:2.3.0' | ||
// implementation 'com.bm.photoview:library:1.4.1' | ||
|
||
} |
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 @@ | ||
# 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 |
27 changes: 27 additions & 0 deletions
27
demo_android_ncnn/app/src/androidTest/java/com/rangi/nanodet/ExampleInstrumentedTest.java
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,27 @@ | ||
package com.rangi.nanodet; | ||
|
||
import android.content.Context; | ||
|
||
import androidx.test.platform.app.InstrumentationRegistry; | ||
import androidx.test.ext.junit.runners.AndroidJUnit4; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
/** | ||
* Instrumented test, which will execute on an Android device. | ||
* | ||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a> | ||
*/ | ||
@RunWith(AndroidJUnit4.class) | ||
public class ExampleInstrumentedTest { | ||
@Test | ||
public void useAppContext() { | ||
// Context of the app under test. | ||
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); | ||
|
||
assertEquals("gd.hq.yolov5", appContext.getPackageName()); | ||
} | ||
} |
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,30 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.rangi.nanodet"> | ||
|
||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> | ||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> | ||
<uses-permission android:name="android.permission.CAMERA" /> | ||
|
||
<application | ||
android:name="com.rangi.nanodet.NcnnApp" | ||
android:allowBackup="true" | ||
android:icon="@drawable/ncnn_icon" | ||
android:label="@string/app_name" | ||
android:roundIcon="@mipmap/ic_launcher_round" | ||
android:supportsRtl="true" | ||
android:requestLegacyExternalStorage="true" | ||
android:theme="@style/AppTheme"> | ||
<activity android:name="com.rangi.nanodet.WelcomeActivity"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
<activity | ||
android:name="com.rangi.nanodet.MainActivity" | ||
android:theme="@style/AppNoTitleTheme" /> | ||
</application> | ||
|
||
</manifest> |
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,102 @@ | ||
# For more information about using CMake with Android Studio, read the | ||
# documentation: https://d.android.com/studio/projects/add-native-code.html | ||
|
||
# Sets the minimum version of CMake required to build the native library. | ||
|
||
cmake_minimum_required(VERSION 3.4.1) | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp") | ||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fopenmp") | ||
if(DEFINED ANDROID_NDK_MAJOR AND ${ANDROID_NDK_MAJOR} GREATER 20) | ||
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-openmp") | ||
endif() | ||
# Creates and names a library, sets it as either STATIC | ||
# or SHARED, and provides the relative paths to its source code. | ||
# You can define multiple libraries, and CMake builds them for you. | ||
# Gradle automatically packages shared libraries with your APK. | ||
|
||
add_library( # Sets the name of the library. | ||
yolov5 | ||
|
||
# Sets the library as a shared library. | ||
SHARED | ||
|
||
# Provides a relative path to your source file(s). | ||
jni_interface.cpp | ||
YoloV5.cpp | ||
YoloV4.cpp | ||
NanoDet.cpp | ||
) | ||
|
||
include_directories( | ||
ncnnvulkan/include | ||
# ocr | ||
) | ||
# Searches for a specified prebuilt library and stores the path as a | ||
# variable. Because CMake includes system libraries in the search path by | ||
# default, you only need to specify the name of the public NDK library | ||
# you want to add. CMake verifies that the library exists before | ||
# completing its build. | ||
|
||
find_library(log-lib log) | ||
find_library(android-lib android) | ||
find_library(vulkan-lib vulkan) | ||
find_library(jnigraphics-lib jnigraphics) | ||
add_library( ncnn STATIC IMPORTED ) | ||
set_target_properties( # Specifies the target library. | ||
ncnn | ||
|
||
# Specifies the parameter you want to define. | ||
PROPERTIES IMPORTED_LOCATION | ||
|
||
# Provides the path to the library you want to import. | ||
${CMAKE_SOURCE_DIR}/ncnnvulkan/${ANDROID_ABI}/libncnn.a ) | ||
|
||
|
||
# ncnnvulkan | ||
add_library(glslang STATIC IMPORTED) | ||
add_library(OGLCompiler STATIC IMPORTED) | ||
add_library(OSDependent STATIC IMPORTED) | ||
add_library(SPIRV STATIC IMPORTED) | ||
set_target_properties(glslang PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/ncnnvulkan/${ANDROID_ABI}/libglslang.a) | ||
set_target_properties(OGLCompiler PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/ncnnvulkan/${ANDROID_ABI}/libOGLCompiler.a) | ||
set_target_properties(OSDependent PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/ncnnvulkan/${ANDROID_ABI}/libOSDependent.a) | ||
set_target_properties(SPIRV PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/ncnnvulkan/${ANDROID_ABI}/libSPIRV.a) | ||
|
||
|
||
#include_directories( | ||
# ${CMAKE_SOURCE_DIR}/opencv/include/ | ||
#) | ||
#add_library(libopencv_java4 STATIC IMPORTED) | ||
#set_target_properties( | ||
# libopencv_java4 | ||
# PROPERTIES IMPORTED_LOCATION | ||
# ${CMAKE_SOURCE_DIR}/opencv/${ANDROID_ABI}/libopencv_java4.so | ||
# ) | ||
target_link_libraries( # Specifies the target library. | ||
yolov5 | ||
|
||
# Links the target library to the log library | ||
# included in the NDK. | ||
${log-lib} | ||
${vulkan-lib} | ||
${android-lib} | ||
${jnigraphics-lib} | ||
# libopencv_java4 | ||
) | ||
|
||
|
||
# Specifies libraries CMake should link to your target library. You | ||
# can link multiple libraries, such as libraries you define in this | ||
# build script, prebuilt third-party libraries, or system libraries. | ||
|
||
target_link_libraries( # Specifies the target library. | ||
yolov5 | ||
|
||
# Links the target library to the log library | ||
# included in the NDK. | ||
${log-lib} | ||
${vulkan-lib} | ||
${android-lib} | ||
${jnigraphics-lib} | ||
ncnn | ||
glslang SPIRV OGLCompiler OSDependent ) |
Oops, something went wrong.