import tensorflow as tf


//Load data

x = tf.placeholder(tf.float32,[None,784])  //data가 들어갈 부분

W = tf.Variable(tf.zeros([784,10]))  //학습될 weight의 자리 - 0으로 초기화

b = tf.Variable(tf.zeros([10])) //학습될 bias b의 자리 - 0으로 초기화

y = tf.nn.softmax(tf.matmul(x,W)+b) //


//Train the model

y_=tf.placeholder(tf.float32,[None,10])

cross_entropy = -tf.reduce_sum(y_ * tf.log(y))

train_step = tf.train.GradientDescentOptimizer(0.01).minimize(cross_entropy)

init = tf.initialize_all_variables()

sess = tf.Session()

sess.run(init)


//실제 train하는 부분 //데이터를 100개씩 1000번 주면서 train_step을 밟음

for i in range(1000):

  batch_xs, batch_ys = mnist.train.next_batch(100)

  sess.run(train_step, feed_dict={x: batch_xs, y_: batch_ys})


//Evaluate the model

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

accuracy = tf.reduce_mean(tf.cast(correct_prediction, "float"))

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


'COMPUTER > Machine Learning' 카테고리의 다른 글

추천 공부 할 링크  (0) 2022.06.20
머신 러닝 관련 용어  (0) 2015.07.17
Likelihood Function  (0) 2013.05.06
loss function  (0) 2013.05.06
매니폴드 러닝 (Manifold Learning)  (0) 2013.04.02

Mac OS에 설치후 파이썬에서 Import tensorflow as tf했더니 아래와 같은 에러가 난다..


Traceback (most recent call last):

  File "<stdin>", line 1, in <module>

  File "/Library/Python/2.7/site-packages/tensorflow/__init__.py", line 4, in <module>

    from tensorflow.python import *

  File "/Library/Python/2.7/site-packages/tensorflow/python/__init__.py", line 13, in <module>

    from tensorflow.core.framework.graph_pb2 import *

  File "/Library/Python/2.7/site-packages/tensorflow/core/framework/graph_pb2.py", line 8, in <module>

    from google.protobuf import reflection as _reflection

  File "/Library/Python/2.7/site-packages/google/protobuf/reflection.py", line 58, in <module>

    from google.protobuf.internal import python_message as message_impl

  File "/Library/Python/2.7/site-packages/google/protobuf/internal/python_message.py", line 59, in <module>

    import six.moves.copyreg as copyreg

ImportError: No module named copyreg



맥os에서 흔히 있는 문제들에 정리되어 있었네요... 

TensorFlow는 six-1.10.0가 필요한데 애플의 기본 python 환경은 six-1.4.1 이므로 업그레이드가 필요하다...


아래 커맨드로 해결


sudo easy_install -U six


여기 참고...

http://www.tensorflow.org/get_started/os_setup.html#on-macosx


TensorFlow

:Google에서 open한 machine learning api~


Tensor flow는 data flow graph로 computation을 표현 할 수 있다면, Tensor Flow를 사용 가능하다.


-data flow graph : 오토마타 시간에 배웠던 개념중에 하나군..상수,변수 등의 데이터와 그 사이의 operation을 하나의 graph형식의 machine으로 만드는 것...


machine learning 

- 실세계의 데이터로 컴퓨터를 가르치는 방법중에 하나로, 고품질 음성인식, practical 컴퓨터 인식(vision), email spam차단, self-driving 자동차 등에 쓰임..


대부분의 ML은 Labeled Data를 필요로 하지만, self-taught learning과 deep learning 같은 것들은 Label이 없는 데이터 들로도 학습이 가능할지도 모른다는 것을 시사한다..



DistBelief

Google의 딥러닝 인프라스트럭처.. 2011년에 개발됨

1. 고양이 사례에 이용

엄청나게 큰 neural network(16000개의 CPU core, 1billion개의 neural connection)를 구성해서 youtube동영상(unlabeled data)을 1주일 정도 보여줬더니.. 그 neural network가 고양이를 알아보기 시작함..

.DistBelief 를 이용해 이미지 분류 테스트를 한 관련논문-상대적으로 70프로의 성능 향상이 있었음(Building High-level Features Using Large Scale Unsupervised Learning,2012,ICML)

2. Google 앱의 speech recognition에 적용하여 성능을 25프로 향상시킴 

3. Google Photo 에도 사용

※ 한계점 : 설정이 어렵고, google의 internal resource에 tightly coupled 되어 있어 외부에서 사용은 불가능 했다...

이를 개선하여...외부로 open한것이 Tensor Flow!!!

게다가 TensorFlow가 DistBelief보다 2배나 더 빠르다는 연구 결과도 있다


사용하는 언어 : Python, C++

Python interface사용 가능

차후에 SWIG를 통ㅇ해 JAVA, Lua, Javscript,R까지 확장 할 수도 있음...




license 

: Apache license2.0


※ Apache License 2.0 - http://www.apache.org/licenses/LICENSE-2.0


Tensor는 형이 있는 다차원 배열임

Computation을 Graph로 나타내며, 노드는 operation, 여기에 들어가는 데이터가 tensor가 됨







http://googleresearch.blogspot.kr/2015/11/tensorflow-googles-latest-machine_9.html를 참고함...

+ Recent posts