2017-01-04
Deep MNIST for Experts

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets('MNIST_data', one_hot=True)
import tensorflow as tf
sess = tf.InteractiveSession()
#None 表示这里可能存在很多个样本, 784=28*28表示共有784个像素点
#y_表示与x对应的label, 由于采用的是one_hot编码的所以是10维
x = tf.placeholder(tf.float32, shape=[None, 784])
y_ = tf.placeholder(tf.float32, shape=[None, 10])
W = tf.Variable(tf.zeros([784,10]))
b = tf.Variable(tf.zeros([10]))
sess.run(tf.global_variables_initializer())
# 假设 有X个样本,那么 (X*784) * (784*10) = (X*10)
y = tf.matmul(x,W) + b
cross_entropy = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(y, y_))

2016-12-28
install tensorflow

anaconda 提供了python科学计算的环境,为各种python软件包安装和管理提供了遍历,按照官方文档的方式即可以安装tensorflow.

创建tensorflow的虚拟环境

1
conda create -n tensorflow python=3.5

安装tensorflow

1
2
3
4
5
$ source activate tensorflow
(tensorflow)$ # Your prompt should change
# Linux/Mac OS X, Python 2.7/3.4/3.5, CPU only:
(tensorflow)$ conda install -c conda-forge tensorflow

如果网络状况不好,那么可以采用pip安装。

1
2
$ source activate tensorflow
(tensorflow)$ # Your prompt should change
1
export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.12.0-py3-none-any.whl

请注意这里不能采用pip3安装,因为anaconda环境中pip3安装是有问题的

1
pip install --ignore-installed --upgrade $TF_BINARY_URL

测试是否安装成功

1
2
import tensorflow as tf
print(tf.__versioin__)