diff --git a/CMakeLists.txt b/CMakeLists.txt
index a00d179a0d4972080c8fd392160f8ec451692e4d..b54878b365463d4daae8b6e52e81dd58d7d89817 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,30 +1,71 @@
-cmake_minimum_required(VERSION 3.0)
+cmake_minimum_required(VERSION 3.6)
project(paddle-mobile)
option(DEBUGING "enable debug mode" ON)
-option(USE_OPENMP "openmp support" OFF)
+option(USE_OPENMP "openmp support" ON)
option(USE_EXCEPTION "use std exception" ON)
option(LOG_PROFILE "log profile" ON)
# select the platform to build
option(CPU "armv7 with neon" ON)
option(MALI_GPU "mali gpu" OFF)
option(FPGA "fpga" OFF)
-set(DEBUGING ON)
-
-if (ARM_LINUX)
-include("${CMAKE_CURRENT_LIST_DIR}/tools/arm-platform.cmake")
-endif ()
+option(QUANTI "quantification" OFF)
file(GLOB_RECURSE PADDLE_MOBILE_CC src/*.cc src/*.cpp src/*.c src/*.mm)
file(GLOB_RECURSE PADDLE_MOBILE_H src/*.h)
+include_directories(src/)
+
+if(IS_IOS)
+ set(CMAKE_CXX_FLAGS "-mfpu=neon -marm -fobjc-abi-version=2 -fobjc-arc -std=gnu++11 -stdlib=libc++ -O3 -s -isysroot ${CMAKE_OSX_SYSROOT} ${CMAKE_CXX_FLAGS}")
+else()
+ set(CMAKE_CXX_FLAGS "-std=c++14 -O3 -s ${CMAKE_CXX_FLAGS}")
+endif()
+
+if (DEBUGING)
+ message(STATUS "debug")
+ set(CMAKE_BUILD_TYPE Release)
+ set(CMAKE_CXX_FLAGS_RELEASE "-DNDEBUG")
+ add_definitions(-DPADDLE_MOBILE_DEBUG)
+else ()
+ set(CMAKE_BUILD_TYPE Release)
+ set(CMAKE_CXX_FLAGS_RELEASE "-DNDEBUG")
+ add_definitions(-fvisibility=hidden -fvisibility-inlines-hidden)
+endif ()
+
+if (USE_EXCEPTION)
+ message(STATUS "use exception")
+ add_definitions(-DENABLE_EXCEPTION)
+ add_definitions(-fexceptions)
+else()
+ add_definitions(-fno-exceptions)
+endif ()
+
+if (LOG_PROFILE)
+ add_definitions(-DPADDLE_MOBILE_PROFILE)
+endif()
+
+if(USE_OPENMP AND NOT IS_IOS)
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp")
+ add_definitions(-DPADDLE_MOBILE_USE_OPENMP)
+endif()
+
+# platform control
+if (ARM_LINUX)
+ include("${CMAKE_CURRENT_LIST_DIR}/tools/arm-platform.cmake")
+endif ()
if (CPU)
add_definitions(-DPADDLE_MOBILE_CPU)
else()
- list(REMOVE_ITEM PADDLE_MOBILE_CC ./src/operators/kernel/arm/*.h)
- list(REMOVE_ITEM PADDLE_MOBILE_CC ./src/operators/kernel/arm/*.cc)
- list(REMOVE_ITEM PADDLE_MOBILE_CC ./src/operators/kernel/arm/*.cpp)
+ file(GLOB_RECURSE _tmp_list src/operators/kernel/arm/*.cpp src/operators/kernel/arm/*.cc)
+ foreach(f ${_tmp_list})
+ list(REMOVE_ITEM PADDLE_MOBILE_CC ${f})
+ endforeach()
+ file(GLOB_RECURSE _tmp_list_h src/operators/kernel/arm/*.h)
+ foreach(f ${_tmp_list_h})
+ list(REMOVE_ITEM PADDLE_MOBILE_H ${f})
+ endforeach()
endif()
if (MALI_GPU)
@@ -55,55 +96,32 @@ endif()
if(FPGA)
add_definitions(-DPADDLE_MOBILE_FPGA)
else()
- list(REMOVE_ITEM PADDLE_MOBILE_CC ${CMAKE_CURRENT_SOURCE_DIR}/src/operators/kernel/fpga/*.h)
- list(REMOVE_ITEM PADDLE_MOBILE_CC ${CMAKE_CURRENT_SOURCE_DIR}/src/operators/kernel/fpga/*.cc)
- list(REMOVE_ITEM PADDLE_MOBILE_CC ${CMAKE_CURRENT_SOURCE_DIR}/src/operators/kernel/fpga/*.cpp)
+ file(GLOB_RECURSE _tmp_list src/operators/kernel/fpga/*.cpp src/operators/kernel/fpga/*.cc)
+ foreach(f ${_tmp_list})
+ list(REMOVE_ITEM PADDLE_MOBILE_CC ${f})
+ endforeach()
+
+ file(GLOB_RECURSE _tmp_list_h src/operators/kernel/fpga/*.h)
+ foreach(f ${_tmp_list_h})
+ list(REMOVE_ITEM PADDLE_MOBILE_H ${f})
+ endforeach()
endif()
-set(CMAKE_CXX_FLAGS "-std=c++14 -O3 -s ${CMAKE_CXX_FLAGS}")
-if (DEBUGING)
- message(STATUS "debug")
- set(CMAKE_BUILD_TYPE Debug)
- set(CMAKE_CXX_FLAGS_DEBUG "-g -DNDEBUG")
- add_definitions(-DPADDLE_MOBILE_DEBUG)
- if (ANDROID_NDK_TOOLCHAIN_INCLUDED)
- add_definitions(-DARMV7)
+if (ANDROID_NDK_TOOLCHAIN_INCLUDED)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -llog")
- endif ()
-else ()
- set(CMAKE_BUILD_TYPE Release)
- set(CMAKE_CXX_FLAGS_RELEASE "-DNDEBUG")
- add_definitions(-fvisibility=hidden -fvisibility-inlines-hidden)
-endif ()
-
-if (USE_EXCEPTION)
- message(STATUS "use exception")
- add_definitions(-DENABLE_EXCEPTION)
- add_definitions(-fexceptions)
else()
- add_definitions(-fno-exceptions)
-endif ()
-
-if (LOG_PROFILE)
- add_definitions(-DPADDLE_MOBILE_PROFILE)
-endif()
-
-if(USE_OPENMP)
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp")
- add_definitions(-DPADDLE_MOBILE_USE_OPENMP)
-endif()
-
-
-
-
-if (NOT ANDROID_NDK_TOOLCHAIN_INCLUDED)
list(REMOVE_ITEM PADDLE_MOBILE_H ${CMAKE_CURRENT_SOURCE_DIR}/src/jni/paddle_mobile_jni.h)
list(REMOVE_ITEM PADDLE_MOBILE_CC ${CMAKE_CURRENT_SOURCE_DIR}/src/jni/paddle_mobile_jni.cpp)
list(REMOVE_ITEM PADDLE_MOBILE_H ${CMAKE_CURRENT_SOURCE_DIR}/src/operators/math/math_func_neon.h)
endif ()
-include_directories(src/)
+if (IS_IOS)
+else()
+ list(REMOVE_ITEM PADDLE_MOBILE_H ${CMAKE_CURRENT_SOURCE_DIR}/src/ios_io/PaddleMobile.h)
+ list(REMOVE_ITEM PADDLE_MOBILE_CC ${CMAKE_CURRENT_SOURCE_DIR}/src/ios_io/PaddleMobile.mm)
+ list(REMOVE_ITEM PADDLE_MOBILE_H ${CMAKE_CURRENT_SOURCE_DIR}/src/ios_io/op_symbols.h)
+endif ()
set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
@@ -114,26 +132,28 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY build)
# NET default
set(NET "defult" CACHE STRING "select net type")
set_property(CACHE NET PROPERTY STRINGS "defult" "googlenet" "mobilenet" "yolo" "squeezenet")
-
include("${CMAKE_CURRENT_LIST_DIR}/tools/op.cmake")
-if (IS_IOS)
- add_library(paddle-mobile STATIC ${PADDLE_MOBILE_CC} ${PADDLE_MOBILE_H})
-else()
- list(REMOVE_ITEM PADDLE_MOBILE_H ${CMAKE_CURRENT_SOURCE_DIR}/src/ios_io/PaddleMobile.h)
- list(REMOVE_ITEM PADDLE_MOBILE_CC ${CMAKE_CURRENT_SOURCE_DIR}/src/ios_io/PaddleMobile.mm)
- list(REMOVE_ITEM PADDLE_MOBILE_H ${CMAKE_CURRENT_SOURCE_DIR}/src/ios_io/op_symbols.h)
-endif ()
+# build library
if (ANDROID_NDK_TOOLCHAIN_INCLUDED)
list(REMOVE_DUPLICATES CMAKE_CXX_FLAGS)
add_library(paddle-mobile SHARED ${PADDLE_MOBILE_CC} ${PADDLE_MOBILE_H})
elseif(IS_IOS)
+ add_library(paddle-mobile STATIC ${PADDLE_MOBILE_CC} ${PADDLE_MOBILE_H})
else ()
add_library(paddle-mobile SHARED ${PADDLE_MOBILE_CC} ${PADDLE_MOBILE_H})
endif ()
+# unit test
if(DEBUGING)
- add_subdirectory(test)
+ if(IS_IOS)
+ else()
+ add_subdirectory(test)
+ endif()
endif()
+if (QUANTI)
+ add_subdirectory(tools/quantification)
+endif ()
+
diff --git a/Dockerfile b/Dockerfile
index df7df032acefd39c20051e861d353644e3b91024..f4fa3abcd29f613fe5f7a90f22a9736a3006bf3f 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -32,6 +32,7 @@ RUN cd /tmp && curl -O http://mirrors.neusoft.edu.cn/android/repository/android-
RUN curl -O https://mms-res.cdn.bcebos.com/cmake-3.10.3-Linux-x86_64.tar.gz && \
tar xzf cmake-3.10.3-Linux-x86_64.tar.gz && \
mv cmake-3.10.3-Linux-x86_64 /opt/cmake-3.10 && \
- mv /usr/bin/cmake /usr/bin/cmake.bak && ln -s /opt/cmake-3.10/bin/cmake /usr/bin/cmake
+ mv /usr/bin/cmake /usr/bin/cmake.bak && ln -s /opt/cmake-3.10/bin/cmake /usr/bin/cmake && \
+ mv /usr/bin/ccmake /usr/bin/ccmake.bak && ln -s /opt/cmake-3.10/bin/ccmake /usr/bin/ccmake
RUN cd /opt && unzip /tmp/android-ndk-r17b-linux-x86_64.zip
ENV NDK_ROOT /opt/android-ndk-r17b
diff --git a/README.md b/README.md
index b299879ab73dde1d4e6b749596cfed6bf1888e9e..c9d15d4960a6330ff6614b6dfc8fd20b81386c9c 100644
--- a/README.md
+++ b/README.md
@@ -26,8 +26,11 @@ Paddle-Moible是PaddlePaddle组织下的项目,是一个致力于嵌入式平
- **ARM CPU**
+
+
+
arm cpu是paddle-mobile的主要支持方向,cpu的通用性一直是其优势。嵌入式深度学习,需要大量的cpu汇编实现。我们正在紧锣密鼓的编码,为的是能充分硬件的每一点加速能力。
- arm cpu的优化工作还在进行中,现在使用了常规的cpu优化。在arm a73上paddle-mobile现在单核运行一次mobilenet 1.0是160+ms,显然这不是我们的最终目标,我们正在用大量的汇编改写,后续性能仍会有巨大提升空间。
+ arm cpu的优化工作还在进行中,现在使用了常规的cpu优化。在arm a73上paddle-mobile arm-v7现在单核运行一次mobilenet1.0是110+ms,显然这不是我们的最终目标,我们正在用大量的汇编改写,后续性能仍会有巨大提升空间, 目前只支持armv7, 未来我们也会支持armv8。
- **Mali GPU**
@@ -66,7 +69,7 @@ Paddle-Moible是PaddlePaddle组织下的项目,是一个致力于嵌入式平
### 开发文档
开发文档主要是关于编译、运行等问题。做为开发者,它可以和贡献文档共同结合使用。
-[开发文档]()https://github.com/PaddlePaddle/paddle-mobile/blob/develop/doc/development_doc.md
+[开发文档链接](https://github.com/PaddlePaddle/paddle-mobile/blob/develop/doc/development_doc.md)
### 贡献文档
- [贡献文档链接](https://github.com/PaddlePaddle/paddle-mobile/blob/develop/CONTRIBUTING.md)
@@ -86,10 +89,10 @@ ONNX全称为“Open Neural Network Exchange”,即“开放的神经网络切
目前,百度也在做onnx支持工作。相关转换项目在这里:[paddle-onnx](https://github.com/PaddlePaddle/paddle-onnx)。
-
+
-### 4. 部分测试模型下载
-[下载链接](https://mms-mis.cdn.bcebos.com/paddle-mobile/models.zip)
+### 4. 部分测试模型和测试图片下载
+[下载链接](http://mms-graph.bj.bcebos.com/paddle-mobile%2FmodelsAndImages.zip)
## 问题解决
diff --git a/demo/ReadMe.md b/demo/ReadMe.md
new file mode 100644
index 0000000000000000000000000000000000000000..aa71f75cb7526234bb0bb32e2e5e1f93c1789711
--- /dev/null
+++ b/demo/ReadMe.md
@@ -0,0 +1,11 @@
+## 如何运行demo
+- Android demo下载路径
+ http://mms-graph.bj.bcebos.com/paddle-mobile%2FPaddleMobile_Android.zip
+- iOS demo下载路径:
+ http://mms-graph.bj.bcebos.com/paddle-mobile%2FPaddleMobileDemo_iOS.zip
+
+在demo目录下执行下载demo的脚本
+```
+sh getDemo.sh
+```
+demo工程就下载解压到当前目录中了。
\ No newline at end of file
diff --git a/demo/android/PaddleMobile_Android/.gitignore b/demo/android/PaddleMobile_Android/.gitignore
deleted file mode 100644
index 39fb081a42a86ccf8f9cf99dbccc8bdf7c828bce..0000000000000000000000000000000000000000
--- a/demo/android/PaddleMobile_Android/.gitignore
+++ /dev/null
@@ -1,9 +0,0 @@
-*.iml
-.gradle
-/local.properties
-/.idea/workspace.xml
-/.idea/libraries
-.DS_Store
-/build
-/captures
-.externalNativeBuild
diff --git a/demo/android/PaddleMobile_Android/app/.gitignore b/demo/android/PaddleMobile_Android/app/.gitignore
deleted file mode 100644
index 8b137891791fe96927ad78e64b0aad7bded08bdc..0000000000000000000000000000000000000000
--- a/demo/android/PaddleMobile_Android/app/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-
diff --git a/demo/android/PaddleMobile_Android/app/build.gradle b/demo/android/PaddleMobile_Android/app/build.gradle
deleted file mode 100644
index 3d61efb83a083909a0038886469e1c7fce218e8c..0000000000000000000000000000000000000000
--- a/demo/android/PaddleMobile_Android/app/build.gradle
+++ /dev/null
@@ -1,23 +0,0 @@
-apply plugin: 'com.android.application'
-
-android {
- compileSdkVersion 21
- defaultConfig {
- applicationId "com.baidu.paddle"
- minSdkVersion 15
- targetSdkVersion 21
- versionCode 1
- versionName "1.0"
- }
- buildTypes {
- release {
- minifyEnabled false
- proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
- }
- }
-}
-
-dependencies {
- implementation fileTree(dir: 'libs', include: ['*.jar'])
- implementation 'com.android.support:appcompat-v7:21.0.3'
-}
diff --git a/demo/android/PaddleMobile_Android/app/proguard-rules.pro b/demo/android/PaddleMobile_Android/app/proguard-rules.pro
deleted file mode 100644
index f1b424510da51fd82143bc74a0a801ae5a1e2fcd..0000000000000000000000000000000000000000
--- a/demo/android/PaddleMobile_Android/app/proguard-rules.pro
+++ /dev/null
@@ -1,21 +0,0 @@
-# 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
diff --git a/demo/android/PaddleMobile_Android/app/src/main/AndroidManifest.xml b/demo/android/PaddleMobile_Android/app/src/main/AndroidManifest.xml
deleted file mode 100644
index b9bf81dcb9fffb855d067cc7df1633ebcf586432..0000000000000000000000000000000000000000
--- a/demo/android/PaddleMobile_Android/app/src/main/AndroidManifest.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/demo/android/PaddleMobile_Android/app/src/main/java/com/baidu/paddle/MainActivity.java b/demo/android/PaddleMobile_Android/app/src/main/java/com/baidu/paddle/MainActivity.java
deleted file mode 100755
index febe816681d3845a61c5a8b40630e82ac9b4ea95..0000000000000000000000000000000000000000
--- a/demo/android/PaddleMobile_Android/app/src/main/java/com/baidu/paddle/MainActivity.java
+++ /dev/null
@@ -1,408 +0,0 @@
-/*
- * Copyright (c) 2016 Baidu, Inc. All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
- * documentation files (the "Software"), to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
- * to permit persons to whom the Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all copies or substantial portions of
- * the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
- * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
- * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE.
- */
-package com.baidu.paddle;
-
-import android.app.Activity;
-import android.content.Context;
-import android.content.Intent;
-import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
-import android.graphics.Canvas;
-import android.graphics.Color;
-import android.graphics.Paint;
-import android.net.Uri;
-import android.os.AsyncTask;
-import android.os.Bundle;
-import android.os.Environment;
-
-import android.provider.MediaStore;
-
-import android.util.Log;
-import android.view.View;
-import android.widget.Button;
-import android.widget.ImageView;
-import android.widget.TextView;
-import android.widget.Toast;
-
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.InputStream;
-
-import static android.graphics.Color.blue;
-import static android.graphics.Color.green;
-import static android.graphics.Color.red;
-import static com.baidu.paddle.MainActivity.TYPE.googlenet;
-
-
-public class MainActivity extends Activity {
- public static final int TAKE_PHOTO_REQUEST_CODE = 1001;
-
- private Context mContext = null;
-
- private int inputSize = 224;
-
- enum TYPE {
- googlenet
- }
-
- private TYPE type = googlenet;
- private ImageView imageView;
- private TextView tvSpeed;
- private Button button;
- private Bitmap bmp;
-
- static {
- try {
- System.loadLibrary("paddle-mobile");
-
- } catch (SecurityException e) {
- e.printStackTrace();
-
- } catch (UnsatisfiedLinkError e) {
- e.printStackTrace();
-
- } catch (NullPointerException e) {
- e.printStackTrace();
-
- }
-
- }
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- mContext = this;
- setContentView(R.layout.main_activity);
- init();
- }
-
- private void init() {
- imageView = (ImageView) findViewById(R.id.imageView);
- tvSpeed = (TextView) findViewById(R.id.tv_speed);
- button = (Button) findViewById(R.id.button);
- button.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- if (!isHasSdCard()) {
- Toast.makeText(mContext, R.string.sdcard_not_available,
- Toast.LENGTH_LONG).show();
- return;
- }
- Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
- // save pic in sdcard
- Uri imageUri = Uri.fromFile(getTempImage());
- intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
- startActivityForResult(intent, TAKE_PHOTO_REQUEST_CODE);
-
- }
- });
- Button bt_load = (Button) findViewById(R.id.bt_load);
- bt_load.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- String assetPath = "pml_demo";
- String sdcardPath = Environment.getExternalStorageDirectory()
- + File.separator + assetPath + File.separator + type;
- PML.load(sdcardPath);
-
- }
- });
- Button bt_clear = (Button) findViewById(R.id.bt_clear);
- bt_clear.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
-
- PML.clear();
-
-
- }
- });
- String assetPath = "pml_demo";
- String sdcardPath = Environment.getExternalStorageDirectory()
- + File.separator + assetPath;
- copyFilesFromAssets(this, assetPath, sdcardPath);
-
-
- }
-
- public void copyFilesFromAssets(Context context, String oldPath, String newPath) {
- try {
- String[] fileNames = context.getAssets().list(oldPath);
- if (fileNames.length > 0) {
- // directory
- File file = new File(newPath);
- file.mkdirs();
- // copy recursivelyC
- for (String fileName : fileNames) {
- copyFilesFromAssets(context, oldPath + "/" + fileName,
- newPath + "/" + fileName);
- }
- } else {
- // file
- InputStream is = context.getAssets().open(oldPath);
- FileOutputStream fos = new FileOutputStream(new File(newPath));
- byte[] buffer = new byte[1024];
- int byteCount;
- while ((byteCount = is.read(buffer)) != -1) {
- fos.write(buffer, 0, byteCount);
- }
- fos.flush();
- is.close();
- fos.close();
- }
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
-
- public File getTempImage() {
- if (Environment.getExternalStorageState().equals(
- Environment.MEDIA_MOUNTED)) {
- File tempFile = new File(Environment.getExternalStorageDirectory(), "temp.jpg");
- try {
- tempFile.createNewFile();
- } catch (IOException e) {
- e.printStackTrace();
- }
-
- return tempFile;
- }
- return null;
- }
-
- public void onActivityResult(int requestCode, int resultCode, Intent data) {
- super.onActivityResult(requestCode, resultCode, data);
- switch (requestCode) {
- case TAKE_PHOTO_REQUEST_CODE:
- if (resultCode == RESULT_OK) {
- DetectionTask detectionTask = new DetectionTask();
- detectionTask.execute(getTempImage().getPath());
- }
- break;
- default:
- break;
- }
- }
-
- /**
- * draw rect on imageView
- *
- * @param bitmap
- * @param predicted
- * @param viewWidth
- * @param viewHeight
- */
- private void drawRect(Bitmap bitmap, float[] predicted, int viewWidth, int viewHeight) {
-
- Canvas canvas = new Canvas(bitmap);
- canvas.drawBitmap(bitmap, 0, 0, null);
- if (type == googlenet) {
- Paint paint = new Paint();
- paint.setColor(Color.RED);
- paint.setStyle(Paint.Style.STROKE);
- paint.setStrokeWidth(3.0f);
- float x1 = 0;
- float x2 = 0;
- float y1 = 0;
- float y2 = 0;
-
- // the googlenet result sequence is (left top right top bottom)
- x1 = (predicted[0] * viewWidth / 224);
- y1 = (predicted[1] * viewHeight / 224);
- x2 = (predicted[2] * viewWidth / 224);
- y2 = (predicted[3] * viewHeight / 224);
-
-
- canvas.drawRect(x1, y1, x2, y2, paint);
- }
-
-
- imageView.setImageBitmap(bitmap);
-
- }
-
- float getMaxIndex(float[] predicted) {
- float max = 0;
- int index = 0;
- for (int i = 0; i < predicted.length; i++) {
- if (predicted[i] > max) {
- max = predicted[i];
- index = i;
- }
- }
- return index;
- }
-
- public float[] getScaledMatrix(Bitmap bitmap, int desWidth,
- int desHeight) {
- float[] dataBuf = new float[3 * desWidth * desHeight];
- int rIndex;
- int gIndex;
- int bIndex;
- int[] pixels = new int[desWidth * desHeight];
- Bitmap bm = Bitmap.createScaledBitmap(bitmap, desWidth, desHeight, false);
- bm.getPixels(pixels, 0, desWidth, 0, 0, desWidth, desHeight);
- int j = 0;
- int k = 0;
- for (int i = 0; i < pixels.length; i ++) {
- int clr = pixels[i];
- j = i / desHeight;
- k = i % desWidth;
- rIndex = j * desWidth + k;
- gIndex = rIndex + desHeight * desWidth;
- bIndex = gIndex + desHeight * desWidth;
- dataBuf[rIndex] = (float)((clr & 0x00ff0000)>> 16) -148;
- dataBuf[gIndex] = (float)((clr & 0x0000ff00)>> 8) - 148;
- dataBuf[bIndex] = (float)((clr & 0x000000ff)) -148;
-
- }
- if (bm.isRecycled()) {
- bm.recycle();
- }
- return dataBuf;
-
-
- }
- /**
- * check whether sdcard is mounted
- *
- * @return
- */
- public boolean isHasSdCard() {
- if (Environment.getExternalStorageState().equals(
- Environment.MEDIA_MOUNTED)) {
- return true;
- } else {
- return false;
- }
- }
-
- public void dumpData(float[] results, String filename) {
- try {
- File writename = new File(filename);
- writename.createNewFile();
- BufferedWriter out = new BufferedWriter(new FileWriter(writename));
- for (float result : results) {
- out.write(result + " ");
- }
- out.flush();
- out.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
-
-
- /**
- * scale bitmap in case of OOM
- *
- * @param ctx
- * @param filePath
- * @return
- */
- public Bitmap getScaleBitmap(Context ctx, String filePath) {
- BitmapFactory.Options opt = new BitmapFactory.Options();
- opt.inJustDecodeBounds = true;
- BitmapFactory.decodeFile(filePath, opt);
-
- int bmpWidth = opt.outWidth;
- int bmpHeight = opt.outHeight;
-
- int maxSize = 500;
-
- opt.inSampleSize = 1;
- while (true) {
- if (bmpWidth / opt.inSampleSize < maxSize || bmpHeight / opt.inSampleSize < maxSize) {
- break;
- }
- opt.inSampleSize *= 2;
- }
- opt.inJustDecodeBounds = false;
- Bitmap bmp = BitmapFactory.decodeFile(filePath, opt);
- return bmp;
- }
-
- @Override
- public void onBackPressed() {
- super.onBackPressed();
- Log.d("mdl", "mdl clear");
- // clear mdl
- PML.clear();
-
- }
-
- class DetectionTask extends AsyncTask {
- private long time;
-
- public DetectionTask() {
- super();
- }
-
- @Override
- protected void onPreExecute() {
- super.onPreExecute();
- if (type == googlenet) {
- inputSize = 224;
- }
- }
-
- @Override
- protected void onPostExecute(float[] result) {
- super.onPostExecute(result);
- try {
- Bitmap src = Bitmap.createScaledBitmap(bmp, imageView.getWidth(),
- imageView.getHeight(), false);
- drawRect(src, result, imageView.getWidth(), imageView.getHeight());
- tvSpeed.setText("detection cost:" + time + "ms");
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- @Override
- protected void onProgressUpdate(Void... values) {
- super.onProgressUpdate(values);
- }
-
- @Override
- protected void onCancelled() {
- super.onCancelled();
- }
-
- @Override
- protected float[] doInBackground(String... strings) {
- bmp = getScaleBitmap(mContext, strings[0]);
- float[] inputData = getScaledMatrix(bmp, inputSize, inputSize);
- float[] result = null;
- try {
- long start = System.currentTimeMillis();
- result = PML.predict(inputData);
- long end = System.currentTimeMillis();
- time = end - start;
-
- } catch (Exception e) {
- e.printStackTrace();
- }
- return result;
- }
- }
-}
diff --git a/demo/android/PaddleMobile_Android/app/src/main/java/com/baidu/paddle/PML.java b/demo/android/PaddleMobile_Android/app/src/main/java/com/baidu/paddle/PML.java
deleted file mode 100644
index 7649d4c081223bace01b806d1eb7dca57129ed7c..0000000000000000000000000000000000000000
--- a/demo/android/PaddleMobile_Android/app/src/main/java/com/baidu/paddle/PML.java
+++ /dev/null
@@ -1,23 +0,0 @@
-package com.baidu.paddle;
-
-public class PML {
- /**
- * Load
- * @param modelPath
- * @return
- */
- public static native boolean load(String modelPath);
-
-
- /**
- * object detection
- *
- * @param buf
- * @return
- */
- public static native float[] predict(float[] buf);
-
-
- public static native void clear();
-
-}
diff --git a/demo/android/PaddleMobile_Android/app/src/main/res/drawable/ic_launcher_background.xml b/demo/android/PaddleMobile_Android/app/src/main/res/drawable/ic_launcher_background.xml
deleted file mode 100644
index d5fccc538c179838bfdce779c26eebb4fa0b5ce9..0000000000000000000000000000000000000000
--- a/demo/android/PaddleMobile_Android/app/src/main/res/drawable/ic_launcher_background.xml
+++ /dev/null
@@ -1,170 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/demo/android/PaddleMobile_Android/app/src/main/res/layout/main_activity.xml b/demo/android/PaddleMobile_Android/app/src/main/res/layout/main_activity.xml
deleted file mode 100644
index 6653b182adbfc6d82d50d313db8c88789c0b027b..0000000000000000000000000000000000000000
--- a/demo/android/PaddleMobile_Android/app/src/main/res/layout/main_activity.xml
+++ /dev/null
@@ -1,55 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/demo/android/PaddleMobile_Android/app/src/main/res/mipmap-hdpi/ic_launcher.png b/demo/android/PaddleMobile_Android/app/src/main/res/mipmap-hdpi/ic_launcher.png
deleted file mode 100644
index a2f5908281d070150700378b64a84c7db1f97aa1..0000000000000000000000000000000000000000
Binary files a/demo/android/PaddleMobile_Android/app/src/main/res/mipmap-hdpi/ic_launcher.png and /dev/null differ
diff --git a/demo/android/PaddleMobile_Android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png b/demo/android/PaddleMobile_Android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
deleted file mode 100644
index 1b523998081149a985cef0cdf89045b9ed29964a..0000000000000000000000000000000000000000
Binary files a/demo/android/PaddleMobile_Android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png and /dev/null differ
diff --git a/demo/android/PaddleMobile_Android/app/src/main/res/values/colors.xml b/demo/android/PaddleMobile_Android/app/src/main/res/values/colors.xml
deleted file mode 100644
index 3ab3e9cbce07f7cdc941fc8ba424c05e83ed80f0..0000000000000000000000000000000000000000
--- a/demo/android/PaddleMobile_Android/app/src/main/res/values/colors.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
- #3F51B5
- #303F9F
- #FF4081
-
diff --git a/demo/android/PaddleMobile_Android/app/src/main/res/values/strings.xml b/demo/android/PaddleMobile_Android/app/src/main/res/values/strings.xml
deleted file mode 100644
index f927237046f8a51f9f49ef37440cc05a3abcc0fa..0000000000000000000000000000000000000000
--- a/demo/android/PaddleMobile_Android/app/src/main/res/values/strings.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-
- PaddleMobile_Android
- sdcard not available
- detection cost:
-
diff --git a/demo/android/PaddleMobile_Android/app/src/main/res/values/styles.xml b/demo/android/PaddleMobile_Android/app/src/main/res/values/styles.xml
deleted file mode 100644
index 5885930df6d10edf3d6df40d6556297d11f953da..0000000000000000000000000000000000000000
--- a/demo/android/PaddleMobile_Android/app/src/main/res/values/styles.xml
+++ /dev/null
@@ -1,11 +0,0 @@
-
-
-
-
-
-
diff --git a/demo/android/PaddleMobile_Android/build.gradle b/demo/android/PaddleMobile_Android/build.gradle
deleted file mode 100644
index 43c070853e6387cb26e12ad00449e2c4df192bf6..0000000000000000000000000000000000000000
--- a/demo/android/PaddleMobile_Android/build.gradle
+++ /dev/null
@@ -1,27 +0,0 @@
-// Top-level build file where you can add configuration options common to all sub-projects/modules.
-
-buildscript {
-
- repositories {
- google()
- jcenter()
- }
- dependencies {
- classpath 'com.android.tools.build:gradle:3.1.3'
-
-
- // NOTE: Do not place your application dependencies here; they belong
- // in the individual module build.gradle files
- }
-}
-
-allprojects {
- repositories {
- google()
- jcenter()
- }
-}
-
-task clean(type: Delete) {
- delete rootProject.buildDir
-}
diff --git a/demo/android/PaddleMobile_Android/gradle.properties b/demo/android/PaddleMobile_Android/gradle.properties
deleted file mode 100644
index db1fda5348df0a517e66da43975df8d062ac7109..0000000000000000000000000000000000000000
--- a/demo/android/PaddleMobile_Android/gradle.properties
+++ /dev/null
@@ -1,18 +0,0 @@
-# Project-wide Gradle settings.
-
-# IDE (e.g. Android Studio) users:
-# Gradle settings configured through the IDE *will override*
-# any settings specified in this file.
-
-# For more details on how to configure your build environment visit
-# http://www.gradle.org/docs/current/userguide/build_environment.html
-
-# Specifies the JVM arguments used for the daemon process.
-# The setting is particularly useful for tweaking memory settings.
-org.gradle.jvmargs=-Xmx1536m
-android.injected.testOnly=false
-
-# When configured, Gradle will run in incubating parallel mode.
-# This option should only be used with decoupled projects. More details, visit
-# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
-# org.gradle.parallel=true
diff --git a/demo/android/PaddleMobile_Android/gradle/wrapper/gradle-wrapper.jar b/demo/android/PaddleMobile_Android/gradle/wrapper/gradle-wrapper.jar
deleted file mode 100644
index 13372aef5e24af05341d49695ee84e5f9b594659..0000000000000000000000000000000000000000
Binary files a/demo/android/PaddleMobile_Android/gradle/wrapper/gradle-wrapper.jar and /dev/null differ
diff --git a/demo/android/PaddleMobile_Android/gradle/wrapper/gradle-wrapper.properties b/demo/android/PaddleMobile_Android/gradle/wrapper/gradle-wrapper.properties
deleted file mode 100644
index 45f9d18b437e41e53ed0620b52bbabc2c65b361b..0000000000000000000000000000000000000000
--- a/demo/android/PaddleMobile_Android/gradle/wrapper/gradle-wrapper.properties
+++ /dev/null
@@ -1,6 +0,0 @@
-#Mon Jul 02 13:58:58 CST 2018
-distributionBase=GRADLE_USER_HOME
-distributionPath=wrapper/dists
-zipStoreBase=GRADLE_USER_HOME
-zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
diff --git a/demo/android/PaddleMobile_Android/gradlew b/demo/android/PaddleMobile_Android/gradlew
deleted file mode 100755
index 9d82f78915133e1c35a6ea51252590fb38efac2f..0000000000000000000000000000000000000000
--- a/demo/android/PaddleMobile_Android/gradlew
+++ /dev/null
@@ -1,160 +0,0 @@
-#!/usr/bin/env bash
-
-##############################################################################
-##
-## Gradle start up script for UN*X
-##
-##############################################################################
-
-# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
-DEFAULT_JVM_OPTS=""
-
-APP_NAME="Gradle"
-APP_BASE_NAME=`basename "$0"`
-
-# Use the maximum available, or set MAX_FD != -1 to use that value.
-MAX_FD="maximum"
-
-warn ( ) {
- echo "$*"
-}
-
-die ( ) {
- echo
- echo "$*"
- echo
- exit 1
-}
-
-# OS specific support (must be 'true' or 'false').
-cygwin=false
-msys=false
-darwin=false
-case "`uname`" in
- CYGWIN* )
- cygwin=true
- ;;
- Darwin* )
- darwin=true
- ;;
- MINGW* )
- msys=true
- ;;
-esac
-
-# Attempt to set APP_HOME
-# Resolve links: $0 may be a link
-PRG="$0"
-# Need this for relative symlinks.
-while [ -h "$PRG" ] ; do
- ls=`ls -ld "$PRG"`
- link=`expr "$ls" : '.*-> \(.*\)$'`
- if expr "$link" : '/.*' > /dev/null; then
- PRG="$link"
- else
- PRG=`dirname "$PRG"`"/$link"
- fi
-done
-SAVED="`pwd`"
-cd "`dirname \"$PRG\"`/" >/dev/null
-APP_HOME="`pwd -P`"
-cd "$SAVED" >/dev/null
-
-CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
-
-# Determine the Java command to use to start the JVM.
-if [ -n "$JAVA_HOME" ] ; then
- if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
- # IBM's JDK on AIX uses strange locations for the executables
- JAVACMD="$JAVA_HOME/jre/sh/java"
- else
- JAVACMD="$JAVA_HOME/bin/java"
- fi
- if [ ! -x "$JAVACMD" ] ; then
- die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
-
-Please set the JAVA_HOME variable in your environment to match the
-location of your Java installation."
- fi
-else
- JAVACMD="java"
- which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
-
-Please set the JAVA_HOME variable in your environment to match the
-location of your Java installation."
-fi
-
-# Increase the maximum file descriptors if we can.
-if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
- MAX_FD_LIMIT=`ulimit -H -n`
- if [ $? -eq 0 ] ; then
- if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
- MAX_FD="$MAX_FD_LIMIT"
- fi
- ulimit -n $MAX_FD
- if [ $? -ne 0 ] ; then
- warn "Could not set maximum file descriptor limit: $MAX_FD"
- fi
- else
- warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
- fi
-fi
-
-# For Darwin, add options to specify how the application appears in the dock
-if $darwin; then
- GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
-fi
-
-# For Cygwin, switch paths to Windows format before running java
-if $cygwin ; then
- APP_HOME=`cygpath --path --mixed "$APP_HOME"`
- CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
- JAVACMD=`cygpath --unix "$JAVACMD"`
-
- # We build the pattern for arguments to be converted via cygpath
- ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
- SEP=""
- for dir in $ROOTDIRSRAW ; do
- ROOTDIRS="$ROOTDIRS$SEP$dir"
- SEP="|"
- done
- OURCYGPATTERN="(^($ROOTDIRS))"
- # Add a user-defined pattern to the cygpath arguments
- if [ "$GRADLE_CYGPATTERN" != "" ] ; then
- OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
- fi
- # Now convert the arguments - kludge to limit ourselves to /bin/sh
- i=0
- for arg in "$@" ; do
- CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
- CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
-
- if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
- eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
- else
- eval `echo args$i`="\"$arg\""
- fi
- i=$((i+1))
- done
- case $i in
- (0) set -- ;;
- (1) set -- "$args0" ;;
- (2) set -- "$args0" "$args1" ;;
- (3) set -- "$args0" "$args1" "$args2" ;;
- (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
- (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
- (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
- (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
- (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
- (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
- esac
-fi
-
-# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
-function splitJvmOpts() {
- JVM_OPTS=("$@")
-}
-eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
-JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
-
-exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
diff --git a/demo/android/PaddleMobile_Android/gradlew.bat b/demo/android/PaddleMobile_Android/gradlew.bat
deleted file mode 100644
index aec99730b4e8fcd90b57a0e8e01544fea7c31a89..0000000000000000000000000000000000000000
--- a/demo/android/PaddleMobile_Android/gradlew.bat
+++ /dev/null
@@ -1,90 +0,0 @@
-@if "%DEBUG%" == "" @echo off
-@rem ##########################################################################
-@rem
-@rem Gradle startup script for Windows
-@rem
-@rem ##########################################################################
-
-@rem Set local scope for the variables with windows NT shell
-if "%OS%"=="Windows_NT" setlocal
-
-@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
-set DEFAULT_JVM_OPTS=
-
-set DIRNAME=%~dp0
-if "%DIRNAME%" == "" set DIRNAME=.
-set APP_BASE_NAME=%~n0
-set APP_HOME=%DIRNAME%
-
-@rem Find java.exe
-if defined JAVA_HOME goto findJavaFromJavaHome
-
-set JAVA_EXE=java.exe
-%JAVA_EXE% -version >NUL 2>&1
-if "%ERRORLEVEL%" == "0" goto init
-
-echo.
-echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
-echo.
-echo Please set the JAVA_HOME variable in your environment to match the
-echo location of your Java installation.
-
-goto fail
-
-:findJavaFromJavaHome
-set JAVA_HOME=%JAVA_HOME:"=%
-set JAVA_EXE=%JAVA_HOME%/bin/java.exe
-
-if exist "%JAVA_EXE%" goto init
-
-echo.
-echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
-echo.
-echo Please set the JAVA_HOME variable in your environment to match the
-echo location of your Java installation.
-
-goto fail
-
-:init
-@rem Get command-line arguments, handling Windowz variants
-
-if not "%OS%" == "Windows_NT" goto win9xME_args
-if "%@eval[2+2]" == "4" goto 4NT_args
-
-:win9xME_args
-@rem Slurp the command line arguments.
-set CMD_LINE_ARGS=
-set _SKIP=2
-
-:win9xME_args_slurp
-if "x%~1" == "x" goto execute
-
-set CMD_LINE_ARGS=%*
-goto execute
-
-:4NT_args
-@rem Get arguments from the 4NT Shell from JP Software
-set CMD_LINE_ARGS=%$
-
-:execute
-@rem Setup the command line
-
-set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
-
-@rem Execute Gradle
-"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
-
-:end
-@rem End local scope for the variables with windows NT shell
-if "%ERRORLEVEL%"=="0" goto mainEnd
-
-:fail
-rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
-rem the _cmd.exe /c_ return code!
-if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
-exit /b 1
-
-:mainEnd
-if "%OS%"=="Windows_NT" endlocal
-
-:omega
diff --git a/demo/android/PaddleMobile_Android/settings.gradle b/demo/android/PaddleMobile_Android/settings.gradle
deleted file mode 100644
index e7b4def49cb53d9aa04228dd3edb14c9e635e003..0000000000000000000000000000000000000000
--- a/demo/android/PaddleMobile_Android/settings.gradle
+++ /dev/null
@@ -1 +0,0 @@
-include ':app'
diff --git a/demo/getDemo.sh b/demo/getDemo.sh
new file mode 100644
index 0000000000000000000000000000000000000000..b69461e01c710c30ce9a44714ed2d0cdae0c9819
--- /dev/null
+++ b/demo/getDemo.sh
@@ -0,0 +1,8 @@
+#!/usr/bin/env bash
+wget http://mms-graph.bj.bcebos.com/paddle-mobile%2FPaddleMobile_Android.zip
+wget http://mms-graph.bj.bcebos.com/paddle-mobile%2FPaddleMobileDemo_iOS.zip
+unzip paddle-mobile%2FPaddleMobile_Android.zip
+unzip paddle-mobile%2FPaddleMobileDemo_iOS.zip
+rm -rf paddle-mobile%2FPaddleMobile_Android.zip
+rm -rf paddle-mobile%2FPaddleMobileDemo_iOS.zip
+rm -rf __MACOSX
\ No newline at end of file
diff --git a/demo/ios/PaddleMobileDemo/PaddleMobileDemo.xcodeproj/project.pbxproj b/demo/ios/PaddleMobileDemo/PaddleMobileDemo.xcodeproj/project.pbxproj
deleted file mode 100644
index 8500c89c9af5ab2d56e08b576dc007a424262d15..0000000000000000000000000000000000000000
--- a/demo/ios/PaddleMobileDemo/PaddleMobileDemo.xcodeproj/project.pbxproj
+++ /dev/null
@@ -1,398 +0,0 @@
-// !$*UTF8*$!
-{
- archiveVersion = 1;
- classes = {
- };
- objectVersion = 50;
- objects = {
-
-/* Begin PBXBuildFile section */
- FC12E93320EB6B2800807EF4 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = FC12E93220EB6B2800807EF4 /* AppDelegate.m */; };
- FC12E93620EB6B2800807EF4 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = FC12E93520EB6B2800807EF4 /* ViewController.m */; };
- FC12E93920EB6B2800807EF4 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = FC12E93720EB6B2800807EF4 /* Main.storyboard */; };
- FC12E93B20EB6B2900807EF4 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = FC12E93A20EB6B2900807EF4 /* Assets.xcassets */; };
- FC12E93E20EB6B2900807EF4 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = FC12E93C20EB6B2900807EF4 /* LaunchScreen.storyboard */; };
- FC12E94120EB6B2900807EF4 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = FC12E94020EB6B2900807EF4 /* main.m */; };
- FC12E94A20EB6B6800807EF4 /* libpaddle-mobile.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FC12E94820EB6B6800807EF4 /* libpaddle-mobile.a */; };
- FC12E94D20EB6BBB00807EF4 /* libstdc++.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = FC12E94C20EB6BBB00807EF4 /* libstdc++.tbd */; };
- FC12E95120EB6BED00807EF4 /* params in Resources */ = {isa = PBXBuildFile; fileRef = FC12E94F20EB6BED00807EF4 /* params */; };
- FC12E95220EB6BED00807EF4 /* model in Resources */ = {isa = PBXBuildFile; fileRef = FC12E95020EB6BED00807EF4 /* model */; };
- FC12E95420EB6C0D00807EF4 /* apple.jpg in Resources */ = {isa = PBXBuildFile; fileRef = FC12E95320EB6C0D00807EF4 /* apple.jpg */; };
-/* End PBXBuildFile section */
-
-/* Begin PBXFileReference section */
- FC12E92E20EB6B2800807EF4 /* PaddleMobileDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = PaddleMobileDemo.app; sourceTree = BUILT_PRODUCTS_DIR; };
- FC12E93120EB6B2800807EF4 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; };
- FC12E93220EB6B2800807EF4 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; };
- FC12E93420EB6B2800807EF4 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; };
- FC12E93520EB6B2800807EF4 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; };
- FC12E93820EB6B2800807EF4 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; };
- FC12E93A20EB6B2900807EF4 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; };
- FC12E93D20EB6B2900807EF4 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; };
- FC12E93F20EB6B2900807EF4 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; };
- FC12E94020EB6B2900807EF4 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; };
- FC12E94820EB6B6800807EF4 /* libpaddle-mobile.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = "libpaddle-mobile.a"; sourceTree = ""; };
- FC12E94920EB6B6800807EF4 /* PaddleMobile.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PaddleMobile.h; sourceTree = ""; };
- FC12E94C20EB6BBB00807EF4 /* libstdc++.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = "libstdc++.tbd"; path = "usr/lib/libstdc++.tbd"; sourceTree = SDKROOT; };
- FC12E94F20EB6BED00807EF4 /* params */ = {isa = PBXFileReference; lastKnownFileType = file; path = params; sourceTree = ""; };
- FC12E95020EB6BED00807EF4 /* model */ = {isa = PBXFileReference; lastKnownFileType = file; path = model; sourceTree = ""; };
- FC12E95320EB6C0D00807EF4 /* apple.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = apple.jpg; sourceTree = ""; };
-/* End PBXFileReference section */
-
-/* Begin PBXFrameworksBuildPhase section */
- FC12E92B20EB6B2800807EF4 /* Frameworks */ = {
- isa = PBXFrameworksBuildPhase;
- buildActionMask = 2147483647;
- files = (
- FC12E94D20EB6BBB00807EF4 /* libstdc++.tbd in Frameworks */,
- FC12E94A20EB6B6800807EF4 /* libpaddle-mobile.a in Frameworks */,
- );
- runOnlyForDeploymentPostprocessing = 0;
- };
-/* End PBXFrameworksBuildPhase section */
-
-/* Begin PBXGroup section */
- FC12E92520EB6B2800807EF4 = {
- isa = PBXGroup;
- children = (
- FC12E93020EB6B2800807EF4 /* PaddleMobileDemo */,
- FC12E92F20EB6B2800807EF4 /* Products */,
- FC12E94B20EB6BBB00807EF4 /* Frameworks */,
- );
- sourceTree = "";
- };
- FC12E92F20EB6B2800807EF4 /* Products */ = {
- isa = PBXGroup;
- children = (
- FC12E92E20EB6B2800807EF4 /* PaddleMobileDemo.app */,
- );
- name = Products;
- sourceTree = "";
- };
- FC12E93020EB6B2800807EF4 /* PaddleMobileDemo */ = {
- isa = PBXGroup;
- children = (
- FC12E95320EB6C0D00807EF4 /* apple.jpg */,
- FC12E94E20EB6BED00807EF4 /* googlenet_combine */,
- FC12E94720EB6B6800807EF4 /* PaddleMobile */,
- FC12E93120EB6B2800807EF4 /* AppDelegate.h */,
- FC12E93220EB6B2800807EF4 /* AppDelegate.m */,
- FC12E93420EB6B2800807EF4 /* ViewController.h */,
- FC12E93520EB6B2800807EF4 /* ViewController.m */,
- FC12E93720EB6B2800807EF4 /* Main.storyboard */,
- FC12E93A20EB6B2900807EF4 /* Assets.xcassets */,
- FC12E93C20EB6B2900807EF4 /* LaunchScreen.storyboard */,
- FC12E93F20EB6B2900807EF4 /* Info.plist */,
- FC12E94020EB6B2900807EF4 /* main.m */,
- );
- path = PaddleMobileDemo;
- sourceTree = "";
- };
- FC12E94720EB6B6800807EF4 /* PaddleMobile */ = {
- isa = PBXGroup;
- children = (
- FC12E94820EB6B6800807EF4 /* libpaddle-mobile.a */,
- FC12E94920EB6B6800807EF4 /* PaddleMobile.h */,
- );
- path = PaddleMobile;
- sourceTree = "";
- };
- FC12E94B20EB6BBB00807EF4 /* Frameworks */ = {
- isa = PBXGroup;
- children = (
- FC12E94C20EB6BBB00807EF4 /* libstdc++.tbd */,
- );
- name = Frameworks;
- sourceTree = "";
- };
- FC12E94E20EB6BED00807EF4 /* googlenet_combine */ = {
- isa = PBXGroup;
- children = (
- FC12E94F20EB6BED00807EF4 /* params */,
- FC12E95020EB6BED00807EF4 /* model */,
- );
- path = googlenet_combine;
- sourceTree = "";
- };
-/* End PBXGroup section */
-
-/* Begin PBXNativeTarget section */
- FC12E92D20EB6B2800807EF4 /* PaddleMobileDemo */ = {
- isa = PBXNativeTarget;
- buildConfigurationList = FC12E94420EB6B2900807EF4 /* Build configuration list for PBXNativeTarget "PaddleMobileDemo" */;
- buildPhases = (
- FC12E92A20EB6B2800807EF4 /* Sources */,
- FC12E92B20EB6B2800807EF4 /* Frameworks */,
- FC12E92C20EB6B2800807EF4 /* Resources */,
- );
- buildRules = (
- );
- dependencies = (
- );
- name = PaddleMobileDemo;
- productName = PaddleMobileDemo;
- productReference = FC12E92E20EB6B2800807EF4 /* PaddleMobileDemo.app */;
- productType = "com.apple.product-type.application";
- };
-/* End PBXNativeTarget section */
-
-/* Begin PBXProject section */
- FC12E92620EB6B2800807EF4 /* Project object */ = {
- isa = PBXProject;
- attributes = {
- LastUpgradeCheck = 0940;
- ORGANIZATIONNAME = orange;
- TargetAttributes = {
- FC12E92D20EB6B2800807EF4 = {
- CreatedOnToolsVersion = 9.4.1;
- };
- };
- };
- buildConfigurationList = FC12E92920EB6B2800807EF4 /* Build configuration list for PBXProject "PaddleMobileDemo" */;
- compatibilityVersion = "Xcode 9.3";
- developmentRegion = en;
- hasScannedForEncodings = 0;
- knownRegions = (
- en,
- Base,
- );
- mainGroup = FC12E92520EB6B2800807EF4;
- productRefGroup = FC12E92F20EB6B2800807EF4 /* Products */;
- projectDirPath = "";
- projectRoot = "";
- targets = (
- FC12E92D20EB6B2800807EF4 /* PaddleMobileDemo */,
- );
- };
-/* End PBXProject section */
-
-/* Begin PBXResourcesBuildPhase section */
- FC12E92C20EB6B2800807EF4 /* Resources */ = {
- isa = PBXResourcesBuildPhase;
- buildActionMask = 2147483647;
- files = (
- FC12E93E20EB6B2900807EF4 /* LaunchScreen.storyboard in Resources */,
- FC12E95220EB6BED00807EF4 /* model in Resources */,
- FC12E93B20EB6B2900807EF4 /* Assets.xcassets in Resources */,
- FC12E95120EB6BED00807EF4 /* params in Resources */,
- FC12E95420EB6C0D00807EF4 /* apple.jpg in Resources */,
- FC12E93920EB6B2800807EF4 /* Main.storyboard in Resources */,
- );
- runOnlyForDeploymentPostprocessing = 0;
- };
-/* End PBXResourcesBuildPhase section */
-
-/* Begin PBXSourcesBuildPhase section */
- FC12E92A20EB6B2800807EF4 /* Sources */ = {
- isa = PBXSourcesBuildPhase;
- buildActionMask = 2147483647;
- files = (
- FC12E93620EB6B2800807EF4 /* ViewController.m in Sources */,
- FC12E94120EB6B2900807EF4 /* main.m in Sources */,
- FC12E93320EB6B2800807EF4 /* AppDelegate.m in Sources */,
- );
- runOnlyForDeploymentPostprocessing = 0;
- };
-/* End PBXSourcesBuildPhase section */
-
-/* Begin PBXVariantGroup section */
- FC12E93720EB6B2800807EF4 /* Main.storyboard */ = {
- isa = PBXVariantGroup;
- children = (
- FC12E93820EB6B2800807EF4 /* Base */,
- );
- name = Main.storyboard;
- sourceTree = "";
- };
- FC12E93C20EB6B2900807EF4 /* LaunchScreen.storyboard */ = {
- isa = PBXVariantGroup;
- children = (
- FC12E93D20EB6B2900807EF4 /* Base */,
- );
- name = LaunchScreen.storyboard;
- sourceTree = "";
- };
-/* End PBXVariantGroup section */
-
-/* Begin XCBuildConfiguration section */
- FC12E94220EB6B2900807EF4 /* Debug */ = {
- isa = XCBuildConfiguration;
- buildSettings = {
- ALWAYS_SEARCH_USER_PATHS = NO;
- CLANG_ANALYZER_NONNULL = YES;
- CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
- CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
- CLANG_CXX_LIBRARY = "libc++";
- CLANG_ENABLE_MODULES = YES;
- CLANG_ENABLE_OBJC_ARC = YES;
- CLANG_ENABLE_OBJC_WEAK = YES;
- CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
- CLANG_WARN_BOOL_CONVERSION = YES;
- CLANG_WARN_COMMA = YES;
- CLANG_WARN_CONSTANT_CONVERSION = YES;
- CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
- CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
- CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
- CLANG_WARN_EMPTY_BODY = YES;
- CLANG_WARN_ENUM_CONVERSION = YES;
- CLANG_WARN_INFINITE_RECURSION = YES;
- CLANG_WARN_INT_CONVERSION = YES;
- CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
- CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
- CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
- CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
- CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
- CLANG_WARN_STRICT_PROTOTYPES = YES;
- CLANG_WARN_SUSPICIOUS_MOVE = YES;
- CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
- CLANG_WARN_UNREACHABLE_CODE = YES;
- CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
- CODE_SIGN_IDENTITY = "iPhone Developer";
- COPY_PHASE_STRIP = NO;
- DEBUG_INFORMATION_FORMAT = dwarf;
- ENABLE_STRICT_OBJC_MSGSEND = YES;
- ENABLE_TESTABILITY = YES;
- GCC_C_LANGUAGE_STANDARD = gnu11;
- GCC_DYNAMIC_NO_PIC = NO;
- GCC_NO_COMMON_BLOCKS = YES;
- GCC_OPTIMIZATION_LEVEL = 0;
- GCC_PREPROCESSOR_DEFINITIONS = (
- "DEBUG=1",
- "$(inherited)",
- );
- GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
- GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
- GCC_WARN_UNDECLARED_SELECTOR = YES;
- GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
- GCC_WARN_UNUSED_FUNCTION = YES;
- GCC_WARN_UNUSED_VARIABLE = YES;
- IPHONEOS_DEPLOYMENT_TARGET = 11.4;
- MTL_ENABLE_DEBUG_INFO = YES;
- ONLY_ACTIVE_ARCH = YES;
- SDKROOT = iphoneos;
- };
- name = Debug;
- };
- FC12E94320EB6B2900807EF4 /* Release */ = {
- isa = XCBuildConfiguration;
- buildSettings = {
- ALWAYS_SEARCH_USER_PATHS = NO;
- CLANG_ANALYZER_NONNULL = YES;
- CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
- CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
- CLANG_CXX_LIBRARY = "libc++";
- CLANG_ENABLE_MODULES = YES;
- CLANG_ENABLE_OBJC_ARC = YES;
- CLANG_ENABLE_OBJC_WEAK = YES;
- CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
- CLANG_WARN_BOOL_CONVERSION = YES;
- CLANG_WARN_COMMA = YES;
- CLANG_WARN_CONSTANT_CONVERSION = YES;
- CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
- CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
- CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
- CLANG_WARN_EMPTY_BODY = YES;
- CLANG_WARN_ENUM_CONVERSION = YES;
- CLANG_WARN_INFINITE_RECURSION = YES;
- CLANG_WARN_INT_CONVERSION = YES;
- CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
- CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
- CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
- CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
- CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
- CLANG_WARN_STRICT_PROTOTYPES = YES;
- CLANG_WARN_SUSPICIOUS_MOVE = YES;
- CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
- CLANG_WARN_UNREACHABLE_CODE = YES;
- CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
- CODE_SIGN_IDENTITY = "iPhone Developer";
- COPY_PHASE_STRIP = NO;
- DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
- ENABLE_NS_ASSERTIONS = NO;
- ENABLE_STRICT_OBJC_MSGSEND = YES;
- GCC_C_LANGUAGE_STANDARD = gnu11;
- GCC_NO_COMMON_BLOCKS = YES;
- GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
- GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
- GCC_WARN_UNDECLARED_SELECTOR = YES;
- GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
- GCC_WARN_UNUSED_FUNCTION = YES;
- GCC_WARN_UNUSED_VARIABLE = YES;
- IPHONEOS_DEPLOYMENT_TARGET = 11.4;
- MTL_ENABLE_DEBUG_INFO = NO;
- SDKROOT = iphoneos;
- VALIDATE_PRODUCT = YES;
- };
- name = Release;
- };
- FC12E94520EB6B2900807EF4 /* Debug */ = {
- isa = XCBuildConfiguration;
- buildSettings = {
- ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
- CODE_SIGN_STYLE = Automatic;
- DEVELOPMENT_TEAM = Z5M2UUN5YV;
- ENABLE_BITCODE = NO;
- INFOPLIST_FILE = PaddleMobileDemo/Info.plist;
- IPHONEOS_DEPLOYMENT_TARGET = 10.0;
- LD_RUNPATH_SEARCH_PATHS = (
- "$(inherited)",
- "@executable_path/Frameworks",
- );
- LIBRARY_SEARCH_PATHS = (
- "$(inherited)",
- "$(PROJECT_DIR)/PaddleMobileDemo/PaddleMobile",
- );
- PRODUCT_BUNDLE_IDENTIFIER = orange.PaddleMobileDemo;
- PRODUCT_NAME = "$(TARGET_NAME)";
- TARGETED_DEVICE_FAMILY = "1,2";
- };
- name = Debug;
- };
- FC12E94620EB6B2900807EF4 /* Release */ = {
- isa = XCBuildConfiguration;
- buildSettings = {
- ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
- CODE_SIGN_STYLE = Automatic;
- DEVELOPMENT_TEAM = Z5M2UUN5YV;
- ENABLE_BITCODE = NO;
- INFOPLIST_FILE = PaddleMobileDemo/Info.plist;
- IPHONEOS_DEPLOYMENT_TARGET = 10.0;
- LD_RUNPATH_SEARCH_PATHS = (
- "$(inherited)",
- "@executable_path/Frameworks",
- );
- LIBRARY_SEARCH_PATHS = (
- "$(inherited)",
- "$(PROJECT_DIR)/PaddleMobileDemo/PaddleMobile",
- );
- PRODUCT_BUNDLE_IDENTIFIER = orange.PaddleMobileDemo;
- PRODUCT_NAME = "$(TARGET_NAME)";
- TARGETED_DEVICE_FAMILY = "1,2";
- };
- name = Release;
- };
-/* End XCBuildConfiguration section */
-
-/* Begin XCConfigurationList section */
- FC12E92920EB6B2800807EF4 /* Build configuration list for PBXProject "PaddleMobileDemo" */ = {
- isa = XCConfigurationList;
- buildConfigurations = (
- FC12E94220EB6B2900807EF4 /* Debug */,
- FC12E94320EB6B2900807EF4 /* Release */,
- );
- defaultConfigurationIsVisible = 0;
- defaultConfigurationName = Release;
- };
- FC12E94420EB6B2900807EF4 /* Build configuration list for PBXNativeTarget "PaddleMobileDemo" */ = {
- isa = XCConfigurationList;
- buildConfigurations = (
- FC12E94520EB6B2900807EF4 /* Debug */,
- FC12E94620EB6B2900807EF4 /* Release */,
- );
- defaultConfigurationIsVisible = 0;
- defaultConfigurationName = Release;
- };
-/* End XCConfigurationList section */
- };
- rootObject = FC12E92620EB6B2800807EF4 /* Project object */;
-}
diff --git a/demo/ios/PaddleMobileDemo/PaddleMobileDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/demo/ios/PaddleMobileDemo/PaddleMobileDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata
deleted file mode 100644
index e4db9529ba656814e6a2bd889426662d914277eb..0000000000000000000000000000000000000000
--- a/demo/ios/PaddleMobileDemo/PaddleMobileDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata
+++ /dev/null
@@ -1,7 +0,0 @@
-
-
-
-
-
diff --git a/demo/ios/PaddleMobileDemo/PaddleMobileDemo.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/demo/ios/PaddleMobileDemo/PaddleMobileDemo.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
deleted file mode 100644
index 18d981003d68d0546c4804ac2ff47dd97c6e7921..0000000000000000000000000000000000000000
--- a/demo/ios/PaddleMobileDemo/PaddleMobileDemo.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-
-
- IDEDidComputeMac32BitWarning
-
-
-
diff --git a/demo/ios/PaddleMobileDemo/PaddleMobileDemo.xcodeproj/project.xcworkspace/xcuserdata/liuruilong.xcuserdatad/UserInterfaceState.xcuserstate b/demo/ios/PaddleMobileDemo/PaddleMobileDemo.xcodeproj/project.xcworkspace/xcuserdata/liuruilong.xcuserdatad/UserInterfaceState.xcuserstate
deleted file mode 100644
index 395136a63bb50378df8c37256880d4bbf9fd2f83..0000000000000000000000000000000000000000
Binary files a/demo/ios/PaddleMobileDemo/PaddleMobileDemo.xcodeproj/project.xcworkspace/xcuserdata/liuruilong.xcuserdatad/UserInterfaceState.xcuserstate and /dev/null differ
diff --git a/demo/ios/PaddleMobileDemo/PaddleMobileDemo.xcodeproj/xcuserdata/liuruilong.xcuserdatad/xcschemes/xcschememanagement.plist b/demo/ios/PaddleMobileDemo/PaddleMobileDemo.xcodeproj/xcuserdata/liuruilong.xcuserdatad/xcschemes/xcschememanagement.plist
deleted file mode 100644
index 7caa9222e77f1e53c0ee45c298aacb330e870688..0000000000000000000000000000000000000000
--- a/demo/ios/PaddleMobileDemo/PaddleMobileDemo.xcodeproj/xcuserdata/liuruilong.xcuserdatad/xcschemes/xcschememanagement.plist
+++ /dev/null
@@ -1,14 +0,0 @@
-
-
-
-
- SchemeUserState
-
- PaddleMobileDemo.xcscheme
-
- orderHint
- 0
-
-
-
-
diff --git a/demo/ios/PaddleMobileDemo/PaddleMobileDemo/AppDelegate.h b/demo/ios/PaddleMobileDemo/PaddleMobileDemo/AppDelegate.h
deleted file mode 100644
index 0d2e035ab3c44617694f9ebe437d1a7289be0390..0000000000000000000000000000000000000000
--- a/demo/ios/PaddleMobileDemo/PaddleMobileDemo/AppDelegate.h
+++ /dev/null
@@ -1,23 +0,0 @@
-/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
-
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License. */
-
-#import
-
-@interface AppDelegate : UIResponder
-
-@property (strong, nonatomic) UIWindow *window;
-
-
-@end
-
diff --git a/demo/ios/PaddleMobileDemo/PaddleMobileDemo/AppDelegate.m b/demo/ios/PaddleMobileDemo/PaddleMobileDemo/AppDelegate.m
deleted file mode 100644
index 6644c3c079ae1748de28a634b78c344640cd335a..0000000000000000000000000000000000000000
--- a/demo/ios/PaddleMobileDemo/PaddleMobileDemo/AppDelegate.m
+++ /dev/null
@@ -1,57 +0,0 @@
-/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
-
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License. */
-
-#import "AppDelegate.h"
-
-@interface AppDelegate ()
-
-@end
-
-@implementation AppDelegate
-
-
-- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
- // Override point for customization after application launch.
- return YES;
-}
-
-
-- (void)applicationWillResignActive:(UIApplication *)application {
- // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
- // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
-}
-
-
-- (void)applicationDidEnterBackground:(UIApplication *)application {
- // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
- // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
-}
-
-
-- (void)applicationWillEnterForeground:(UIApplication *)application {
- // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
-}
-
-
-- (void)applicationDidBecomeActive:(UIApplication *)application {
- // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
-}
-
-
-- (void)applicationWillTerminate:(UIApplication *)application {
- // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
-}
-
-
-@end
diff --git a/demo/ios/PaddleMobileDemo/PaddleMobileDemo/Assets.xcassets/AppIcon.appiconset/Contents.json b/demo/ios/PaddleMobileDemo/PaddleMobileDemo/Assets.xcassets/AppIcon.appiconset/Contents.json
deleted file mode 100644
index d8db8d65fd79fd541b2b7eba75c7378af3448f9c..0000000000000000000000000000000000000000
--- a/demo/ios/PaddleMobileDemo/PaddleMobileDemo/Assets.xcassets/AppIcon.appiconset/Contents.json
+++ /dev/null
@@ -1,98 +0,0 @@
-{
- "images" : [
- {
- "idiom" : "iphone",
- "size" : "20x20",
- "scale" : "2x"
- },
- {
- "idiom" : "iphone",
- "size" : "20x20",
- "scale" : "3x"
- },
- {
- "idiom" : "iphone",
- "size" : "29x29",
- "scale" : "2x"
- },
- {
- "idiom" : "iphone",
- "size" : "29x29",
- "scale" : "3x"
- },
- {
- "idiom" : "iphone",
- "size" : "40x40",
- "scale" : "2x"
- },
- {
- "idiom" : "iphone",
- "size" : "40x40",
- "scale" : "3x"
- },
- {
- "idiom" : "iphone",
- "size" : "60x60",
- "scale" : "2x"
- },
- {
- "idiom" : "iphone",
- "size" : "60x60",
- "scale" : "3x"
- },
- {
- "idiom" : "ipad",
- "size" : "20x20",
- "scale" : "1x"
- },
- {
- "idiom" : "ipad",
- "size" : "20x20",
- "scale" : "2x"
- },
- {
- "idiom" : "ipad",
- "size" : "29x29",
- "scale" : "1x"
- },
- {
- "idiom" : "ipad",
- "size" : "29x29",
- "scale" : "2x"
- },
- {
- "idiom" : "ipad",
- "size" : "40x40",
- "scale" : "1x"
- },
- {
- "idiom" : "ipad",
- "size" : "40x40",
- "scale" : "2x"
- },
- {
- "idiom" : "ipad",
- "size" : "76x76",
- "scale" : "1x"
- },
- {
- "idiom" : "ipad",
- "size" : "76x76",
- "scale" : "2x"
- },
- {
- "idiom" : "ipad",
- "size" : "83.5x83.5",
- "scale" : "2x"
- },
- {
- "idiom" : "ios-marketing",
- "size" : "1024x1024",
- "scale" : "1x"
- }
- ],
- "info" : {
- "version" : 1,
- "author" : "xcode"
- }
-}
\ No newline at end of file
diff --git a/demo/ios/PaddleMobileDemo/PaddleMobileDemo/Assets.xcassets/Contents.json b/demo/ios/PaddleMobileDemo/PaddleMobileDemo/Assets.xcassets/Contents.json
deleted file mode 100644
index da4a164c918651cdd1e11dca5cc62c333f097601..0000000000000000000000000000000000000000
--- a/demo/ios/PaddleMobileDemo/PaddleMobileDemo/Assets.xcassets/Contents.json
+++ /dev/null
@@ -1,6 +0,0 @@
-{
- "info" : {
- "version" : 1,
- "author" : "xcode"
- }
-}
\ No newline at end of file
diff --git a/demo/ios/PaddleMobileDemo/PaddleMobileDemo/Base.lproj/LaunchScreen.storyboard b/demo/ios/PaddleMobileDemo/PaddleMobileDemo/Base.lproj/LaunchScreen.storyboard
deleted file mode 100644
index f83f6fd5810b9c852cf98563d82d5ed1e84ff893..0000000000000000000000000000000000000000
--- a/demo/ios/PaddleMobileDemo/PaddleMobileDemo/Base.lproj/LaunchScreen.storyboard
+++ /dev/null
@@ -1,25 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/demo/ios/PaddleMobileDemo/PaddleMobileDemo/Base.lproj/Main.storyboard b/demo/ios/PaddleMobileDemo/PaddleMobileDemo/Base.lproj/Main.storyboard
deleted file mode 100644
index d7c78a1255c016bde922c849eef8555881c207b6..0000000000000000000000000000000000000000
--- a/demo/ios/PaddleMobileDemo/PaddleMobileDemo/Base.lproj/Main.storyboard
+++ /dev/null
@@ -1,24 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/demo/ios/PaddleMobileDemo/PaddleMobileDemo/Info.plist b/demo/ios/PaddleMobileDemo/PaddleMobileDemo/Info.plist
deleted file mode 100644
index 16be3b681122de83e380d47b840b7d0486f71f86..0000000000000000000000000000000000000000
--- a/demo/ios/PaddleMobileDemo/PaddleMobileDemo/Info.plist
+++ /dev/null
@@ -1,45 +0,0 @@
-
-
-
-
- CFBundleDevelopmentRegion
- $(DEVELOPMENT_LANGUAGE)
- CFBundleExecutable
- $(EXECUTABLE_NAME)
- CFBundleIdentifier
- $(PRODUCT_BUNDLE_IDENTIFIER)
- CFBundleInfoDictionaryVersion
- 6.0
- CFBundleName
- $(PRODUCT_NAME)
- CFBundlePackageType
- APPL
- CFBundleShortVersionString
- 1.0
- CFBundleVersion
- 1
- LSRequiresIPhoneOS
-
- UILaunchStoryboardName
- LaunchScreen
- UIMainStoryboardFile
- Main
- UIRequiredDeviceCapabilities
-
- armv7
-
- UISupportedInterfaceOrientations
-
- UIInterfaceOrientationPortrait
- UIInterfaceOrientationLandscapeLeft
- UIInterfaceOrientationLandscapeRight
-
- UISupportedInterfaceOrientations~ipad
-
- UIInterfaceOrientationPortrait
- UIInterfaceOrientationPortraitUpsideDown
- UIInterfaceOrientationLandscapeLeft
- UIInterfaceOrientationLandscapeRight
-
-
-
diff --git a/demo/ios/PaddleMobileDemo/PaddleMobileDemo/PaddleMobile/PaddleMobile.h b/demo/ios/PaddleMobileDemo/PaddleMobileDemo/PaddleMobile/PaddleMobile.h
deleted file mode 100644
index ec58371de032c265b2c32a5bac61ca6cf682ff28..0000000000000000000000000000000000000000
--- a/demo/ios/PaddleMobileDemo/PaddleMobileDemo/PaddleMobile/PaddleMobile.h
+++ /dev/null
@@ -1,26 +0,0 @@
-/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License. */
-
-#import
-#import
-
-@interface PaddleMobile : NSObject
-
-- (instancetype)init;
-- (BOOL)load:(NSString *)modelPath andWeightsPath:(NSString *)weighsPath;
-- (NSArray *)predict:(CGImageRef)image dim:(NSArray *)dim means:(NSArray *)means scale:(float)scale;
-- (NSArray *)predict:(CGImageRef)image dim:(NSArray *)dim;
-- (void)clear;
-
-@end
diff --git a/demo/ios/PaddleMobileDemo/PaddleMobileDemo/ViewController.h b/demo/ios/PaddleMobileDemo/PaddleMobileDemo/ViewController.h
deleted file mode 100644
index 41e22092711c4fd1def105470c5b6610cce2257a..0000000000000000000000000000000000000000
--- a/demo/ios/PaddleMobileDemo/PaddleMobileDemo/ViewController.h
+++ /dev/null
@@ -1,21 +0,0 @@
-/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
-
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License. */
-
-#import
-
-@interface ViewController : UIViewController
-
-
-@end
-
diff --git a/demo/ios/PaddleMobileDemo/PaddleMobileDemo/ViewController.m b/demo/ios/PaddleMobileDemo/PaddleMobileDemo/ViewController.m
deleted file mode 100644
index eb9f7d2bb5329ac4bbf8b790dc83c256f164ec64..0000000000000000000000000000000000000000
--- a/demo/ios/PaddleMobileDemo/PaddleMobileDemo/ViewController.m
+++ /dev/null
@@ -1,49 +0,0 @@
-/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
-
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License. */
-
-#import "PaddleMobile.h"
-#import "ViewController.h"
-
-@interface ViewController ()
-
-@end
-
-@implementation ViewController
-
-- (void)viewDidLoad {
- [super viewDidLoad];
- PaddleMobile *pam = [[PaddleMobile alloc] init];
- NSString *modelPath = [[NSBundle mainBundle] pathForResource:@"model" ofType:nil];
- NSString *paramPath = [[NSBundle mainBundle] pathForResource:@"params" ofType:nil];
- if (modelPath.length == 0 || paramPath.length == 0) {
- NSLog(@" need model and param");
- return;
- }
-
- if ([pam load:modelPath andWeightsPath:paramPath]) {
- NSLog(@"load success");
- UIImage *inputImage = [UIImage imageNamed:@"apple.jpg"];
- if (!inputImage) {
- NSLog(@" input image is nil");
- return;
- }
-
- NSDate *beforeDate = [NSDate date];
- NSArray *res = [pam predict:inputImage.CGImage dim:@[@1, @3, @224, @224] means:@[@148, @148, @148] scale:1.0];
- NSLog(@"res: %@", res);
- NSLog(@"elapsed time: %f", [[NSDate date] timeIntervalSinceDate:beforeDate]);
- }
-}
-
-@end
diff --git a/demo/ios/PaddleMobileDemo/PaddleMobileDemo/main.m b/demo/ios/PaddleMobileDemo/PaddleMobileDemo/main.m
deleted file mode 100644
index cf2cf6aa80b1d3d3c0480b54a668780ea3324c8b..0000000000000000000000000000000000000000
--- a/demo/ios/PaddleMobileDemo/PaddleMobileDemo/main.m
+++ /dev/null
@@ -1,22 +0,0 @@
-/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
-
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License. */
-
-#import
-#import "AppDelegate.h"
-
-int main(int argc, char * argv[]) {
- @autoreleasepool {
- return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
- }
-}
diff --git a/doc/build.md b/doc/build.md
index 6a8521b593ccdeab464687e7eae79192d131d51b..1c1c906458a0dd5f525c9d5153d48356b907b23b 100644
--- a/doc/build.md
+++ b/doc/build.md
@@ -19,9 +19,14 @@ paddle-mobile dev 33b146787711 45 hours ago 372MB
```
$ docker run -it --mount type=bind,source=$PWD,target=/paddle-mobile paddle-mobile:dev
root@5affd29d4fc5:/ # cd /paddle-mobile
+###
+### paddle-mobile 支持 arm 架构下的各种平台,包括 android 以及 linux 等,可以使用不同的
+### toolchain 文件生成满足需要的 makefile
+###
# 生成构建 android 产出的 Makefile
root@5affd29d4fc5:/ # rm CMakeCache.txt
root@5affd29d4fc5:/ # cmake -DCMAKE_TOOLCHAIN_FILE=tools/toolchains/arm-android-neon.cmake
+
# 生成构建 linux 产出的 Makefile
root@5affd29d4fc5:/ # rm CMakeCache.txt
root@5affd29d4fc5:/ # cmake -DCMAKE_TOOLCHAIN_FILE=tools/toolchains/arm-linux-gnueabi.cmake
@@ -56,4 +61,4 @@ root@5affd29d4fc5:/ # make
构架产出可以在 host 机器上查看,在 paddle-mobile 的目录下,build 以及 test/build 下,可以使用 adb 指令或者 scp 传输到 device 上执行
## 不使用 docker
-不使用 docker 的方法,可以直接用 cmake 生成 makefile 后构建。使用 ndk 构建 android 应用需要正确设置 NDK_ROOT。构建 linux 应用需要安装 arm-linux-gnueabi-gcc 或者类似的交叉编译工具,可能需要设置 CC,CXX 环境变量,或者在 tools/toolchains/ 中修改 arm-linux-gnueabi.cmake,或者增加自己需要的 toolchain file。
\ No newline at end of file
+不使用 docker 的方法,可以直接用 cmake 生成 makefile 后构建。使用 ndk 构建 android 应用需要正确设置 NDK_ROOT。构建 linux 应用需要安装 arm-linux-gnueabi-gcc 或者类似的交叉编译工具,可能需要设置 CC,CXX 环境变量,或者在 tools/toolchains/ 中修改 arm-linux-gnueabi.cmake,或者增加自己需要的 toolchain file。
diff --git a/doc/development_doc.md b/doc/development_doc.md
index 90f07a65ffe00bd20a8277dce97286d92875670b..3f45f956f00e78c23b60b4c108b8c90cf4065e04 100644
--- a/doc/development_doc.md
+++ b/doc/development_doc.md
@@ -4,9 +4,11 @@
## 编译
-### 一. 使用 build.sh 编译
-
```sh
+
+# 在 paddle-mobile 目录下:
+cd tools
+
sh build.sh ios
# 如果只想编译某个特定模型的 op, 则需执行以下命令
@@ -16,10 +18,14 @@ sh build.sh ios googlenet
cd ../build/release/ios/build
```
+#### 常见问题:
+
+1. No iOS SDK's found in default search path ...
-### 二. 集成
+ 这个问题是因为 tools/ios-cmake/ios.toolchain.cmake 找不到你最近使用的 iOS SDK 路径, 所以需要自己进行指定,
+ 以我当前的环境为例: 在 tools/ios-cmake/ios.toolchain.cmake 143行前添加我本地的 iOS SDK 路径: set(CMAKE_IOS_SDK_ROOT "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk")
-#### 如使用 oc 接口
+## 集成
```
将上一步生成的:
@@ -28,7 +34,11 @@ libpaddle-mobile.a
/src/ios_io/ 下的
PaddleMobile.h
```
-拖入工程, 接口如下:
+拖入工程
+
+#### oc 接口
+
+接口如下:
```
/*
@@ -133,11 +143,16 @@ root@5affd29d4fc5:/ # make
##### 下载Android NDK
从源码交叉编译paddle-mobile,用户需要提前准备好交叉编译环境。Android平台使用的C/C++交叉编译工具链是[Android NDK](https://developer.android.com/ndk/),用户可以自行前往下载,也可以通过以下命令获取:
-
+- Mac平台
```
wget https://dl.google.com/android/repository/android-ndk-r17b-darwin-x86_64.zip
unzip android-ndk-r17b-darwin-x86_64.zip
+```
+- Linux平台
+```
+wget https://dl.google.com/android/repository/android-ndk-r17b-linux-x86_64.zip
+unzip android-ndk-r17b-linux-x86_64.zip
```
##### 设置环境变量
@@ -182,27 +197,51 @@ which to test :
##部署
Android应用可通过JNI接口调用底层C/C++,paddle-mobile对外提供的JNI接口如下:
-##### 1 load接口 加载模型参数
-
+##### 1 load接口 加载模型参数
+- 用于加载参数文件分散的模型
```
-/*
-*@param modelPath 模型文件路径
-*@return jboolean
-*/
-JNIEXPORT jboolean JNICALL Java_com_baidu_paddle_PML_load(JNIEnv *env,
- jclass thiz,
- jstring modelPath);
+/**
+ * Load seperated parameters
+ * @param modelDir
+ * @return
+ */
+ public static native boolean load(String modelDir);
```
+- 用于加载参数文件合并的模型文件
+```
+/**
+ * Load combined parameters
+ * @param modelPath
+ * @param paramPath
+ * @return
+ */
+ public static native boolean loadCombined(String modelPath,String paramPath);
+```
##### 2 predict接口 执行预测
-
+- 接受预处理过的RGB数组的predict接口
```
/**
*@param buf 输入数据
*@return 输出数据
-JNIEXPORT jfloatArray JNICALL Java_com_baidu_paddle_PML_predict(
+JNIEXPORT jfloatArray JNICALL Java_com_baidu_paddle_PML_predictImage(
JNIEnv *env, jclass thiz, jfloatArray buf);
```
+- 接受原始yuv数据的predict接口
+```
+ /**
+ *
+ * @param buf yuv420格式的字节数组
+ * @param imgWidth yuv数据的宽
+ * @param imgHeight yuv数据的高
+ * @param ddims 输入数据的形状
+ * @param meanValues 模型训练时各通道的均值
+ * @return
+ */
+
+ public static native float[] predictYuv(byte[] buf, int imgWidth, int imgHeight, int[] ddims, float[]meanValues);
+
+```
##### 3 clear接口 销毁实例、清理内存操作
```
diff --git a/src/common/types.cpp b/src/common/types.cpp
index cea42171f0205e0d40b2703d5c90f0b9fc253e68..7b8b5bb559a29bd28c9789f3b52fa1b65cc14dc5 100644
--- a/src/common/types.cpp
+++ b/src/common/types.cpp
@@ -24,6 +24,8 @@ const std::string G_OP_TYPE_CONCAT = "concat";
const std::string G_OP_TYPE_ELEMENTWISE_ADD = "elementwise_add";
const std::string G_OP_TYPE_FUSION_CONV_ADD_RELU = "fusion_conv_add_relu";
const std::string G_OP_TYPE_FUSION_CONV_ADD_BN_RELU = "fusion_conv_add_bn_relu";
+const std::string G_OP_TYPE_FUSION_DWCONV_BN_RELU = "fusion_dwconv_bn_relu";
+const std::string G_OP_TYPE_FUSION_CONV_BN_RELU = "fusion_conv_bn_relu";
const std::string G_OP_TYPE_FC = "fusion_fc";
const std::string G_OP_TYPE_FUSION_CONV_ADD = "fusion_conv_add";
const std::string G_OP_TYPE_LRN = "lrn";
@@ -47,6 +49,8 @@ std::unordered_map<
std::string, std::pair, std::vector>>
op_input_output_key = {
{G_OP_TYPE_CONV, {{"Input"}, {"Output"}}},
+ {G_OP_TYPE_FUSION_DWCONV_BN_RELU, {{"Input"}, {"Out"}}},
+ {G_OP_TYPE_FUSION_CONV_BN_RELU, {{"Input"}, {"Out"}}},
{G_OP_TYPE_FUSION_CONV_ADD, {{"Input"}, {"Out"}}},
{G_OP_TYPE_RELU, {{"X"}, {"Out"}}},
{G_OP_TYPE_SOFTMAX, {{"X"}, {"Out"}}},
diff --git a/src/common/types.h b/src/common/types.h
index ec428b9911f64d7ccc8c6f5dc4be7f970e855d3c..627b7efac6ef6bee6dc96295e63ee8f0f96b7932 100644
--- a/src/common/types.h
+++ b/src/common/types.h
@@ -16,6 +16,7 @@ limitations under the License. */
#include
#include
+#include
#include
namespace paddle_mobile {
@@ -81,6 +82,8 @@ extern const std::string G_OP_TYPE_FUSION_CONV_ADD_RELU;
extern const std::string G_OP_TYPE_FC;
extern const std::string G_OP_TYPE_FUSION_CONV_ADD;
extern const std::string G_OP_TYPE_FUSION_CONV_ADD_BN_RELU;
+extern const std::string G_OP_TYPE_FUSION_DWCONV_BN_RELU;
+extern const std::string G_OP_TYPE_FUSION_CONV_BN_RELU;
extern const std::string G_OP_TYPE_LRN;
extern const std::string G_OP_TYPE_MUL;
diff --git a/src/common/variant.h b/src/common/variant.h
index b87a5e67a76f4c616f2c450ef4527bcf6c16286b..00b8eb985d8f7fc22bb93a3e229aa387c358e257 100644
--- a/src/common/variant.h
+++ b/src/common/variant.h
@@ -12,6 +12,8 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
+#include
+
#include "common/enforce.h"
#include "common/log.h"
@@ -82,7 +84,7 @@ struct Variant {
if (type_id == typeid(T).hash_code()) {
return *const_cast(reinterpret_cast(&data));
} else {
- PADDLE_MOBILE_THROW_EXCEPTION(" bad cast in variant ");
+ PADDLE_MOBILE_THROW_EXCEPTION(" bad cast in variant");
exit(0);
}
}
diff --git a/src/framework/attribute.h b/src/framework/attribute.h
index f0519a35b3ed2a02e35f1ef0d6a718efb7b76095..ed264057be6810d8bae29e0117fa4f6d91067cc1 100644
--- a/src/framework/attribute.h
+++ b/src/framework/attribute.h
@@ -14,6 +14,7 @@ limitations under the License. */
#pragma once
+#include
#include
#include
#include
diff --git a/src/framework/data_layout.h b/src/framework/data_layout.h
index f1249008f088dce48ed040e47900121c2eb41af1..0ba31ef9b7016b453b34cc4a023b0841b2110540 100644
--- a/src/framework/data_layout.h
+++ b/src/framework/data_layout.h
@@ -15,6 +15,7 @@ limitations under the License. */
#pragma once
#include
+#include
#include
namespace paddle_mobile {
diff --git a/src/framework/ddim.h b/src/framework/ddim.h
index 833bc2783f855fd9d6df50d21345539fbe2ca6c4..db240b260185bb8ac2ba1fe84d3390bedac5c36d 100644
--- a/src/framework/ddim.h
+++ b/src/framework/ddim.h
@@ -14,9 +14,11 @@ limitations under the License. */
#pragma once
+#include
#include
#include
#include
+
#include "common/enforce.h"
#include "common/variant.h"
#include "dim.h"
diff --git a/src/framework/dim.h b/src/framework/dim.h
index dd7610de65d4a4c93402cf49b0fdbdc7995610c0..0d3e86e92289da155843e1a9959d5ea67a73c060 100644
--- a/src/framework/dim.h
+++ b/src/framework/dim.h
@@ -14,6 +14,7 @@ limitations under the License. */
#pragma once
+#include
#include "common/enforce.h"
namespace paddle_mobile {
namespace framework {
diff --git a/src/framework/operator.cpp b/src/framework/operator.cpp
index 36b4663cb603d29bb60cfc297899d1c300e8ca91..765103c241a82ac224d707340f8b66ace827e335 100644
--- a/src/framework/operator.cpp
+++ b/src/framework/operator.cpp
@@ -28,6 +28,16 @@ vector OperatorBase::GetOutKeys() const {
return it->second.second;
}
+template
+vector OperatorBase::GetInputKeys() const {
+ auto it = op_input_output_key.find(type_);
+ if (it == op_input_output_key.end()) {
+ DLOG << type_ << " has no outputs";
+ return {};
+ }
+ return it->second.first;
+}
+
template
OperatorBase::OperatorBase(const std::string &type,
const VariableNameMap &inputs,
@@ -49,6 +59,11 @@ template
void OperatorBase::Run() const {
RunImpl();
#ifdef PADDLE_MOBILE_DEBUG
+ vector input_keys = GetInputKeys();
+ for (const auto key : input_keys) {
+ Tensor *input = GetVarValue(key, inputs_, *scope_);
+ DLOG << type_ << " input- " << key << "=" << *input;
+ }
vector output_keys = GetOutKeys();
for (const auto key : output_keys) {
Tensor *out_ = GetVarValue(key, outputs_, *scope_);
diff --git a/src/framework/operator.h b/src/framework/operator.h
index 793551b0cd3eea290243c156c27616a34c37a3d2..084ac3c81185fe489fe1ca67589c1e8edb1d4fdf 100644
--- a/src/framework/operator.h
+++ b/src/framework/operator.h
@@ -61,6 +61,7 @@ class OperatorBase {
virtual ~OperatorBase() {}
void Run() const;
std::vector GetOutKeys() const;
+ std::vector GetInputKeys() const;
virtual void RunImpl() const = 0;
virtual void Init() = 0;
@@ -118,6 +119,10 @@ class OperatorWithKernel : public OperatorBase {
virtual void InferShape() const = 0;
void Init() {
+ // for (auto i : this->inputs_) {
+ // DLOG << i.first;
+ // DLOG << i.second;
+ // }
PADDLE_MOBILE_ENFORCE(kernel_.Init(¶m_), " %s kernel init failed",
this->type_.c_str());
}
@@ -146,7 +151,7 @@ class OpKernelBase {
}
#endif
virtual void Compute(const P ¶) const = 0;
- virtual bool Init(P *para) { return true; };
+ virtual bool Init(P *para) { return true; }
virtual ~OpKernelBase() = default;
private:
diff --git a/src/framework/program/program-optimize/fusion_op_register.h b/src/framework/program/program-optimize/fusion_op_register.h
index 1cd6b1dd779f9bc9ff0f5be5513c4fa716d80b10..f16a65c28fb47e1cf4139588742ebe1073c3f3e6 100644
--- a/src/framework/program/program-optimize/fusion_op_register.h
+++ b/src/framework/program/program-optimize/fusion_op_register.h
@@ -42,8 +42,17 @@ class FusionOpRegister {
matchers_[matcher->Type()] = shared_matcher;
}
- const std::map> Matchers() {
- return matchers_;
+ const std::vector> Matchers() {
+ std::vector> matchers;
+ for (const auto& match : matchers_) {
+ matchers.push_back(match.second);
+ }
+ std::sort(matchers.begin(), matchers.end(),
+ [](std::shared_ptr first,
+ std::shared_ptr second) {
+ return first->BeginNode().Depth() > second->BeginNode().Depth();
+ });
+ return matchers;
}
private:
diff --git a/src/framework/program/program-optimize/node.cpp b/src/framework/program/program-optimize/node.cpp
index e635e07eaf4484c3e390101c3b43fdaf24bbd2c6..a4e1db506da362df4fb61b39827d5e77ebc425eb 100644
--- a/src/framework/program/program-optimize/node.cpp
+++ b/src/framework/program/program-optimize/node.cpp
@@ -44,23 +44,6 @@ bool Node::operator==(const Node &in) {
return true;
}
-std::vector> Node::OpDescs(int size) {
- std::vector> op_descs;
- OpDescs(size - 1, &op_descs);
- return op_descs;
-}
-
-void Node::OpDescs(int index,
- std::vector> *op_desc) {
- if (index == 0) {
- return;
- }
- op_desc->push_back(this->op_desc_);
- for (auto &output : outputs_) {
- output->OpDescs(index, op_desc);
- }
-}
-
std::shared_ptr Node::To(int size) {
std::shared_ptr node = std::make_shared();
this->To(size - 1, node);
diff --git a/src/framework/program/program-optimize/node.h b/src/framework/program/program-optimize/node.h
index 88bf1e16ed2a5fb3a038eadd546d63ffb3916f68..7eb179c243c28fe2668c3cf2f8f28f81312c0988 100644
--- a/src/framework/program/program-optimize/node.h
+++ b/src/framework/program/program-optimize/node.h
@@ -47,13 +47,10 @@ class Node {
std::map>>
change,
std::vector> *removed_nodes);
- std::vector> OpDescs(int size);
std::shared_ptr OpDescOfNode() { return op_desc_; }
std::string Type() { return type_; }
private:
- void OpDescs(int size,
- std::vector> *op_desc);
void To(int index, std::shared_ptr);
void Folder(
std::shared_ptr op_desc,
diff --git a/src/framework/program/program-optimize/program_optimize.cpp b/src/framework/program/program-optimize/program_optimize.cpp
index 3619bc79f576651245aa322992df9d318c810cd4..82d33bc65d864e010fbe41b270b71ed98a21b33e 100644
--- a/src/framework/program/program-optimize/program_optimize.cpp
+++ b/src/framework/program/program-optimize/program_optimize.cpp
@@ -78,9 +78,8 @@ std::shared_ptr ProgramOptimize::FusionOptimize(
}
for (auto ®isted : FusionOpRegister::Instance()->Matchers()) {
- std::string fusion_type = registed.first;
- std::shared_ptr matcher = registed.second;
- // DLOG << " registed node \n " << matcher->BeginNode();
+ std::string fusion_type = registed->Type();
+ std::shared_ptr matcher = registed;
auto match_vector = type_map[matcher->BeginType()];
diff --git a/src/framework/program/program.h b/src/framework/program/program.h
index 5760efc826667d805695118b12e41efa0305553b..e500d500344d83204bf388401541259b90ea2f78 100644
--- a/src/framework/program/program.h
+++ b/src/framework/program/program.h
@@ -30,6 +30,7 @@ class Program {
std::string model_path;
std::string para_path;
bool combined = false;
+ bool quantification = false;
private:
};
diff --git a/src/framework/tensor.h b/src/framework/tensor.h
index 9bbd81aa30f6fa0188dacd0dce01813e17b9e339..56e6d6bf18740489c195a66db70331cbab42aeea 100644
--- a/src/framework/tensor.h
+++ b/src/framework/tensor.h
@@ -152,7 +152,7 @@ class Tensor {
if (holder_ != nullptr) {
holder_->set_type(type);
}
- PADDLE_MOBILE_ENFORCE(numel() >= 0, "the Tensor'snumel must >=0.")
+ PADDLE_MOBILE_ENFORCE(numel() >= 0, "the Tensor's numel must >=0.")
int64_t size = numel() * SizeOfType(type);
if (holder_ == nullptr || holder_->size() < size + offset_) {
holder_.reset(new PlaceholderImpl(size, type));
diff --git a/src/io/executor.cpp b/src/io/executor.cpp
index 82c3eae5d92fac19b2ed94fb587497236afd917d..65f019d1e3c3f6f6bdb8a18a9ff99bb7ecb2012c 100644
--- a/src/io/executor.cpp
+++ b/src/io/executor.cpp
@@ -13,6 +13,7 @@ See the License for the specific language governing permissions and
limitations under the License. */
#include "io/executor.h"
+#include
#include
#include
#include "common/enforce.h"
@@ -153,7 +154,7 @@ void Executor::LoadMemory(const framework::VarDesc var_desc,
tensor->Resize(framework::make_ddim(desc.Dims()));
- void *memory = tensor;
+ void *memory = nullptr;
int type_size = 0;
switch (desc.DataType()) {
case framework::VARTYPE_TYPE_FP16:
@@ -178,11 +179,25 @@ void Executor::LoadMemory(const framework::VarDesc var_desc,
default:
break;
}
-
- for (int n = 0; n < memory_size * type_size; ++n) {
- static_cast(memory)[n] = (*data)[n];
+ if (program_.quantification) {
+ float min_value;
+ float max_value;
+
+ memcpy(&min_value, *data, sizeof(float));
+ memcpy(&max_value, *data + sizeof(float), sizeof(float));
+ *data += 2 * sizeof(float);
+ const float factor = (max_value - min_value) / 255.0;
+ uint8_t *uint8_data = (uint8_t *)(*data);
+ for (int k = 0; k < memory_size; ++k) {
+ static_cast(memory)[k] = uint8_data[k] * factor + min_value;
+ }
+ *data += (memory_size * sizeof(uint8_t));
+ } else {
+ for (int n = 0; n < memory_size * type_size; ++n) {
+ static_cast(memory)[n] = (*data)[n];
+ }
+ (*data) += (sizeof(char) * memory_size * type_size);
}
- (*data) += (sizeof(char) * memory_size * type_size);
}
template
diff --git a/src/io/loader.cpp b/src/io/loader.cpp
index 51e007a6ab4bce415628649a40f711903bceee92..9ed877d05d51dfbe7139ea2289fdb6480c62f88f 100644
--- a/src/io/loader.cpp
+++ b/src/io/loader.cpp
@@ -44,26 +44,29 @@ static size_t ReadBuffer(const char *file_name, uint8_t **out) {
template
const framework::Program Loader::Load(
- const std::string &dirname, bool optimize, bool can_add_split) {
- auto program =
- this->LoadProgram(dirname + "/__model__", optimize, can_add_split);
+ const std::string &dirname, bool optimize, bool quantification,
+ bool can_add_split) {
+ auto program = this->LoadProgram(dirname + "/__model__", optimize,
+ quantification, can_add_split);
program.model_path = dirname;
return program;
}
template
const framework::Program Loader::Load(
- const std::string &model_path, const std::string ¶_path,
- bool optimize) {
+ const std::string &model_path, const std::string ¶_path, bool optimize,
+ bool quantification) {
auto program = this->LoadProgram(model_path, optimize);
program.para_path = para_path;
program.combined = true;
+ program.quantification = quantification;
return program;
}
template
const framework::Program Loader::LoadProgram(
- const std::string &model_path, bool optimize, bool can_add_split) {
+ const std::string &model_path, bool optimize, bool quantification,
+ bool can_add_split) {
std::string model_filename = model_path;
PaddleMobile__Framework__Proto__ProgramDesc *c_program;
uint8_t *buf = NULL;
@@ -82,6 +85,7 @@ const framework::Program Loader::LoadProgram(
framework::Program program;
program.originProgram = originProgramDesc;
+ program.quantification = quantification;
auto scope = std::make_shared();
program.scope = scope;
diff --git a/src/io/loader.h b/src/io/loader.h
index 5e3c53dc9db858f506a13d2105339038340344a6..512cee831f0a09f8223c07c531eb9d1c74e75d92 100644
--- a/src/io/loader.h
+++ b/src/io/loader.h
@@ -30,6 +30,7 @@ class Loader {
* */
const framework::Program Load(const std::string &dirname,
bool optimize = false,
+ bool quantification = false,
bool can_add_split = false);
/*
@@ -38,11 +39,13 @@ class Loader {
* */
const framework::Program Load(const std::string &model_path,
const std::string ¶_path,
- bool optimize = false);
+ bool optimize = false,
+ bool quantification = false);
private:
const framework::Program LoadProgram(const std::string &model_path,
bool optimize = false,
+ bool quantification = false,
bool can_add_split = false);
};
diff --git a/src/io/paddle_mobile.cpp b/src/io/paddle_mobile.cpp
index 3d5735f8da66db6f4b5f139f8261a4cd9cf0f796..5e2e209d64aa7a00b56a5bdbbff88cb3097b7b94 100644
--- a/src/io/paddle_mobile.cpp
+++ b/src/io/paddle_mobile.cpp
@@ -16,9 +16,17 @@ limitations under the License. */
namespace paddle_mobile {
+template
+void PaddleMobile::SetThreadNum(int num) {
+#ifdef _OPENMP
+ // omp_set_dynamic(0);
+ omp_set_num_threads(num);
+#endif
+};
+
template
bool PaddleMobile::Load(const std::string &dirname, bool optimize,
- int batch_size) {
+ bool quantification, int batch_size) {
if (loader_.get() == nullptr) {
loader_ = std::make_shared>();
} else {
@@ -27,7 +35,7 @@ bool PaddleMobile::Load(const std::string &dirname, bool optimize,
if (executor_.get() == nullptr) {
executor_ = std::make_shared>(
- loader_->Load(dirname, optimize), batch_size, optimize);
+ loader_->Load(dirname, optimize, quantification), batch_size, optimize);
} else {
LOG(kLOG_INFO) << "executor inited";
}
@@ -38,7 +46,7 @@ bool PaddleMobile::Load(const std::string &dirname, bool optimize,
template
bool PaddleMobile::Load(const std::string &model_path,
const std::string ¶_path, bool optimize,
- int batch_size) {
+ bool quantification, int batch_size) {
if (loader_.get() == nullptr) {
loader_ = std::make_shared>();
} else {
@@ -47,7 +55,8 @@ bool PaddleMobile::Load(const std::string &model_path,
if (executor_.get() == nullptr) {
executor_ = std::make_shared>(
- loader_->Load(model_path, para_path, optimize), batch_size, optimize);
+ loader_->Load(model_path, para_path, optimize, quantification),
+ batch_size, optimize);
} else {
LOG(kLOG_INFO) << "executor inited";
}
@@ -81,7 +90,9 @@ PaddleMobile::~PaddleMobile() {
}
template class PaddleMobile;
+
template class PaddleMobile;
+
template class PaddleMobile;
} // namespace paddle_mobile
diff --git a/src/io/paddle_mobile.h b/src/io/paddle_mobile.h
index 3ce39e0ae1ffc7e193f6f4308a911875fdf95076..5dc3ccb21dd7e67fbe9b5032d01046b12728dc64 100644
--- a/src/io/paddle_mobile.h
+++ b/src/io/paddle_mobile.h
@@ -17,6 +17,9 @@ limitations under the License. */
#include
#include
#include
+#ifdef _OPENMP
+#include
+#endif // _OPENMP
#include "common/types.h"
#include "framework/tensor.h"
@@ -36,14 +39,19 @@ class PaddleMobile {
* @b 加载分开形式的 fluid 模型
* */
bool Load(const std::string &dirname, bool optimize = false,
- int batch_size = 1);
+ bool quantification = false, int batch_size = 1);
/*
* @b load combine format fluid mode
* @b 加载结合在一起格式的模型
* */
bool Load(const std::string &model_path, const std::string ¶_path,
- bool optimize = false, int batch_size = 1);
+ bool optimize = false, bool quantification = false,
+ int batch_size = 1);
+ /*
+ * @b 设置线程数, 当 cmake 中开启 openmp 时生效
+ * */
+ void SetThreadNum(int num);
/*
* @b to predict
diff --git a/src/ios_io/PaddleMobile.h b/src/ios_io/PaddleMobile.h
index 863c0d004440dc6098eb7dc1ed490fde20f237c9..5854c5c3a4d4c899feb88822b2f7993860d1ed76 100644
--- a/src/ios_io/PaddleMobile.h
+++ b/src/ios_io/PaddleMobile.h
@@ -19,10 +19,34 @@
@interface PaddleMobile : NSObject
+/*
+ 创建对象
+*/
- (instancetype)init;
+
+/*
+ load 模型, 开辟内存
+*/
- (BOOL)load:(NSString *)modelPath andWeightsPath:(NSString *)weighsPath;
+
+/*
+ 加载散开形式的模型, 需传入模型的目录
+*/
+- (BOOL)load:(NSString *)modelAndWeightPath;
+
+/*
+ 进行预测, means 和 scale 为训练模型时的预处理参数, 如训练时没有做这些预处理则直接使用 predict
+*/
- (NSArray *)predict:(CGImageRef)image dim:(NSArray *)dim means:(NSArray *)means scale:(float)scale;
+
+/*
+ 进行预测
+*/
- (NSArray *)predict:(CGImageRef)image dim:(NSArray *)dim;
+
+/*
+ 清理内存
+*/
- (void)clear;
@end
diff --git a/src/ios_io/PaddleMobile.mm b/src/ios_io/PaddleMobile.mm
index f5ec2afb2a996ec4932d99ea93362e06ddf28a14..e3ed909394a1057302fb0f747b582b944c89cc65 100644
--- a/src/ios_io/PaddleMobile.mm
+++ b/src/ios_io/PaddleMobile.mm
@@ -62,6 +62,15 @@ static std::mutex shared_mutex;
}
}
+- (BOOL)load:(NSString *)modelAndWeightPath{
+ std::string model_path_str = std::string([modelAndWeightPath UTF8String]);
+ if (loaded_ = pam_->Load(model_path_str)) {
+ return YES;
+ } else {
+ return NO;
+ }
+}
+
-(void)preprocess:(const UInt8 *)input output:(float *)output imageWidth:(int)imageWidth imageHeight:(int)imageHeight imageChannels:(int)imageChannels means:(NSArray *)means scale:(float)scale dim:(std::vector)dim{
if (means == nil) {
means = @[@0, @0, @0];
diff --git a/src/jni/paddle_mobile_jni.cpp b/src/jni/paddle_mobile_jni.cpp
index 01d4e52a4b1308a7ff97bc672d1a15d329dbf318..d4eb9e0f0733814cbe367a1873e241383127340a 100644
--- a/src/jni/paddle_mobile_jni.cpp
+++ b/src/jni/paddle_mobile_jni.cpp
@@ -15,6 +15,7 @@ limitations under the License. */
#ifdef ANDROID
#include "paddle_mobile_jni.h"
+#include
#include "common/log.h"
#include "framework/tensor.h"
#include "io/paddle_mobile.h"
@@ -60,8 +61,26 @@ JNIEXPORT jboolean JNICALL Java_com_baidu_paddle_PML_load(JNIEnv *env,
optimize);
}
-JNIEXPORT jfloatArray JNICALL
-Java_com_baidu_paddle_PML_predict(JNIEnv *env, jclass thiz, jfloatArray buf) {
+JNIEXPORT jboolean JNICALL Java_com_baidu_paddle_PML_loadCombined(
+ JNIEnv *env, jclass thiz, jstring modelPath, jstring paramPath) {
+ ANDROIDLOGI("loadCombined invoked");
+ bool optimize = true;
+ return getPaddleMobileInstance()->Load(jstring2cppstring(env, modelPath),
+ jstring2cppstring(env, paramPath),
+ optimize);
+}
+
+JNIEXPORT jfloatArray JNICALL Java_com_baidu_paddle_PML_predictImage(
+ JNIEnv *env, jclass thiz, jfloatArray buf, jintArray ddims) {
+ ANDROIDLOGI("predictImage invoked");
+ jsize ddim_size = env->GetArrayLength(ddims);
+ if (ddim_size != 4) {
+ ANDROIDLOGE("ddims size not equal to 4");
+ }
+ jint *ddim_ptr = env->GetIntArrayElements(ddims, NULL);
+ framework::DDim ddim = framework::make_ddim(
+ {ddim_ptr[0], ddim_ptr[1], ddim_ptr[2], ddim_ptr[3]});
+ int length = framework::product(ddim);
jfloatArray result = NULL;
int count = 0;
float *dataPointer = nullptr;
@@ -69,17 +88,102 @@ Java_com_baidu_paddle_PML_predict(JNIEnv *env, jclass thiz, jfloatArray buf) {
dataPointer = env->GetFloatArrayElements(buf, NULL);
}
framework::Tensor input;
- framework::DDim ddim = framework::make_ddim({1, 3, 224, 224});
input.Resize(ddim);
auto input_ptr = input.mutable_data();
- for (int i = 0; i < framework::product(ddim); i++) {
+ for (int i = 0; i < length; i++) {
input_ptr[i] = dataPointer[i];
}
auto output = shared_paddle_mobile_instance->Predict(input);
count = output->numel();
result = env->NewFloatArray(count);
env->SetFloatArrayRegion(result, 0, count, output->data());
- ANDROIDLOGI("predict finished");
+ env->ReleaseIntArrayElements(ddims, ddim_ptr, 0);
+ ANDROIDLOGI("predictImage finished");
+ return result;
+}
+
+inline int yuv_to_rgb(int y, int u, int v, float *r, float *g, float *b) {
+ int r1 = (int)(y + 1.370705 * (v - 128));
+ int g1 = (int)(y - 0.698001 * (u - 128) - 0.703125 * (v - 128));
+ int b1 = (int)(y + 1.732446 * (u - 128));
+
+ r1 = (int)fminf(255, fmaxf(0, r1));
+ g1 = (int)fminf(255, fmaxf(0, g1));
+ b1 = (int)fminf(255, fmaxf(0, b1));
+ *r = r1;
+ *g = g1;
+ *b = b1;
+
+ return 0;
+}
+void convert_nv21_to_matrix(uint8_t *nv21, float *matrix, int width, int height,
+ int targetWidth, int targetHeight, float *means) {
+ const uint8_t *yData = nv21;
+ const uint8_t *vuData = nv21 + width * height;
+
+ const int yRowStride = width;
+ const int vuRowStride = width;
+
+ float scale_x = width * 1.0 / targetWidth;
+ float scale_y = height * 1.0 / targetHeight;
+
+ for (int j = 0; j < targetHeight; ++j) {
+ int y = j * scale_y;
+ const uint8_t *pY = yData + y * yRowStride;
+ const uint8_t *pVU = vuData + (y >> 1) * vuRowStride;
+ for (int i = 0; i < targetWidth; ++i) {
+ int x = i * scale_x;
+ const int offset = ((x >> 1) << 1);
+ float r = 0;
+ float g = 0;
+ float b = 0;
+ yuv_to_rgb(pY[x], pVU[offset + 1], pVU[offset], &r, &g, &b);
+ int r_index = j * targetWidth + i;
+ int g_index = r_index + targetWidth * targetHeight;
+ int b_index = g_index + targetWidth * targetHeight;
+ matrix[r_index] = r - means[0];
+ matrix[g_index] = g - means[1];
+ matrix[b_index] = b - means[2];
+ }
+ }
+}
+
+JNIEXPORT jfloatArray JNICALL Java_com_baidu_paddle_PML_predictYuv(
+ JNIEnv *env, jclass thiz, jbyteArray yuv_, jint imgwidth, jint imgHeight,
+ jintArray ddims, jfloatArray meanValues) {
+ ANDROIDLOGI("predictYuv invoked");
+ jsize ddim_size = env->GetArrayLength(ddims);
+ if (ddim_size != 4) {
+ ANDROIDLOGE("ddims size not equal to 4");
+ }
+ jint *ddim_ptr = env->GetIntArrayElements(ddims, NULL);
+ framework::DDim ddim = framework::make_ddim(
+ {ddim_ptr[0], ddim_ptr[1], ddim_ptr[2], ddim_ptr[3]});
+ int length = framework::product(ddim);
+ float matrix[length];
+ jbyte *yuv = env->GetByteArrayElements(yuv_, NULL);
+ float *meansPointer = nullptr;
+ if (nullptr != meanValues) {
+ meansPointer = env->GetFloatArrayElements(meanValues, NULL);
+ }
+ convert_nv21_to_matrix((uint8_t *)yuv, matrix, imgwidth, imgHeight, ddim[3],
+ ddim[2], meansPointer);
+ jfloatArray result = NULL;
+ int count = 0;
+ framework::Tensor input;
+ input.Resize(ddim);
+ auto input_ptr = input.mutable_data();
+ for (int i = 0; i < length; i++) {
+ input_ptr[i] = matrix[i];
+ }
+ auto output = shared_paddle_mobile_instance->Predict(input);
+ count = output->numel();
+ result = env->NewFloatArray(count);
+ env->SetFloatArrayRegion(result, 0, count, output->data());
+ env->ReleaseByteArrayElements(yuv_, yuv, 0);
+ env->ReleaseIntArrayElements(ddims, ddim_ptr, 0);
+ env->ReleaseFloatArrayElements(meanValues, meansPointer, 0);
+ ANDROIDLOGI("predictYuv finished");
return result;
}
diff --git a/src/jni/paddle_mobile_jni.h b/src/jni/paddle_mobile_jni.h
index 86caa9a273ab11124f6ea67efe27dc3529cea69f..a830ab43c8ee0598fbf75e1fef5f3eb7da06c27b 100644
--- a/src/jni/paddle_mobile_jni.h
+++ b/src/jni/paddle_mobile_jni.h
@@ -22,11 +22,29 @@ extern "C" {
namespace paddle_mobile {
namespace jni {
/**
- * load model & params of the net for android
+ * load separated model for android
*/
JNIEXPORT jboolean JNICALL Java_com_baidu_paddle_PML_load(JNIEnv *env,
jclass thiz,
jstring modelPath);
+/**
+ * load combined model for android
+ */
+JNIEXPORT jboolean JNICALL Java_com_baidu_paddle_PML_loadCombined(
+ JNIEnv *env, jclass thiz, jstring modelPath, jstring paramPath);
+
+/**
+ * object detection for anroid
+ */
+JNIEXPORT jfloatArray JNICALL Java_com_baidu_paddle_PML_predictImage(
+ JNIEnv *env, jclass thiz, jfloatArray buf, jintArray ddims);
+
+/**
+ * object detection for anroid
+ */
+JNIEXPORT jfloatArray JNICALL Java_com_baidu_paddle_PML_predictYuv(
+ JNIEnv *env, jclass thiz, jbyteArray yuv, jint imgwidth, jint imgHeight,
+ jintArray ddims, jfloatArray meanValues);
/**
* object detection for anroid
diff --git a/src/operators/batchnorm_op.cpp b/src/operators/batchnorm_op.cpp
index 644a27c586375bc66d327e18ac5182e8fce2893b..f820908404ea637d9680c32d5c4b5568e191dd7e 100644
--- a/src/operators/batchnorm_op.cpp
+++ b/src/operators/batchnorm_op.cpp
@@ -26,7 +26,7 @@ void BatchNormOp::InferShape() const {
auto x_dims = this->param_.InputX()->dims();
this->param_.OutputY()->Resize(x_dims);
}
-template class BatchNormOp;
+
} // namespace operators
} // namespace paddle_mobile
diff --git a/src/operators/box_coder_op.cpp b/src/operators/box_coder_op.cpp
index dece07d5efcfae9629842aead04d0274b9d82c93..9e57c9021dac1b6857752989727c1c86051e33f7 100644
--- a/src/operators/box_coder_op.cpp
+++ b/src/operators/box_coder_op.cpp
@@ -47,7 +47,7 @@ void BoxCoderOp::InferShape() const {
this->param_.OutputBox()->Resize(framework::make_ddim(
{input_targetbox_dims[0], input_priorbox_dims[0], 4}));
}
-template class BoxCoderOp;
+
} // namespace operators
} // namespace paddle_mobile
diff --git a/src/operators/concat_op.cpp b/src/operators/concat_op.cpp
index 9c524df351549fd0141294be805d77b3f1057362..19d771ddd5884412624a0720368ecc80f92678ea 100644
--- a/src/operators/concat_op.cpp
+++ b/src/operators/concat_op.cpp
@@ -56,7 +56,6 @@ void ConcatOp::InferShape() const {
this->param_.Out()->Resize(out_dims);
}
-template class ConcatOp;
} // namespace operators
} // namespace paddle_mobile
diff --git a/src/operators/conv_op.cpp b/src/operators/conv_op.cpp
index 1b00ed06eee2b1676667b9c54b8601c8872b6699..c4601995219b32db75f22c7c2ed959e18af85f36 100644
--- a/src/operators/conv_op.cpp
+++ b/src/operators/conv_op.cpp
@@ -48,8 +48,6 @@ void ConvOp::InferShape() const {
this->param_.Output()->Resize(ddim);
}
-template class ConvOp;
-
} // namespace operators
} // namespace paddle_mobile
diff --git a/src/operators/depthwise_conv_op.cpp b/src/operators/depthwise_conv_op.cpp
index bee90781cd2de9d65bbbee3193cc922e743706de..8d6b6a143c37537be6de1e60cc095f1052136e26 100644
--- a/src/operators/depthwise_conv_op.cpp
+++ b/src/operators/depthwise_conv_op.cpp
@@ -49,8 +49,6 @@ void DepthwiseConvOp::InferShape() const {
this->param_.Output()->Resize(ddim);
}
-template class DepthwiseConvOp;
-
} // namespace operators
} // namespace paddle_mobile
diff --git a/src/operators/dropout_op.cpp b/src/operators/dropout_op.cpp
index f7f5ca2475171f5756ee8cf4f13754d07df8fe01..a632aa0c52b19c591467f94afb216245a596680b 100644
--- a/src/operators/dropout_op.cpp
+++ b/src/operators/dropout_op.cpp
@@ -22,7 +22,7 @@ void DropoutOp::InferShape() const {
auto input_dims = this->param_.InputX()->dims();
this->param_.Out()->Resize(input_dims);
}
-template class DropoutOp;
+
} // namespace operators
} // namespace paddle_mobile
diff --git a/src/operators/elementwise_add_op.cpp b/src/operators/elementwise_add_op.cpp
index 369589574139c7bc68debb7c55836926a3d5f6b2..49885f783417d61c6348fc4563e7306036994f17 100644
--- a/src/operators/elementwise_add_op.cpp
+++ b/src/operators/elementwise_add_op.cpp
@@ -24,7 +24,7 @@ void ElementwiseAddOp::InferShape() const {
auto x_dim = this->param_.InputX()->dims();
this->param_.Out()->Resize(x_dim);
}
-template class ElementwiseAddOp;
+
} // namespace operators
} // namespace paddle_mobile
diff --git a/src/operators/feed_op.cpp b/src/operators/feed_op.cpp
index c4357d7993cd91a306fec5856eaa6839e9ab6a6e..4447f2c699fc929805f15a265440803e6ff34b56 100644
--- a/src/operators/feed_op.cpp
+++ b/src/operators/feed_op.cpp
@@ -14,10 +14,7 @@ limitations under the License. */
#include "feed_op.h"
namespace paddle_mobile {
-namespace operators {
-
-template class FeedOp;
-}
+namespace operators {}
} // namespace paddle_mobile
namespace ops = paddle_mobile::operators;
diff --git a/src/operators/fetch_op.cpp b/src/operators/fetch_op.cpp
index cdbe413c955b931a16e716aa2e18d2a018a53bab..adbd61d5ec364a40b565059ceb5d5d49999c8436 100644
--- a/src/operators/fetch_op.cpp
+++ b/src/operators/fetch_op.cpp
@@ -14,10 +14,7 @@ limitations under the License. */
#include "fetch_op.h"
namespace paddle_mobile {
-namespace operators {
-
-template class FetchOp;
-}
+namespace operators {}
} // namespace paddle_mobile
namespace ops = paddle_mobile::operators;
diff --git a/src/operators/fusion_conv_add.cpp b/src/operators/fusion_conv_add.cpp
index b1dba23be0d8ea010b38844b1897381fbf578617..cdd6a6db2bb11ebf8dce2aca85630aa8805adf3e 100644
--- a/src/operators/fusion_conv_add.cpp
+++ b/src/operators/fusion_conv_add.cpp
@@ -45,7 +45,6 @@ void FusionConvAddOp::InferShape() const {
this->param_.Output()->Resize(ddim);
}
-template class FusionConvAddOp;
} // namespace operators
} // namespace paddle_mobile
diff --git a/src/operators/fusion_conv_add.h b/src/operators/fusion_conv_add.h
index ae030ba5767e4039cfa3effe0a7ded4886f261cf..170df9ce33e4ab90297664fbc81d723e7c246f83 100644
--- a/src/operators/fusion_conv_add.h
+++ b/src/operators/fusion_conv_add.h
@@ -36,8 +36,6 @@ class FusionConvAddMatcher : public framework::FusionOpMatcher {
void FolderNodes(
framework::Node *node,
std::vector> *removed_nodes) {
- vector> origin_descs =
- node->OpDescs(node_.Depth());
node->Folder(node_.Depth(), Type(),
{{G_OP_TYPE_ELEMENTWISE_ADD, {{"Y", "Y"}}}}, removed_nodes);
}
diff --git a/src/operators/fusion_conv_add_bn_relu_op.cpp b/src/operators/fusion_conv_add_bn_relu_op.cpp
index 62839c1a5acaf89a3efef39bbe4a67c675da393b..16f4650a64ec0c363d5fa94ee27c15c73cf58a70 100644
--- a/src/operators/fusion_conv_add_bn_relu_op.cpp
+++ b/src/operators/fusion_conv_add_bn_relu_op.cpp
@@ -44,7 +44,7 @@ void FusionConvAddBNReluOp::InferShape() const {
framework::DDim ddim = framework::make_ddim(output_shape);
this->param_.Output()->Resize(ddim);
}
-template class FusionConvAddBNReluOp;
+
} // namespace operators
} // namespace paddle_mobile
diff --git a/src/operators/fusion_conv_add_bn_relu_op.h b/src/operators/fusion_conv_add_bn_relu_op.h
index 753ce395980c9186c948bc1ae4c89c3d2c417fdc..19e33465c06921e9a6a7beb77053f05a03a6c760 100644
--- a/src/operators/fusion_conv_add_bn_relu_op.h
+++ b/src/operators/fusion_conv_add_bn_relu_op.h
@@ -39,8 +39,6 @@ class FusionConvAddBNReluMatcher : public framework::FusionOpMatcher {
void FolderNodes(
framework::Node *node,
std::vector> *removed_nodes) {
- vector> origin_descs =
- node->OpDescs(node_.Depth());
node->Folder(node_.Depth(), Type(),
{{G_OP_TYPE_ELEMENTWISE_ADD, {{"Y", "Y"}}},
{G_OP_TYPE_BATCHNORM,
@@ -79,11 +77,11 @@ class FusionConvAddBNReluOp
#ifdef PADDLE_MOBILE_CPU
-//#ifndef FUSION_CONV_ADD_BN_RELU_REGISTER
-// static framework::FusionOpRegistrar fusion_conv_add_bn_relu_registrar(
-// new FusionConvAddBNReluMatcher());
-//#define FUSION_CONV_ADD_BN_RELU_REGISTER
-//#endif
+#ifndef FUSION_CONV_ADD_BN_RELU_REGISTER
+static framework::FusionOpRegistrar fusion_conv_add_bn_relu_registrar(
+ new FusionConvAddBNReluMatcher());
+#define FUSION_CONV_ADD_BN_RELU_REGISTER
+#endif
#endif
diff --git a/src/operators/fusion_conv_bn_relu_op.cpp b/src/operators/fusion_conv_bn_relu_op.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..49fe9c933a5a9695f2c18bd0921c2d36063dc065
--- /dev/null
+++ b/src/operators/fusion_conv_bn_relu_op.cpp
@@ -0,0 +1,60 @@
+/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License. */
+
+#ifdef FUSION_CONVBNRELU_OP
+
+#include "operators/fusion_conv_bn_relu_op.h"
+#include "operators/math/conv_func.h"
+
+namespace paddle_mobile {
+namespace operators {
+
+template
+void FusionConvBNReluOp::InferShape() const {
+ auto in_dims = this->param_.Input()->dims();
+ auto filter_dims = this->param_.Filter()->dims();
+ const std::vector &strides = this->param_.Strides();
+ std::vector paddings = this->param_.Paddings();
+ int groups = this->param_.Groups();
+ std::vector dilations = this->param_.Dilations();
+
+ PADDLE_MOBILE_ENFORCE((in_dims.size() == filter_dims.size() &&
+ dilations.size() == paddings.size() &&
+ paddings.size() == strides.size()),
+ "ConvParam is not suitable");
+
+ std::vector output_shape({in_dims[0], filter_dims[0]});
+ for (size_t i = 0; i < strides.size(); ++i) {
+ output_shape.push_back(
+ math::ConvOutputSize(in_dims[i + 2], filter_dims[i + 2], dilations[i],
+ paddings[i], strides[i]));
+ }
+
+ framework::DDim ddim = framework::make_ddim(output_shape);
+ this->param_.Output()->Resize(ddim);
+}
+
+} // namespace operators
+} // namespace paddle_mobile
+
+namespace ops = paddle_mobile::operators;
+#ifdef PADDLE_MOBILE_CPU
+REGISTER_OPERATOR_CPU(fusion_conv_bn_relu, ops::FusionConvBNReluOp);
+#endif
+#ifdef PADDLE_MOBILE_MALI_GPU
+#endif
+#ifdef PADDLE_MOBILE_FPGA
+#endif
+
+#endif
diff --git a/src/operators/fusion_conv_bn_relu_op.h b/src/operators/fusion_conv_bn_relu_op.h
new file mode 100644
index 0000000000000000000000000000000000000000..4c2c1033ac0a4d6c8e3bc3f188a66884dd9e0642
--- /dev/null
+++ b/src/operators/fusion_conv_bn_relu_op.h
@@ -0,0 +1,103 @@
+/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License. */
+
+#ifdef FUSION_CONVBNRELU_OP
+
+#pragma once
+
+#include
+#include
+#include "framework/operator.h"
+#include "framework/program/program-optimize/fusion_op_register.h"
+#include "operators/kernel/conv_bn_relu_kernel.h"
+#include "operators/op_param.h"
+
+namespace paddle_mobile {
+namespace operators {
+using std::string;
+using std::vector;
+class FusionConvBNReluMatcher : public framework::FusionOpMatcher {
+ public:
+ FusionConvBNReluMatcher() {
+ node_ = framework::Node(G_OP_TYPE_CONV);
+ node_ > std::make_shared(G_OP_TYPE_BATCHNORM) >
+ std::make_shared(G_OP_TYPE_RELU);
+ }
+
+ void FolderNodes(
+ framework::Node *node,
+ std::vector> *removed_nodes) {
+ node->Folder(node_.Depth(), Type(),
+ {{G_OP_TYPE_BATCHNORM,
+ {{"Scale", "Scale"},
+ {"Mean", "Mean"},
+ {"Bias", "Bias"},
+ {"Variance", "Variance"}}}},
+ removed_nodes);
+ }
+
+ std::string Type() { return G_OP_TYPE_FUSION_CONV_BN_RELU; }
+};
+
+template
+class FusionConvBNReluOp : public framework::OperatorWithKernel<
+ DeviceType, FusionConvBNReluParam,
+ operators::ConvBNReluKernel> {
+ public:
+ FusionConvBNReluOp(const string &type, const VariableNameMap &inputs,
+ const VariableNameMap &outputs,
+ const framework::AttributeMap &attrs,
+ std::shared_ptr scope)
+ : framework::OperatorWithKernel<
+ DeviceType, FusionConvBNReluParam,
+ operators::ConvBNReluKernel>(type, inputs, outputs,
+ attrs, scope) {}
+
+ using framework::OperatorWithKernel<
+ DeviceType, FusionConvBNReluParam,
+ operators::ConvBNReluKernel>::OperatorWithKernel;
+ void InferShape() const override;
+
+ protected:
+};
+
+#ifdef PADDLE_MOBILE_CPU
+
+#ifndef FUSION_CONV_BN_RELU_REGISTER
+static framework::FusionOpRegistrar fusion_conv_bn_relu_registrar(
+ new FusionConvBNReluMatcher());
+#define FUSION_CONV_BN_RELU_REGISTER
+#endif
+
+#endif
+
+#ifdef PADDLE_MOBILE_MALI_GPU
+
+#endif
+
+#ifdef PADDLE_MOBILE_FPGA
+#endif
+
+} // namespace operators
+} // namespace paddle_mobile
+
+#ifdef PADDLE_MOBILE_CPU
+USE_OP_CPU(fusion_conv_bn_relu);
+#endif
+#ifdef PADDLE_MOBILE_MALI_GPU
+#endif
+#ifdef PADDLE_MOBILE_FPGA
+#endif
+
+#endif
diff --git a/src/operators/fusion_dwconv_bn_relu_op.cpp b/src/operators/fusion_dwconv_bn_relu_op.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..e55295830e19b5b39a5ae2501e30170ffb1a7854
--- /dev/null
+++ b/src/operators/fusion_dwconv_bn_relu_op.cpp
@@ -0,0 +1,60 @@
+/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License. */
+
+#ifdef FUSION_DWCONVBNRELU_OP
+
+#include "operators/fusion_dwconv_bn_relu_op.h"
+#include "operators/math/conv_func.h"
+
+namespace paddle_mobile {
+namespace operators {
+
+template
+void FusionDWConvBNReluOp::InferShape() const {
+ auto in_dims = this->param_.Input()->dims();
+ auto filter_dims = this->param_.Filter()->dims();
+ const std::vector &strides = this->param_.Strides();
+ std::vector paddings = this->param_.Paddings();
+ int groups = this->param_.Groups();
+ std::vector dilations = this->param_.Dilations();
+
+ PADDLE_MOBILE_ENFORCE((in_dims.size() == filter_dims.size() &&
+ dilations.size() == paddings.size() &&
+ paddings.size() == strides.size()),
+ "ConvParam is not suitable");
+
+ std::vector output_shape({in_dims[0], filter_dims[0]});
+ for (size_t i = 0; i < strides.size(); ++i) {
+ output_shape.push_back(
+ math::ConvOutputSize(in_dims[i + 2], filter_dims[i + 2], dilations[i],
+ paddings[i], strides[i]));
+ }
+
+ framework::DDim ddim = framework::make_ddim(output_shape);
+ this->param_.Output()->Resize(ddim);
+}
+
+} // namespace operators
+} // namespace paddle_mobile
+
+namespace ops = paddle_mobile::operators;
+#ifdef PADDLE_MOBILE_CPU
+REGISTER_OPERATOR_CPU(fusion_dwconv_bn_relu, ops::FusionDWConvBNReluOp);
+#endif
+#ifdef PADDLE_MOBILE_MALI_GPU
+#endif
+#ifdef PADDLE_MOBILE_FPGA
+#endif
+
+#endif
diff --git a/src/operators/fusion_dwconv_bn_relu_op.h b/src/operators/fusion_dwconv_bn_relu_op.h
new file mode 100644
index 0000000000000000000000000000000000000000..6f9f03e4936e082de802ced385060fecb9cc27a9
--- /dev/null
+++ b/src/operators/fusion_dwconv_bn_relu_op.h
@@ -0,0 +1,109 @@
+/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License. */
+
+#ifdef FUSION_DWCONVBNRELU_OP
+
+#pragma once
+
+#include
+#include
+#include "framework/operator.h"
+#include "framework/program/program-optimize/fusion_op_register.h"
+#include "op_param.h"
+#include "operators/kernel/dwconv_bn_relu_kernel.h"
+
+namespace paddle_mobile {
+namespace operators {
+using std::string;
+using std::vector;
+class FusionDWConvBNReluMatcher : public framework::FusionOpMatcher {
+ public:
+ FusionDWConvBNReluMatcher() {
+ node_ = framework::Node(G_OP_TYPE_DEPTHWISE_CONV);
+ node_ > std::make_shared(G_OP_TYPE_BATCHNORM) >
+ std::make_shared(G_OP_TYPE_RELU);
+ }
+
+ void FolderNodes(
+ framework::Node *node,
+ std::vector> *removed_nodes) {
+ node->Folder(node_.Depth(), Type(),
+ {{G_OP_TYPE_BATCHNORM,
+ {{"Scale", "Scale"},
+ {"Mean", "Mean"},
+ {"Bias", "Bias"},
+ {"Variance", "Variance"}}}},
+ removed_nodes);
+ }
+
+ std::string Type() { return G_OP_TYPE_FUSION_DWCONV_BN_RELU; }
+};
+
+template
+class FusionDWConvBNReluOp : public framework::OperatorWithKernel<
+ DeviceType, FusionDWConvBNReluParam,
+ operators::DWConvBNReluKernel> {
+ public:
+ FusionDWConvBNReluOp(const string &type, const VariableNameMap &inputs,
+ const VariableNameMap &outputs,
+ const framework::AttributeMap &attrs,
+ std::shared_ptr scope)
+ : framework::OperatorWithKernel<
+ DeviceType, FusionDWConvBNReluParam,
+ operators::DWConvBNReluKernel>(type, inputs, outputs,
+ attrs, scope) {}
+
+ using framework::OperatorWithKernel<
+ DeviceType, FusionDWConvBNReluParam,
+ operators::DWConvBNReluKernel>::OperatorWithKernel;
+ void InferShape() const override;
+
+ protected:
+};
+
+#ifdef PADDLE_MOBILE_CPU
+
+#ifndef FUSION_DWCONV_BN_RELU_REGISTER
+static framework::FusionOpRegistrar fusion_dwconv_bn_relu_registrar(
+ new FusionDWConvBNReluMatcher());
+#define FUSION_DWCONV_BN_RELU_REGISTER
+#endif
+
+#endif
+
+#ifdef PADDLE_MOBILE_MALI_GPU
+
+#ifndef FUSION_DWCONV_BN_RELU_REGISTER
+static framework::FusionOpRegistrar fusion_dwconv_bn_relu_registrar(
+ new FusionDWConvBNReluMatcher());
+#define FUSION_DWCONV_BN_RELU_REGISTER
+#endif
+
+#endif
+
+#ifdef PADDLE_MOBILE_FPGA
+#endif
+
+} // namespace operators
+} // namespace paddle_mobile
+
+#ifdef PADDLE_MOBILE_CPU
+USE_OP_CPU(fusion_dwconv_bn_relu);
+#endif
+#ifdef PADDLE_MOBILE_MALI_GPU
+#endif
+#ifdef PADDLE_MOBILE_FPGA
+#endif
+
+#endif
diff --git a/src/operators/fusion_fc_op.cpp b/src/operators/fusion_fc_op.cpp
index 57a8b1b53f2f98b3218ee8fc40c6c9774ec5a5c7..d564d4d88c16ee09382a9b2dae275807ec4bdb4b 100644
--- a/src/operators/fusion_fc_op.cpp
+++ b/src/operators/fusion_fc_op.cpp
@@ -50,7 +50,6 @@ void FusionFcOp::InferShape() const {
this->param_.Out()->Resize(ddim);
}
-template class FusionFcOp;
} // namespace operators
} // namespace paddle_mobile
diff --git a/src/operators/im2sequence_op.cpp b/src/operators/im2sequence_op.cpp
index 273ce462d0aa423a6bf023186c6a579e975dfb11..3c929af9cf0a8a1550f197ffdb42ee590cd43235 100644
--- a/src/operators/im2sequence_op.cpp
+++ b/src/operators/im2sequence_op.cpp
@@ -47,8 +47,6 @@ void Im2SequenceOp::InferShape() const {
this->param_.Output()->Resize(ddim);
}
-template class Im2SequenceOp;
-
} // namespace operators
} // namespace paddle_mobile
diff --git a/src/operators/kernel/arm/conv_add_bn_relu_kernel.cpp b/src/operators/kernel/arm/conv_add_bn_relu_kernel.cpp
index 1fd1c66d4dc92a9918243b23e400ef5309422050..dbf3745eb15cf56bba32dc8cbae50d242ce2da76 100644
--- a/src/operators/kernel/arm/conv_add_bn_relu_kernel.cpp
+++ b/src/operators/kernel/arm/conv_add_bn_relu_kernel.cpp
@@ -15,7 +15,7 @@ limitations under the License. */
#ifdef FUSION_CONVADDBNRELU_OP
#include "operators/kernel/conv_add_bn_relu_kernel.h"
-#include "operators/kernel/central-arm-func/conv_add_bn_relu_func.h"
+#include "operators/kernel/central-arm-func/conv_add_bn_relu_arm_func.h"
namespace paddle_mobile {
namespace operators {
diff --git a/src/operators/kernel/arm/conv_bn_relu_kernel.cpp b/src/operators/kernel/arm/conv_bn_relu_kernel.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..23f06c1f0b8a0ed3f22ca9d23d24ae44c59f3618
--- /dev/null
+++ b/src/operators/kernel/arm/conv_bn_relu_kernel.cpp
@@ -0,0 +1,68 @@
+/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License. */
+
+#ifdef FUSION_CONVBNRELU_OP
+
+#include "operators/kernel/conv_bn_relu_kernel.h"
+#include "operators/kernel/central-arm-func/conv_bn_relu_arm_func.h"
+
+namespace paddle_mobile {
+namespace operators {
+
+template <>
+bool ConvBNReluKernel::Init(FusionConvBNReluParam *param) {
+ const Tensor *mean = param->InputMean();
+ const Tensor *variance = param->InputVariance();
+ const Tensor *scale = param->InputScale();
+ const Tensor *bias = param->InputBias();
+ const float epsilon = param->Epsilon();
+
+ // DLOG << "variance: " << *variance;
+
+ auto mean_ptr = mean->data();
+ auto variance_ptr = variance->data();
+ auto scale_ptr = scale->data();
+ auto bias_ptr = bias->data();
+
+ const int C = mean->numel();
+ float inv_std_ptr[C];
+ for (int i = 0; i < C; i++) {
+ inv_std_ptr[i] =
+ 1 / static_cast(pow((variance_ptr[i] + epsilon), 0.5));
+ }
+ Tensor *new_scale = new Tensor();
+ Tensor *new_bias = new Tensor();
+ auto new_scale_ptr = new_scale->mutable_data({C});
+ auto new_bias_ptr = new_bias->mutable_data({C});
+ for (int i = 0; i < C; i++) {
+ new_scale_ptr[i] = inv_std_ptr[i] * scale_ptr[i];
+ new_bias_ptr[i] = bias_ptr[i] - mean_ptr[i] * inv_std_ptr[i] * scale_ptr[i];
+ }
+
+ param->SetNewScale(new_scale);
+ param->SetNewBias(new_bias);
+ return true;
+}
+
+template <>
+void ConvBNReluKernel::Compute(
+ const FusionConvBNReluParam ¶m) const {
+ ConvBNReluCompute(param);
+}
+template class ConvBNReluKernel;
+
+} // namespace operators
+} // namespace paddle_mobile
+
+#endif
diff --git a/src/operators/kernel/arm/dwconv_bn_relu_kernel.cpp b/src/operators/kernel/arm/dwconv_bn_relu_kernel.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..0ec08fcecb9fefaa247e0acbb8a085e752b8dba3
--- /dev/null
+++ b/src/operators/kernel/arm/dwconv_bn_relu_kernel.cpp
@@ -0,0 +1,65 @@
+/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License. */
+
+#ifdef FUSION_DWCONVBNRELU_OP
+
+#include "operators/kernel/dwconv_bn_relu_kernel.h"
+#include "operators/kernel/central-arm-func/dwconv_bn_relu_arm_func.h"
+
+namespace paddle_mobile {
+namespace operators {
+
+template <>
+bool DWConvBNReluKernel::Init(FusionDWConvBNReluParam *param) {
+ const Tensor *mean = param->InputMean();
+ const Tensor *variance = param->InputVariance();
+ const Tensor *scale = param->InputScale();
+ const Tensor *bias = param->InputBias();
+ const float epsilon = param->Epsilon();
+
+ auto mean_ptr = mean->data();
+ auto variance_ptr = variance->data();
+ auto scale_ptr = scale->data();
+ auto bias_ptr = bias->data();
+
+ const int C = mean->numel();
+ float inv_std_ptr[C];
+ for (int i = 0; i < C; i++) {
+ inv_std_ptr[i] =
+ 1 / static_cast(pow((variance_ptr[i] + epsilon), 0.5));
+ }
+ Tensor *new_scale = new Tensor();
+ Tensor *new_bias = new Tensor();
+ auto new_scale_ptr = new_scale->mutable_data({C});
+ auto new_bias_ptr = new_bias->mutable_data({C});
+ for (int i = 0; i < C; i++) {
+ new_scale_ptr[i] = inv_std_ptr[i] * scale_ptr[i];
+ new_bias_ptr[i] = bias_ptr[i] - mean_ptr[i] * inv_std_ptr[i] * scale_ptr[i];
+ }
+ param->SetNewScale(new_scale);
+ param->SetNewBias(new_bias);
+ return true;
+}
+
+template <>
+void DWConvBNReluKernel::Compute(
+ const FusionDWConvBNReluParam ¶m) const {
+ DWConvBNReluCompute(param);
+}
+template class DWConvBNReluKernel;
+
+} // namespace operators
+} // namespace paddle_mobile
+
+#endif
diff --git a/src/operators/kernel/arm/sigmoid_kernel.cpp b/src/operators/kernel/arm/sigmoid_kernel.cpp
index eb67de153ddb13fb48e42c28d6ec2270b0bc59b4..9f5e6a2048d940ddc4592777a773c69d976033bd 100644
--- a/src/operators/kernel/arm/sigmoid_kernel.cpp
+++ b/src/operators/kernel/arm/sigmoid_kernel.cpp
@@ -16,7 +16,7 @@ limitations under the License. */
#include "../sigmoid_kernel.h"
#include "../central-arm-func/sigmoid_arm_func.h"
-#if __ARM_NEON
+#ifdef __ARM_NEON
#include "../../math/math_func_neon.h"
#endif
#include
diff --git a/src/operators/kernel/central-arm-func/batchnorm_arm_func.h b/src/operators/kernel/central-arm-func/batchnorm_arm_func.h
index b2af17eb4aaf0a7ef98442f589162a3b6f371a3b..cc591035065e4cbbe71ff8f6bd6cbab9c6fe9e79 100644
--- a/src/operators/kernel/central-arm-func/batchnorm_arm_func.h
+++ b/src/operators/kernel/central-arm-func/batchnorm_arm_func.h
@@ -54,7 +54,40 @@ void BatchnormCompute(const BatchNormParam ¶m) {
int HXW = H * W;
-#ifdef ARMV7
+#if __ARM_NEON
+#if __aarch64__
+ float *inv_std_ptr = new float[C];
+ for (int i = 0; i < C; i++) {
+ inv_std_ptr[i] =
+ 1 / static_cast(pow((variance_ptr[i] + epsilon), 0.5));
+ }
+
+ Tensor new_scale;
+ auto new_scale_ptr = new_scale.mutable_data(framework::make_ddim({C}));
+ Tensor new_bias;
+ auto new_bias_ptr = new_bias.mutable_data(framework::make_ddim({C}));
+
+ /// ((x - est_mean) * (inv_var) * scale + bias equal to
+ /// (x * inv_var * scale) + (bias - est_mean * inv_var * scale)
+ for (int i = 0; i < C; i++) {
+ new_scale_ptr[i] = inv_std_ptr[i] * scale_ptr[i];
+ new_bias_ptr[i] = bias_ptr[i] - mean_ptr[i] * inv_std_ptr[i] * scale_ptr[i];
+ {
+ for (int n = 0; n < N; n++) {
+ for (int h = 0; h < H; h++) {
+ int tmp_index = n * stride0 + i * stride1 + h * stride2;
+ for (int w = 0; w < W; w++) {
+ int index = tmp_index + w;
+ out_ptr[index] =
+ input_x_ptr[index] * new_scale_ptr[i] + new_bias_ptr[i];
+ }
+ }
+ }
+ }
+ }
+ delete[] inv_std_ptr;
+#else
+
if (HXW > 32) {
int NXC = N * C;
float *inv_std_ptr = new float[NXC * 4];
@@ -229,6 +262,7 @@ void BatchnormCompute(const BatchNormParam ¶m) {
delete[] inv_std_ptr;
}
+#endif
#else
float *inv_std_ptr = new float[C];
for (int i = 0; i < C; i++) {
diff --git a/src/operators/kernel/central-arm-func/conv_add_arm_func.h b/src/operators/kernel/central-arm-func/conv_add_arm_func.h
index ed6dc46a90f2b6fa73555b3575f24103a34d1dda..15f9b4a17889b77da1884253f9e982d8f14ad131 100644
--- a/src/operators/kernel/central-arm-func/conv_add_arm_func.h
+++ b/src/operators/kernel/central-arm-func/conv_add_arm_func.h
@@ -124,9 +124,15 @@ void ConvAddCompute(const FusionConvAddParam ¶m) {
} else if (param.Groups() == param.Input()->dims()[1] &&
param.Input()->dims()[1] == param.Output()->dims()[1] &&
param.Filter()->dims()[2] == param.Filter()->dims()[3] &&
- param.Filter()->dims()[2] == 3) {
- math::DepthwiseConv3x3(param.Input(), param.Strides(), param.Paddings(),
- param.Filter(), param.Bias(), param.Output(), true);
+ param.Filter()->dims()[2] == 3 && param.Strides()[0] == 2) {
+ // math::DepthwiseConv3x3(param.Input(), param.Strides(),
+ // param.Paddings(),
+ // param.Filter(), param.Bias(),
+ // param.Output(), false);
+
+ math::DepthwiseConv3x3s2p1v2(param.Input(), param.Filter(), param.Output(),
+ *param.Bias(), true);
+
} else {
ConvAddBasic(param);
}
diff --git a/src/operators/kernel/central-arm-func/conv_add_bn_relu_func.h b/src/operators/kernel/central-arm-func/conv_add_bn_relu_arm_func.h
similarity index 80%
rename from src/operators/kernel/central-arm-func/conv_add_bn_relu_func.h
rename to src/operators/kernel/central-arm-func/conv_add_bn_relu_arm_func.h
index f184a59a3abbe463f75778c4db216a306c315e8d..d3b5bc69760797c4efcc3fb77831d54676d7d5b1 100644
--- a/src/operators/kernel/central-arm-func/conv_add_bn_relu_func.h
+++ b/src/operators/kernel/central-arm-func/conv_add_bn_relu_arm_func.h
@@ -15,6 +15,8 @@ limitations under the License. */
#ifdef FUSION_CONVADDBNRELU_OP
#pragma once
+
+#include
#include "operators/math/depthwise_conv_3x3.h"
#include "operators/op_param.h"
@@ -23,16 +25,9 @@ namespace operators {
void ConvAddBNReluBasic(const FusionConvAddBNReluParam ¶m) {
const Tensor *input = param.Input();
Tensor filter = *param.Filter();
- Tensor bias = *param.Bias();
Tensor new_bias = *param.NewBias();
Tensor new_scale = *param.NewScale();
- auto new_bias_ptr = new_bias.data();
- auto new_scale_ptr = new_scale.data();
- int axis = param.Axis();
Tensor *output = param.Output();
- math::expand_bias(bias, axis, output->dims());
- output->ShareDataWith(bias);
-
int groups = param.Groups();
std::vector strides = param.Strides();
std::vector paddings = param.Paddings();
@@ -106,20 +101,10 @@ void ConvAddBNReluBasic(const FusionConvAddBNReluParam ¶m) {
// gemm
Tensor out_slice = out_batch.Slice(g * out_step, (g + 1) * out_step);
Tensor filter_slice = filter.Slice(g * out_step, (g + 1) * out_step);
- math::matmul(filter_slice, false, col_matrix, false,
- static_cast(1), &out_slice,
- static_cast(0));
- }
- }
- /// todo : use neon in special case instead of 2for(300ms)
- auto output_ptr = output->data();
- for (int c = 0; c < output_matrix_shape[0]; c++) {
- int start = c * output_matrix_shape[1];
- for (int j = 0; j < output_matrix_shape[1]; j++) {
- output_ptr[start + j] =
- output_ptr[start + j] * new_scale_ptr[c] + new_bias_ptr[c];
- output_ptr[start + j] =
- output_ptr[start + j] < 0 ? 0 : output_ptr[start + j];
+
+ math::matmulWithBn(
+ filter_slice, false, col_matrix, false, static_cast(1),
+ &out_slice, static_cast(0), true, &new_scale, &new_bias, g);
}
}
}
@@ -133,14 +118,17 @@ void ConvAddBNReluCompute(const FusionConvAddBNReluParam ¶m) {
param.Filter()->dims()[2] == 3 && param.Strides()[0] == 1) {
math::DepthwiseConvAddBNRelu3x3s1p1(param.Input(), param.Filter(),
param.Output(), param.NewScale(),
- param.NewBias(), 1);
+ param.NewBias(), true);
} else if (param.Groups() == param.Input()->dims()[1] &&
param.Input()->dims()[1] == param.Output()->dims()[1] &&
param.Filter()->dims()[2] == param.Filter()->dims()[3] &&
param.Filter()->dims()[2] == 3 && param.Strides()[0] == 2) {
- math::DepthwiseConvAddBNRelu3x3s2p1(param.Input(), param.Filter(),
- param.Output(), param.NewScale(),
- param.NewBias(), 1);
+ // math::DepthwiseConvAddBNRelu3x3s2p1(param.Input(), param.Filter(),
+ // param.Output(), param.NewScale(),
+ // param.NewBias(), 1);
+ math::DepthwiseConvAddBNRelu3x3s2p1v2(param.Input(), param.Filter(),
+ param.Output(), param.NewScale(),
+ param.NewBias(), true);
} else {
ConvAddBNReluBasic(param);
}
diff --git a/src/operators/kernel/central-arm-func/conv_bn_relu_arm_func.h b/src/operators/kernel/central-arm-func/conv_bn_relu_arm_func.h
new file mode 100644
index 0000000000000000000000000000000000000000..f18d67749b96cd0ee2d84c2731af8a2c3e136db1
--- /dev/null
+++ b/src/operators/kernel/central-arm-func/conv_bn_relu_arm_func.h
@@ -0,0 +1,139 @@
+/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License. */
+
+#ifdef FUSION_CONVBNRELU_OP
+
+#pragma once
+#include
+#include "operators/math/depthwise_conv_3x3.h"
+#include "operators/op_param.h"
+namespace paddle_mobile {
+namespace operators {
+void ConvBNReluBasic(const FusionConvBNReluParam ¶m) {
+ const Tensor *input = param.Input();
+ Tensor filter = *param.Filter();
+ Tensor new_bias = *param.NewBias();
+ Tensor new_scale = *param.NewScale();
+
+ Tensor *output = param.Output();
+
+ int groups = param.Groups();
+ std::vector strides = param.Strides();
+ std::vector paddings = param.Paddings();
+ std::vector dilations = param.Dilations();
+
+ const int batch_size = static_cast(input->dims()[0]);
+
+ std::vector filter_shape_vec(framework::vectorize(filter.dims()));
+
+ std::vector output_shape_vec(framework::vectorize(output->dims()));
+ size_t data_dim = filter_shape_vec.size() - 2;
+ std::vector col_shape_vec(1 + 2 * data_dim);
+ col_shape_vec[0] = input->dims()[1] / groups;
+ for (size_t j = 0; j < data_dim; ++j) {
+ col_shape_vec[j + 1] = filter_shape_vec[j + 2];
+ col_shape_vec[j + 1 + data_dim] = output_shape_vec[j + 2];
+ }
+ framework::DDim col_shape(framework::make_ddim(col_shape_vec));
+
+ framework::DDim col_matrix_shape =
+ framework::flatten_to_2d(col_shape, data_dim + 1);
+
+ bool is_expand =
+ math::IsExpand(filter_shape_vec, strides, paddings, dilations);
+ Tensor col;
+ Tensor col_matrix;
+ if (is_expand) {
+ col.mutable_data(col_shape);
+ col_matrix.ShareDataWith(col);
+ col_matrix.Resize(col_matrix_shape);
+ }
+
+ framework::DDim input_shape = framework::slice_ddim(
+ input->dims(), 1, static_cast(input->dims().size()));
+
+ framework::DDim filter_matrix_shape = {filter.dims()[0],
+ filter.numel() / filter.dims()[0]};
+ filter.Resize(filter_matrix_shape);
+ framework::DDim output_matrix_shape = {
+ output->dims()[1],
+ output->numel() / (output->dims()[0] * output->dims()[1])};
+
+ // convolution operator: im2col(or vol2col) + gemm
+ int in_step = static_cast