Tensorflow 기초 - Window 에서 사용하기


Leaner Regression 에 대한 CostFunction
     

 

Tensorflow - TensorBoard
  • Tensorflow 에 기록된 로그를 시각화하여 보여주는 도구
  • 로그를 시각화하는 것이기 때문에 이전 로그 기록도 그대로 시각화 해준다.

Jupyter 에서 설치


Trouble Shooting
  • Check that jupyter-tensorboard, tensorflow and tensorboard are all installed via pip list|grep tensor, you should see at least three lines, jupyter-tensorboard, tensorflow and tensorflow-tensorboard (or tensorboard ). And also, check that tensorflow version is >=1.3.
  • Check that jupyter notebook is installed in the same python version via pip list|grep notebook, you shold see notebook package.
  • If you have installed the package but no buttons of tensorboard in jupyter appear, you need to run jupyter tensorboard enable --user. The step should be performed in the installation process, however, in some cases it seems that the command is not executed.
  • Checking for error messages in the browser's Javascript console (e.g. CTRL+SHIFT+J in Chrome).
  • Check the issue page for this repository. If you can't find one that fits your problem, please create a new one!
  • https://stackoverflow.com/questions/46499808/pip-throws-typeerror-parse-got-an-unexpected-keyword-argument-transport-enco
    • jupyter-tensorboard 가 설치가 안되어 있어서 설치하는데 오류가 발생함.
      • conda install -c conda-forge keras 명령어 실행 중
      • 안될 경우 pip/index.py 파일 수정 필요  730 라인

TensorBoard
  • 노트북의 running 탭에 instance가 하나씩 생김.

TensorBoard 코드
  • 로그 지정
    • writer = tf.summary.FileWriter('./board/sample_2', sess.graph)




AdamOptimizer
  • Gradient Descent Optimization Algorithms 의 한 종류
  • Adam (Adaptive Moment Estimation)은 RMSProp과 Momentum 방식을 합친 것 같은 알고리즘이다. 이 방식에서는 Momentum 방식과 유사하게 지금까지 계산해온 기울기의 지수평균을 저장하며, RMSProp과 유사하게 기울기의 제곱값의 지수평균을 저장한다.
  • 출처 - http://shuuki4.github.io/deep%20learning/2016/05/20/Gradient-Descent-Algorithm-Overview.html

















Jquery 기반



용도

* width 가 100% 인 Image에 imageMap을 입히고 싶을때,

* imageMap 을 입힌 Image 에 onresize 를 통해 사이즈를 조절하고 싶을때 (ImageMap 을 동적으로 사용가능)



https://github.com/stowball/jQuery-rwdImageMaps


사용방법

0) Import 부터..

1) image 에 맞는 map 태그를 작성한다. (반드시 본래 사이즈에서 맞추어야 한다.)

2) css또는 script로 원하는 사이즈로 조절한다. 이때 %로도 가능하다. (ex : sytle="width:100%")

3) 아래 script를 포함시킨다.

$(document).ready(function(e) {
    $('img[usemap]').rwdImageMaps();
});

4) 정상적으로 동작하는지 테스트한다.




2016.02.15일부로 

증상

Xcode로 앱 배포시 Missing iOS Distribution signing identity ...  가 뜨며 인증서를 찾지 못하는 오류.



세부증상

키체인 접근으로 들어가서 인증서를 보니 해당 배포 인증서에 "이 인증서는 유효하지 않은 발급자를 가지고 있음" 오류가 발생.
Apple Worldwide Developer Relations Certification Authority 인증서의 사용기간이 만료됨.



원인

애플에서 발급하는 인증서의
중간기관의 인증서 (WDRCA.CER) 의 인증서가 만료되었습니다. (서울 기준 16년 2월 15일 오전3시까지)
따라서 기존에 사용하던 배포용 인증서 또한 유효하지 않은 발급기관에서 발급한 인증서이므로 
인증서를 사용할 수 없습니다.


조치방법
1) 설치
로그인후 - MemberCenter - Certificates - + 버튼 - 최하단의 Apple Worldwide Developer Relations Certification Authority 다운로드 하여 설치.

2) 기존 인증서 삭제
스포트라이트 - 키체인 접근 - 보기 - 숨겨진 인증서 보기 클릭 - 
로그인, 인증서 에 있는Apple Worldwide Developer Relations Certification Authority 인증서 삭제
시스템, 인증서 에 있는Apple Worldwide Developer Relations Certification Authority 인증서 삭제
(기존 만료된 인증서가 로그인탭, 시스템탭 둘 중 하나라도 남아있으면 해결이 안됨.)

3) 기존 "이 인증서는 유효하지 않은 발급자를 가지고 있음" 오류 가 사라져있는것을 확인.



참고 URL





이클립스 각종 팁

[출처] http://blog.naver.com/sungback/90012467207  작성자 : 메멘토


이클립스 ini 파일 최적화

[출처] http://blog.naver.com/sungback/90012467207

http://kwonnam.pe.kr/wiki/eclipse/config


JS 관련 빌드속도증가

[출처] http://start.goodtime.co.kr/2013/10/%EC%9D%B4%ED%81%B4%EB%A6%BD%EC%8A%A4-validation-%EB%8B%B5%EB%8B%B5%EC%A6%9D/ 




※ window -> preference 를 한번씩 확인해보는 것이 좋다.

'프로그래밍' 카테고리의 다른 글

gRPC 예제 / (Python to nodeJS)  (0) 2018.11.12

특정 Activity LifeCycle 에 기능을 구현할 때 Row Coupling 을 위한 코딩 방법


1) 위 기능에 대하여 Activity 를 상속받는 A 클래스를 만든다. (ServerCheckActivity)

2) A 클래스의 기능을 구현한다.

3) 기존의 Activity 들에 대하여 Activity 를 상속받지 않게 하고 A 클래스를 상속받도록 한다.

4) 기존 Activity 의 oncreate 등의 원하는 LifeCycle 에 A 클래스의 적절한 함수를 실행시킨다. (상속받았으므로 사용 가능)

5) 필요한 경우 Callback 함수를 만들어 쓴다.


이제 관련 기능은 A 클래스만 조작하면 될것이다.




원래는 A 클래스를 따로 빼낼려고 했으나, 작업하면 할수록 A 클래스 내에서 UI 이벤트 쪽 구현에 문제가 생겨

아예 Activity 를 상속받는 방안으로 생각하여 진행한 방법이다.


 보통은 사용자 마다 (리눅스의 User)

.bash_profile 등의 사용자 초기 실행설정에서 

JDK_HOME 이라던가, PATH 등을 정의한다.


 그런데, 한 사용자가 JDK 1.7에서만 돌아가는 프로그램과 JDK 1.8에서만 돌아가는 프로그램 두개를 동시에 돌리게 된다면 어떻게 될까?

둘 중 하나는 지원되지 않는 버전일테고, 그 지원되지 않는 버전일 경우 오류가 발생한다.(UnsupportedClassVersionError)


 이를 해결하기 위해서는 각 프로그램은 각각 다른 패스를 바라볼 필요가 있다.

즉, 패스 관리를 프로그램 별로 하는 것이다.

만약 Java 1.7, Mysql 4.8 기반의 프로그램 이라면 리눅스의 PATH 변수에 두 실행파일의 경로를 넣어주면 되는것이다.


위 내용을 스크립트로 관리하는 것이 아래 내용이다.



 


아래는 Bitnami 의 Redmine Stacks 에서 실제 사용하는 방법이다.


1. 다음과 같은 파일을 만들어서 PATH 부분에 실행할 경로를 넣는다.  (Bitnami Redmine Stack 의 use_Redmine 파일을 참조하였다.)

#use_Redmine 파일

#!/bin/sh

 

PATH="/home/nanum/BitnamiRedmineStack2.5.2/perl/bin:/home/nanum/BitnamiRedmineStack2.5.2/sqlite/bin:/home/nanum/BitnamiRedmineStack2.5.2/ruby/bin:/home/nanum/BitnamiRedmineStack2.5.2/subversion/bin:/home/nanum/BitnamiRedmineStack2.5.2/postgresql/bin:/home/nanum/BitnamiRedmineStack2.5.2/php/bin:/home/nanum/BitnamiRedmineStack2.5.2/mysql/bin:/home/nanum/BitnamiRedmineStack2.5.2/apache2/bin:/home/nanum/BitnamiRedmineStack2.5.2/common/bin:$PATH"

 

exec /bin/bash --noprofile --norc

 

만약 리눅스에 설치되어 있는 기본 JDK 가 1.5인데 1.6 버전을 쓰고싶다면 

PATH="jdk 경로:$PATH" 를 넣어주면 된다.

 

2.  ./"파일이름" 으로 실행하면 쉘이 바로 실행되는데 이 쉘 안에서 실행하고 싶은 프로그램을 돌리면 된다.


   * export PATH=~~~ 가 아닌 PATH=~~~~ 로 되어있다는 것을 알아둬야한다.

     export 명령어를 안썻으니 위의 PATH는 일회용인 것이다.



ex)

./use_Redmine

./redmineCtrl start


 

 

위 방법을 사용하게 된 계기

Jenkins 를 리눅스에서 실행하는데 버전이 낮아서 오류가 났다.

 

 root 의 암호조차 모르던 상태였기 때문에 위 방법을 사용하여 해결하게 되었다.

 

물론 path를 export 한 뒤에 입력해도 된다. 하지만 위 방법이 더 안정성 있다고 생각되고

 

불필요한 작업을 줄인다고 생각하기에 사용하게 되었다.

 

<파일 내용>

#java1.6.sh

#!bin/sh

PATH="/home/alm/jdk1.6.0_45/bin:$PATH"

exec /bin/bash --noprofile --norc


실행 : ./java1.6.sh

  ./Jenkins.jar



 



nohup "실행할 명령어" &

 

뒤에 & 의 의미는 백그라운드로 실행한다는 뜻이며

앞에 nohup 의 의미는 hang-up signal ​을 무시한다는 것을 뜻합니다. (터미널 접속종료, Ctrl+C 등 무시)

즉, 터미널이 끊겨도 그대로 실행됩니다.

그리고 nohup.out 파일에 output 이 로그 형태로 쌓이게 됩니다.


정지 방법은 해당 pid 를 찾아서 kill -9 하는 방법입니다.


 

 

출처 : http://antamis.egloos.com/678228 


[MongoDB] shell 내에서 커서를 이용하여 연속으로 출력시키는 방법.

var myCursor = db.inventory.find().addOption(DBQuery.Option.noTimeout);

var myCursor = db.inventory.find();

var myFirstDocument = myCursor.hasNext() ? myCursor.next() : null;

myCursor.objsLeftInBatch();




많고 많은 라이브러리 중 하나.
보통은 json-simple 을 사용하는 것으로 알고 있다.

Json 오브젝트에서 Key의 메타 데이터를 가져올 수 있는 라이브러리가 있는지 확인하는 과정에서 나온 라이브러리. 원하는 건 못찾았다.


          try {
               JSONObject jObject = new JSONObject(jString);

               // menu jsonobject 생성
               JSONObject responseObject = jObject.getJSONObject("response");

              
               JSONObject header = responseObject.getJSONObject("header");
               System.out.println(header.toString());
              
               String resultMsg = header.getString("resultMsg");
               System.out.println(resultMsg);
               String resultCode = header.getString("resultCode");
               System.out.println(resultCode);

              
               JSONObject body = jObject.getJSONObject("response").getJSONObject("body");

               JSONArray item = body.getJSONObject("items").getJSONArray("item");
              
               for(int i=0; i<item.length(); i++){
                    JSONObject item_o =item.getJSONObject(i);
                    System.out.println(item_o.toString());
                   
                    int rnum = item_o.getInt("rnum");
                    System.out.println(rnum);
                    int code = item_o.getInt("code");
                    System.out.println(code);
                    String name = item_o.getString("name");
                    System.out.println(name);
                   
                    /*String rnum = item.getJSONObject(i).getString("rnum");
                    System.out.println(rnum);
                    String code = item.getJSONObject(i).getString("code");
                    System.out.println(code);
                    String name = item.getJSONObject(i).getString("name");
                    System.out.println(name);*/
               }
               int numOfRows = body.getInt("numOfRows");
               System.out.println(numOfRows);
               int pageNo = body.getInt("pageNo");
               System.out.println(pageNo);
               int totalCount = body.getInt("totalCount");
               System.out.println(totalCount);
              
    

          } catch (JSONException e) {
               // TODO Auto-generated catch block
               e.printStackTrace();
          }


JNI 패키지 컴파일 예제



 본 예제는 JNI 를 사용하였을 때 패키지에서의 컴파일 방법을 설명한 예제이다.

참조 : http://lng1982.tistory.com/153 패키지 컴파일 방법.
참조 : http://buedt.tistory.com/50  패키지 안에서 JNI 활용하기 (일반 방법하고 다르다.)

  * 소스 작성 : ~/simple-test/HelloJni

com.HelloWorld.java   -> com 폴더 안에 HelloWorld.java  JNI 모듈이다.
package com;

public class HelloWorld {
public HelloWorld (){
System.loadLibrary("HelloWorld");
}
public native void printHelloWorld();
}
  
com.main.java   -> com 폴더 안에 main.java    JNI 모듈을 사용할 메인 함수이다.
package com;

public class main {
public static void main(String[] args) {
HelloWorld hw = new HelloWorld();
hw.printHelloWorld();
}
}

  
  

  JNI 모듈을 헤더파일로 변경

javac ./com/HelloWorld.java
javah -cp ./ com.HelloWorld



  * javah 로 작성된 com_HelloWorld.h

com_HelloWorld.h    -> 요거는 com 폴더 안에 있는 것이 아니라 컴파일 루트에 있다.
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class com_HelloWorld */

#ifndef _Included_com_HelloWorld
#define _Included_com_HelloWorld
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: com_HelloWorld
* Method: printHelloWorld
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_com_HelloWorld_printHelloWorld
(JNIEnv *, jobject);


#ifdef __cplusplus
}
#endif
#endif

  * com_HelloWorld.h 에 맞춰서 작성한 .cpp 클래스

HelloWorld.cpp  -> vi HelloWorld.cpp 로 com 폴더 밖에서 작성.
#include <stdio.h>
#include "com_HelloWorld.h"

JNIEXPORT void JNICALL Java_com_HelloWorld_printHelloWorld
(JNIEnv *env, jobject obj){
printf("hi World \n");
return;
}

  동적 라이브러리 생성
gcc -fPIC -g -c -Wall -I /usr/lib/jvm/java-7-openjdk-amd64/include HelloWorld.cpp
gcc -shared -o libHelloWorld.so.1.0.1 HelloWorld.o -lc
ln -s libHelloWorld.so.1.0.1 libHelloWorld.so

  자바 컴파일 및 실행
javac -d . com/*.java
java -cp . com.main


  실행 모습









* 메모리 누수 관련 내용 추가


.cpp 파일에서 jstring param 의 데이터를 쓰고 난 뒤에는

반드시 Release를 해주어야 한다.

이는 jstring 객체 뿐만 아니라 다른  jobject 들도 마찬가지이다.

안 그러면 메모리 누수가 발생한다.



아래는 올바른 예제. 붉은색 글씨가 Get 하고 Release 하는 부분이다.


#include <jni.h>

#include "MessageType.h"

#include <stdio.h>

JNIEXPORT jstring JNICALL Java_MessageType_printMessage(JNIEnv* env, jobject obj, jstring msg) {

   char buf[128];

   const char *str = (*env)->GetStringUTFChars(env, msg, 0);

   printf("%s", str);

   (*env)->ReleaseStringUTFChars(env, msg, str);

   scanf("%s", buf);

   return (*env)->NewStringUTF(env, buf);

} 



출처 : https://rerethink.tistory.com/entry/jni%EB%AC%B8%EC%9E%90%EC%97%B4-%EC%A0%84%EB%8B%AC-%EC%9D%B8%EC%9E%90



'프로그래밍 > JAVA' 카테고리의 다른 글

JDK 버전 충돌이 날 경우 해결 방법  (1) 2016.02.12
Json Parser 라이브러리  (0) 2016.02.12

+ Recent posts