• 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] Tutorial 1. MNIST For ML Beginners  (0) 2016.10.20
[TensorFlow] TensorFlow를 설치해보자. - CPU Only  (0) 2016.10.10
[Caffe] DIGITS에서 사용하는 caffe의 버전을 올려보자.  (0) 2016.03.18
[Caffe] NVIDIA DIGITS 버전 업데이트 하기.  (0) 2016.03.18
블로그 이미지

매직블럭

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

트랙백 0개, 댓글 0개가 달렸습니다

댓글을 달아 주세요

  • «
  • 1
  • ···
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • ···
  • 49
  • »

카테고리

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

태그목록

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

달력

«   2022/05   »
일 월 화 수 목 금 토
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        
05-20 06:34

LATEST FROM OUR BLOG

  • 골뱅이 연산자의 의미 (행렬곱)..
  • 프린터 용지 부족 문제를 해⋯.
  • [MXNet] 데이터 리스트를 만⋯.
  • 예쁘게 출력하자 pprint - pr⋯.
  • 작업표시줄 미리보기를 리스⋯.
  • 이미지 실제 파일 포맷 확인하기.
  • 알리 등 해외배송 배송상태를⋯.
  • 티스토리 코드블럭 내용을 복⋯.
  • warning 을 on/off 하자.
  • windows 10 파일 선택, 파일⋯.
RSS 구독하기

BLOG VISITORS

  • Total : 1,114,475
  • Today : 37
  • Yesterday : 672

Copyright © 2015 Socialdev. All Rights Reserved.

티스토리툴바