标签:
2015-11-10 16:10 830人阅读 (3)
分类:
深度学习(7)
版权声明:本文为博主原创文章,未经博主允许不得转载。
Google发布了开源深度学习工具TensorFlow。
根据官方教程 http://tensorflow.org/tutorials/mnist/beginners/index.md 试用。
操作系统是ubuntu 14.04,64位,python 2.7,已经安装足够的python包。
1. 安装 1.1 参考文档 http://tensorflow.org/get_started/os_setup.md#binary_installation
1.2 用pip安装,需要用代理,否则连不上,这个是本地ssh到vps出去的。 sudo pip install https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.5.0-cp27-none-linux_x86_64.whl --proxy http://127.0.0.1:3128 1.3 注意,我的py2.7已经安装了足够的包,如python-dev,numpy,swig等等。如果遇到缺少相应包的问题,先安装必须的包。 2. 第一个demo,test.py ------------------------------ import tensorflow as tf hello = tf.constant('Hello, TensorFlow!') sess = tf.Session() print sess.run(hello) a = tf.constant(10) b = tf.constant(32) print sess.run(a+b) ------------------------------ 3. mnist手写识别 3.1 下载数据库 在http://yann.lecun.com/exdb/mnist/下载上面提到的4个gz文件,放到本地目录如 /tmp/mnist
3.2 下载input_data.py,放在/home/tim/test目录下
https://tensorflow.googlesource.com/tensorflow/+/master/tensorflow/g3doc/tutorials/mnist/input_data.py
3.3 在/home/tim/test目录下创建文件test_tensor_flow_mnist.py,内容如下 ----------------------- #!/usr/bin/env python import input_data import tensorflow as tf mnist = input_data.read_data_sets("/tmp/mnist", one_hot=True) x = tf.placeholder("float", [None, 784]) W = tf.Variable(tf.zeros([784,10])) b = tf.Variable(tf.zeros([10])) y = tf.nn.softmax(tf.matmul(x,W) + b) y_ = tf.placeholder("float", [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) 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}) 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}) ----------------------- 3.4 运行。大概之需要几秒钟时间,输出结果是91%左右。
4. 关于版本
4.1 pip version
pip 1.5.4 from /usr/lib/python2.7/dist-packages (python 2.7) 4.2 已经安装的python包有一些是用easy_install安装的,大部分是pip安装的。
pip freezeJinja2==2.7.2MarkupSafe==0.18MySQL-python==1.2.3PAM==0.4.2Pillow==2.3.0Twisted-Core==13.2.0Twisted-Web==13.2.0adium-theme-ubuntu==0.3.4apt-xapian-index==0.45argparse==1.2.1beautifulsoup4==4.2.1chardet==2.0.1colorama==0.2.5command-not-found==0.3cvxopt==1.1.4debtagshw==0.1decorator==3.4.0defer==1.0.6dirspec==13.10duplicity==0.6.23fp-growth==0.1.2html5lib==0.999httplib2==0.8ipython==1.2.1joblib==0.7.1lockfile==0.8lxml==3.3.3matplotlib==1.4.3nose==1.3.1numexpr==2.2.2numpy==1.9.2oauthlib==0.6.1oneconf==0.3.7openpyxl==1.7.0pandas==0.13.1patsy==0.2.1pexpect==3.1piston-mini-client==0.7.5pyOpenSSL==0.13pycrypto==2.6.1pycups==1.9.66pycurl==7.19.3pygobject==3.12.0pygraphviz==1.2pyparsing==2.0.3pyserial==2.6pysmbc==1.0.14.1python-apt==0.9.3.5python-dateutil==2.4.2python-debian==0.1.21-nmu2ubuntu2pytz==2012cpyxdg==0.25pyzmq==14.0.1reportlab==3.0requests==2.2.1scipy==0.13.3sessioninstaller==0.0.0simplegeneric==0.8.1simplejson==3.3.1six==1.10.0software-center-aptd-plugins==0.0.0ssh-import-id==3.21statsmodels==0.5.0sympy==0.7.4.1system-service==0.1.6tables==3.1.1tensorflow==0.5.0tornado==3.1.1unity-lens-photos==1.0urllib3==1.7.1vboxapi==1.0wheel==0.24.0wsgiref==0.1.2xdiagnose==3.6.3build2xlrd==0.9.2xlwt==0.7.5zope.interface==4.0.5