[Deep learning] Gradient Descent Optimizer

이미지
https://icim.nims.re.kr/post/easyMath/70 알기 쉬운 산업수학 알기 쉬운 산업수학 Gradient Descent Optimizer 2017년 12월 13일(수) | 김민중 URL  (1) 주어진 목적함수  f f 의 최솟값(minimum)을 찾아가는 알고리즘으로 다음과 같은 방식으로 최솟값을 찾아간다. 초기값  x 0 x 0 을 임의로 설정, 적당한 Learning rate  α α  설정 n ≥ 0 n ≥ 0 인 정수에 대해서  x n + 1 x n + 1 은 다음과 같이 정의한다. x n + 1 : = x n − α ⋅ ∇ f ( x n ) x n + 1 := x n − α ⋅ ∇ f ( x n ) 주의사항 함수 f f 의 모양이 convex가 아닌 경우 global minimum이 아닌 local minimum으로  x n x n 이 수렴할 가능성이 있다. Learning rate  α α  값이 큰 경우 최솟값으로  x n x n 이 수렴하는 것이 아니라 발산할 수 있다. Learning rate  α α  값이 작은 경우 수렴하는 속도가 지나치게 느릴 수 있다. 방정식  2 ⋅ x = 10 2 ⋅ x = 10  의 근을 Gradient Descent를 이용해서 찾아보자. 목적함수  f ( x ) : = ( 10 − 2 x ) 2 f ( x ) := ( 10 − 2 x ) 2 으로 설정하겠다( f f 의 최솟값인 0이 되게 하는  x x 값이 우리가 원하는 방정식의 근이다). 초기값  x 0 = 0 x 0 = 0 , Learning rate  α = 0.05 α = 0.05 으로 설정 f ′ ( x ) = 4 ( 2 x − 10 ) f ′ ( x ) = 4 ( 2 x − 10 )...

ing~~~~ [Android][NDK] How to use c++ source in android?

1. Two method


1-1. NDK
[Ref] https://developer.android.com/ndk/samples/sample_hellojni.html?hl=ko


1-2. CMake
[Ref] https://developer.android.com/studio/projects/add-native-code.html?hl=ko
[Ref] https://developer.android.com/ndk/samples/sample_hellojni.html?hl=ko



2. NDK detail :
[Ref : https://www.youtube.com/watch?v=RmPuwdxR1qs ]
[Ref : http://kn-gloryo.github.io/Build_NDK_AndroidStudio_detail/]
[Ref : http://intellij.my/2017/05/10/how-to-create-a-c-library-with-ndk-on-android-studio/ ]


2-1. Android.mk

LOCAL_PATH := $(call my-dir)

OPENCV_INSTALL_MODULES := on

include $(CLEAR_VARS)
include D:/Data/Libraries/opencv-2.4.13.3-android-sdk/OpenCV-android-sdk/sdk/native/jni/OpenCV.mk
LOCAL_C_INCLUDES := D:/Data/Libraries/opencv-2.4.13.3-android-sdk/OpenCV-android-sdk/sdk/native/jni/include
LOCAL_C_INCLUDES += D:/Data/Libraries/opencv-2.4.13.3-android-sdk/OpenCV-android-sdk/sdk/native/jni/include/opencv
LOCAL_C_INCLUDES += D:/Data/Libraries/opencv-2.4.13.3-android-sdk/OpenCV-android-sdk/sdk/native/jni/include/opencv2

LOCAL_MODULE := liveness-lib
LOCAL_SRC_FILES := livenesslib.cpp
LOCAL_LDLIBS +=  -llog -ldl

LOCAL_CFLAGS += -fexceptions

include $(BUILD_SHARED_LIBRARY)


2-2. Application.mk

APP_MODULES := liveness-lib

APP_ABI := armeabi armeabi-v7a x86

APP_STL := stlport_static


2-3. export functions


//// Created by kisat on 2018-04-19.//
#include "com_liveness_livenesssample_LivenessNDK.h"#include "liveness.h"

#ifdef __cplusplus
extern "C" {
#endif/* * Class:     com_liveness_livenesssample_LivenessNDK * Method:    getVersion * Signature: ()Ljava/lang/String; */JNIEXPORT jstring JNICALL Java_com_liveness_livenesssample_LivenessNDK_getVersion
  (JNIEnv *env, jobject)
{

return (*env).NewStringUTF("0.0.2");}

#ifdef __cplusplus
}
#endif



2-4. Usage ( how to use the exported functions )

package com.liveness.livenesssample;
public class LivenessNDK {

    static {
        System.loadLibrary("liveness-lib");        System.loadLibrary("opencv_java");    }

    public native String getVersion();}


LivenessNDK liveNessNDK = null;
LivenessWrapper() {
    liveNessNDK = new LivenessNDK();}

public String getVersion() {
    return liveNessNDK.getVersion();}

2-5. External tools
2-5-1. javah
* Name : Javah
* Description : Tool for make header
* Program :  jdk install path + javah.exe  (ex>
C:\Program Files\Java\jdk1.8.0_121\bin\javah.exe )
* Arguments : -classpath $Classpath$ -v -jni $FileClass$
* Working Directory : $ProjectFileDir$\app\src\main\jni


2-5-2. ndk-build
* Name : ndk-build
* Program : ndk directory in android sdk folder ( ex> D:\Android_SDK\ndk-bundle\ndk-build.cmd )
* Working Directory : $ProjectFileDir$/app/src/main

2-5-3. ndk-clean
* Name : ndk-build clean
* Program : ndk directory in android sdk folder ( ex> D:\Android_SDK\ndk-bundle\ndk-build.cmd )
* Argument : clean
* Working Directory : $ProjectFileDir$/app/src/main










3. CMake detail

3-1.









---------------------------------------------------------------------------------------

Error1> Could not find method ndk() for arguments android

Solution1>  ndk block in gradle file to defaultConfig

example1>

It turns out that this code
ndk {
    moduleName "hello-android-jni"
    }
should be placed under "defaultConfig" block:
defaultConfig {
    applicationId "com.chenql.helloandroidjni"
    minSdkVersion 22
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

    ndk {
        moduleName "hello-android-jni"
    }
}
instaed of after "buildTypes" block.

Reference1> https://stackoverflow.com/questions/40501986/could-not-find-method-ndk-for-arguments




------------------------------------------------------------------------------------------



Error2> Error: unmappable character for encoding MS949

Solution2>  javac myjavasource.java -encoding UTF-8

------------------------------------------------------------------------------------












댓글

이 블로그의 인기 게시물

@import' when modules are disabled

MagicaVoxel black screen

[Anaconda][Opencv][Spyder] How to install opencv to anaconda (spyder).