본문 바로가기
TensorFlow

TensorFlow Mechanics 101 (1)

by EasyGPT 2016. 4. 30.
반응형

TensorFlow Mechanics 101

Code: tensorflow/examples/tutorials/mnist/

교본은 (전형적인) MNIST 데이터집합을 사용하여 수기 숫자 분류에 대한 간단한 피드-포워드 신경망(NN) 훈련시키고 평가하기 위한 TensorFlow 사용방법을 보여주는데 목적이 있습니다.
교본의 의도된 대상은 TensorFlow 사용에 관심이 있는 경험 있는 ML 사용자입니다.
The goal of this tutorial is to show how to use TensorFlow to train and evaluate a simple feed-forward neural network for handwritten digit classification using the (classic) MNIST data set. The intended audience for this tutorial is experienced machine learning users interested in using TensorFlow.

이들 교본은 일반적인 ML 교습 목적이 아닙니다. install TensorFlow 지침대로 해야 합니다.
These tutorials are not intended for teaching Machine Learning in general.
Please ensure you have followed the instructions to 
install TensorFlow.

Tutorial Files

교본은 다음 파일들을 참조합니다: This tutorial references the following files:

File

Purpose

mnist.py

fully-connected MNIST 모델 구축을 위한 코드.
The code to build a fully-connected MNIST model.

fully_connected_feed.py

feed dictionary 사용하여 다운로드된 데이터집합에 대하여, 구축된 MNIST 모델을 훈련하기 위한 메인 코드.
The main code to train the built MNIST model against the downloaded dataset using a feed dictionary.


훈련 시작을 위하여 fully_connected_feed.py 파일을 직접 간단하게 가동 시키십시오:
python fully_connected_feed.py

Simply run the fully_connected_feed.py file directly to start training:

python fully_connected_feed.py

데이터 준비하기 Prepare the Data

MNIST ML 전형적인 문제입니다. MNIST is a classic problem in machine learning.

문제는 손으로 회색톤의 28x28 pixel 이미지의 숫자를 보고 이미지가 0부터 9까지의 숫자 어떤 숫자를 표현하는지 결정하는 것입니다.
The problem is to look at greyscale 28x28 pixel images of handwritten digits and determine which digit the image represents, for all the digits from zero to nine.

MNIST Digits

For more information, refer to Yann LeCun's MNIST page or Chris Olah's visualizations of MNIST.

Download

run_training() 메소드의 상단에서, input_data.read_data_sets() 함수가, 정확한 데이터가 로컬 training 폴더에 다운로드되고 그런 다음 해당 데이터가 분해되어 DataSet 인스턴스의 dictionary 확실하게 리턴할 것입니다.

data_sets = input_data.read_data_sets(FLAGS.train_dir, FLAGS.fake_data)

At the top of the run_training() method, the input_data.read_data_sets() function will ensure that the correct data has been downloaded to your local training folder and then unpack that data to return a dictionary of DataSet instances.

data_sets = input_data.read_data_sets(FLAGS.train_dir, FLAGS.fake_data)

 

: unit-testing 목적으로 fake_data flag 사용하는데, 안전 목적상 reader 무시해도 됩니다.
NOTE: The fake_data flag is used for unit-testing purposes and may be safely ignored by the reader.

 

Dataset

Purpose

data_sets.train

55000 images and labels, for primary training.

data_sets.validation

5000 images and labels, for iterative validation of training accuracy.

data_sets.test

10000 images and labels, for final testing of trained accuracy.

For more information about the data, please read the Download tutorial.

입력 플레이스홀더     Inputs and Placeholders

placeholder_inputs() 함수는, 그래프의 나머지에, 그리고 실제 훈련 예제가 공급받을, batch_size 포함된 입력 형태를 정의하는, 2개의 tf.placeholder ops 생성시킵니다.
The placeholder_inputs() function creates two 
tf.placeholder ops that define the shape of the inputs, including the batch_size, to the rest of the graph and into which the actual training examples will be fed.

 

images_placeholder = tf.placeholder(tf.float32, shape=(batch_size, IMAGE_PIXELS))

labels_placeholder = tf.placeholder(tf.int32, shape=(batch_size))

 

들어가서, 훈련용 loop안에서, 전체 이미지와 레이블 데이터집합을 스텝 batch_size 맞춰 나누고, 이들 placeholder ops 매치시키며, 그런 다음 feed_dict 매개변수를 사용하는 sess.run() 함수로 전달합니다.
Further down, in the training loop, the full image and label datasets are sliced to fit the batch_size for each step, matched with these placeholder ops, and then passed into the sess.run() function using the feed_dict parameter.

그래프 작성하기 Build the Graph

데이터용 placeholders 만든 , 3-단계 패턴 inference(), loss()  training() 따라 mnist.py 파일로부터 그래프를 작성합니다.

After creating placeholders for the data, the graph is built from the mnist.py file according to a 3-stage pattern:inference(), loss(), and training().

 

1.  inference() – 예측 목적에서, 방향 네트웍 가동에 요구되는 만큼 그래프를 작성합니다.
Builds the graph as far as is required for running the network forward to make predictions.

2.  loss() – loss 생성에 요구되는 ops 추정 그래프에 추가합니다.
Adds to the inference graph the ops required to generate loss.

3.  training() – 기울기를 계산하고 적용하는데 요구되는 ops 손실 그래프에 추가합니다.
Adds to the loss graph the ops required to compute and apply gradients.

https://www.tensorflow.org/versions/r0.7/images/mnist_subgraph.png

반응형

'TensorFlow' 카테고리의 다른 글

TensorFlow Mechanics 101 (3)  (0) 2016.04.30
TensorFlow Mechanics 101 (2)  (0) 2016.04.30
CNN (3)  (0) 2016.04.30
CNN (2)  (0) 2016.04.30
CNN (1)  (0) 2016.04.30

댓글