[DL4J] Image

[목차]

(0) 환경 설정 : DL4J 개발 환경 설정 및 예제 설명 (完)

(1) Data Iterator : 사용하고자 하는 데이터를 DL4J 에서 사용가능한 형태로 변환하는 작업 개발 필요

• Canova: The Rosetta Stone of Vectorization

• Spark

• Hadoop

• JDBC

Text ,CSV (完)

• Image

• Sound

• Video

(2) Net : 사용할 신경망의 형태가 어떤 것이 있는지 이해하고 선택, 활용 할 수 있어야 함
• Restricted Boltzmann machines (完)
• Convolutional nets (完)
• Recursive autoencoders (完)
• Recurrent nets: Long Short-Term Memory (LSTM) (including bi-directional LSTMs)
• Deep-belief networks
• Denoising and Stacked Denoising autoencoders
• Deep autoencoders

(3) Activation : Weight + Bias 결과 다음 적용할 함수 결정 (예 : SigMoid : Chap1 에서 설명한 것)

• ReLU (完)
• Leaky ReLU
• Tanh
• Sigmoid
• Hard Tanh
• Softmax
• Identity
• ELU: Exponential Linear Units
• Softsign
• Softplus

(4) Loss&Objective Functions : 일부 데이터를 누락함으로써 더 Robust 한 모델을 만들 수 있다.
• Reconstruction entropy
• Squared loss
• Mean squared error
• Multi-class cross entropy for classification
• Negative log likelihood
• RMSE_XENT

(5) Hyperparameters : 모든 Layer 에 공통적으로 적용되는 파라메터로 숙지 필요

• Dropout (random ommission of feature detectors to prevent overfitting)
• Sparsity (force activations of sparse/rare inputs)
• Adagrad (feature-specific learning-rate optimization)
• L1 and L2 regularization (weight decay)
• Weight transforms (useful for deep autoencoders)
• Probability distribution manipulation for initial weight generation
• Gradient normalization and clipping

(6) Event Listener & Result Anal : 분석 중간 발생하는 이벤트를 받아서 처리 및 결과에 대한 검증 및 비지니스 연동 등

(7) 모델 저장 및 로딩

• 매번 모든 데이터를 로딩하여 학습 시키는 것이 아니라, 모델 자체를 저장하고, 새로 발생하는 데이터만 학습 시킴으로써,

모델의 즉각적인 학습효과와 대량 데이터 처리에 따른 Performacne 문제를 해결 할수 있을 것으로 보임

http://deeplearning4j.org/modelpersistence

0.개요

Canova Lib 는 다양한 입출력 데이터를 지원한다. DL4J 사이트에서 정리된 자료를 찾고자 하였으나 찾지 못하여,

ND4J 사이트에서 Canova 관련 카테고리에서 유사한 내용을 찾아 정리하고자 한다.

(ND4J 는다양한 수학함수를 제공하는 라이브러리로 Nuppy 보다 4배정도 빠른 연산속도를 보여준다고 함)

http://nd4j.org/get-data-into-canova

○ FileRecordReader (Raw Text as Input)

– Input Format : org.canova.cli.formats.input.TextInputFormat

. FileRecordReader 를 상속받음 한나의 라인을 하나의 Record 로 생각함

– output Format : { csvLineString, dirLabelString }

. 폴더 이름이나, 고유한 ID 로 Label 를 자동으로 생성함

CSVRecordReader (CSV Records as Input)

– Input Format : org.canova.api.formats.input.impl.LineInputFormat

. CSV 는 이미 정형화된 구조임으로 nomalize, binarize, skip, label 만 정의하면 됨

– output Format : { string }

. 라벨 값은 CSV 데이터 안에 포함되어 있음

ImageRecordReader (Image Data as Input)

– Input Format : org.canova.api.formats.input.impl.ImageInputFormat

– output Format : { [array of doubles], directoryLabelID }

. 이미지 데이터와 라벨 값

MNISTRecordReader (Custom Binary Format Data)

– Input Format : org.canova.image.format.MNISTInputFormat

– output Format : { [array of doubles], classIndexID}

1. ImageRecordReader

(1) Loading Labels

이미지에 라벨을 붙이는 과정 , 서브 폴더명을 라벨로 사용하는 예

※ 아래와 같은 과정이라면 폴더명이 아닌 다른 기준으로 라벨링 가능하다고 보여짐

// Set path to the labeled images
String labeledPath = System.getProperty("user.home")+"/lfw";

//create array of strings called labels
List<String> labels = new ArrayList<>();

//traverse dataset to get each label
for(File f : new File(labeledPath).list Files()) {
labels.add(f.getName());
}

 

(2) Reading Records, Iterating Over Data

28 X 28 사이즈로 이미지를 Input Data 로 변환함 이 사이즈는 변경 가능함

true 파라메터는 라벨 값을 append 하는 것에 대한 허용

// Instantiating RecordReader. Specify height and width of images.
RecordReader recordReader = new ImageRecordReader(28, 28, true, labels);

// Point to data path.
recordReader.initialize(new FileSplit(new File(labeledPath)));

 

(3) Canova to DL4J

Canova 데이터 형을 최종적으로DL4J 데이터 형으로 변환한다.

DataSetIterator iter = new RecordReaderDataSetIterator(recordReader, 784, labels.size());

 

※ 위와 같이 실제 이미지에 라벨을 붙이고 DL4J 분석을 위한 Iterator 로 변환하는 과정을 거친다고 하면,

Location 2 Image 형태의 분석 아이디어를 서버에 구축하기 위한 아키택쳐를 어떻게 구성해야 할지 고민이 된다.

DB -> Image 생성 -> Canova -> DL4J 라고 하면 전처리 과정이 너무 많아 지는 것이 아닌지 고민됨

직접 DB 에서 DL4J 로 학습시키는 것과 차이가 있는지 고민 필요

Leave a Reply

Your email address will not be published. Required fields are marked *