• Tistory
    • 태그
    • 위치로그
    • 방명록
    • 관리자
    • 글쓰기
Carousel 01
Carousel 02
Previous Next

[TensorFlow] Tutorial 1. MNIST For ML Beginners

전공관련/Deep Learning 2016. 10. 20. 09:31




텐서플로우 튜토리얼 따라하기 1편.


코드 복사해서 돌려보고 분석하기.


#-*- coding: utf-8 -*-

#MNIST For ML Beginners
import tensorflow as tf

from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets("MNIST_data/", one_hot=True)

# train data y = xW+b
# placeholder와 variable 차이는 session 생성 전에 초기화 유무.
x = tf.placeholder(tf.float32, [None, 784]) # 28*28 = 784 dim
W = tf.Variable(tf.zeros([784, 10])) # 784 * 10 class
b = tf.Variable(tf.zeros([10]))
y = tf.nn.softmax(tf.matmul(x, W) + b)

# label
y_ = tf.placeholder(tf.float32, [None, 10]) # none은 행의 수가 한정되지 않음을 의미.

# define loss
cross_entropy = tf.reduce_mean(-tf.reduce_sum(y_ * tf.log(y), reduction_indices=[1]))

# define weight update method
train_step = tf.train.GradientDescentOptimizer(0.5).minimize(cross_entropy)

# define init variable 변수는 초기화 필수
init = tf.initialize_all_variables()

# create session
sess = tf.Session()

# initialization
sess.run(init)

# training / batch size : 100 / iteration 100
for i in range(1000):
batch_xs, batch_ys = mnist.train.next_batch(100)
# python 문법. feed_dict 파라미터에 직접 dictionary 넣어주기.
sess.run(train_step, feed_dict={x: batch_xs, y_: batch_ys})

# define correctness
correct_prediction = tf.equal(tf.argmax(y,1), tf.argmax(y_,1))

# bool을 float으로 캐스팅하고 평균을 구함. 즉 맞은 확률 계산.
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))

# run & print
print(sess.run(accuracy, feed_dict={x: mnist.test.images, y_: mnist.test.labels}))


저작자표시 비영리 (새창열림)

'전공관련 > Deep Learning' 카테고리의 다른 글

[TensorFlow] Tutorial 3. TensorFlow Mechanics 101  (0) 2016.11.02
[TensorFlow] Tutorial 2. Deep MNIST for Experts  (0) 2016.11.02
[TensorFlow] TensorFlow를 설치해보자. - CPU Only  (0) 2016.10.10
[Caffe] DIGITS에서 사용하는 caffe의 버전을 올려보자.  (0) 2016.03.18
[Caffe] NVIDIA DIGITS 버전 업데이트 하기.  (0) 2016.03.18
블로그 이미지

매직블럭

작은 지식들 그리고 기억 한조각

,

카테고리

  • 살다보니.. (449)
    • 주절거림 (3)
    • 취미생활 (36)
      • 지식과 지혜 (3)
      • 풍경이 되어 (4)
      • Memories (17)
      • 엥겔지수를 높여라 (2)
    • mathematics (6)
      • Matrix Computation (2)
      • RandomProcesses (3)
    • English.. (8)
    • Programming (147)
      • C, C++, MFC (51)
      • C# (1)
      • OpenCV (17)
      • Python (58)
      • Git, Docker (3)
      • Matlab (4)
      • Windows (3)
      • Kinect V2 (2)
      • 기타 etc. (8)
    • 전공관련 (80)
      • Algorithm (6)
      • Deep Learning (54)
      • 실습 프로그램 (4)
      • 주워들은 용어정리 (8)
      • 기타 etc. (8)
    • Computer (118)
      • Utility (21)
      • Windows (31)
      • Mac (4)
      • Ubuntu, Linux (58)
      • NAS (2)
      • Embedded, Mobile (2)
    • IT, Device (41)
      • 제품 사용기, 개봉기 (14)
      • 스마트 체험단 신청 (27)
    • Wish List (3)
    • TISTORY TIP (5)
    • 미분류. 수정중 (1)

태그목록

  • ColorMeRad
  • review
  • 포르투갈
  • 칼로리 대폭발
  • matlab
  • DeepLearning
  • 에누리닷컴
  • random variable
  • 오봉자싸롱
  • LIBSVM
  • Convolutional Neural Networks
  • 크롬
  • 일본
  • function
  • 후쿠오카
  • 매트랩
  • utility
  • ReadString
  • 스마트체험단
  • CStdioFile
  • 갤럭시노트3
  • DSLR
  • 매트랩 함수
  • SVM
  • portugal
  • Deep Learning
  • Computer Tip
  • 큐슈
  • 딥러닝
  • matlab function

달력

«   2025/07   »
일 월 화 수 목 금 토
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
07-04 15:47

LATEST FROM OUR BLOG

RSS 구독하기

BLOG VISITORS

  • Total :
  • Today :
  • Yesterday :

Copyright © 2015 Socialdev. All Rights Reserved.

티스토리툴바