按照网上的教程配置,我试了一上午,都没有成功,最后在tensorflow官网中推荐的方法下完成了。
环境:ubuntu15.04
(1)配置python环境:sudo apt-get install python-pip python-dev python-virtualenv
(2)建立新的virtualenv环境:
$: virtualenv --system-site-packages ~/tensorflow
$:cd ~/tensorflow
(3)激活virtualenv:source bin/activate # If using bash我的就是bash
(4)对于64位的linux:
# For CPU-only linux x86_64 version (tensorflow)$ pip install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.5.0-cp27-none-linux_x86_64.whl
运行一个小例子进行测试:
(1)首先下载一个input_data.py,地址:https://tensorflow.googlesource.com/tensorflow/+/master/tensorflow/g3doc/tutorials/mnist/input_data.py
(2)按照官网教程中对于mnist的例子的介绍,写出代码,保存为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})
并将这两个文件放入$/tim/test中
(3)下载mnist数据库,将t10k-images-idx3-ubyte.gz、t10k-labels-idx1-ubyte.gz、train-images-idx3-ubyte.gz、train-labels-idx1-ubyte.gz放入/tmp/mnist中
(4)运行test_tensor_flow_mnist.py,得到结果,正确率在91%左右(注意改文件权限,在激活virutalenv下运行)
ubuntu15.10源码安装tensorflow:http://www.linuxdiyf.com/linux/16089.html