ubuntu-kylin 16.04 LTS +VM12pro+py2.7+tensorflow0.8.0+mnist

引言

经过两天的不懈努力,外加翻看各种博客,论坛,安装,卸载,再安装。。。终于把这一套深度学习的入门工具和数据环境安装成功。下边就把这个过程详细记录下来,希望入手学习深度学习的小白们能少些弯路。

环境安装

1)下载ubuntu安装包
https://www.ubuntu.com/download/ubuntu-kylin

2)安装VM12和ubuntu-ylin16
https://jingyan.baidu.com/article/c275f6ba07e269e33d756714.html

上边两个安装比较顺利,主要把32位系统和64位系统不要搞错。

在这里用的是ubuntu自带的Python2.7环境。所以接下来就安装的是tensorflow -0.8.0

3)安装tensorflow0.8.0

  1. 打开终端输入以下命令
    sudo apt-get install python-pip python-dev
  2. 下载并安装tensorflow
    sudo pip install –upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.1.0-cp27-none-linux_x86_64.whl
    3.可能会出现pip版本过低等可输入:pip install –upgrade pip

4) 安装jupiter
打开终端输入
sudo pip install jupyter
可能会出现pip版本过低等可输入:pip install –upgrade pip

mnist手写字体数据导入

1)下载数据
http://yann.lecun.com/exdb/mnist/

可以自己先下载出来放到自己写成程序的文件夹的目录下“your程序/mnist”

2)下载数据处理程序input_data.py
链接1:http://download.csdn.net/download/zcf1784266476/9820328?locationNum=14&fps=1
运行程序出现以下错误:

File "g3doc/tutorials/mnist/input_data.py", line 60, in extract_images
    buf = bytestream.read(rows * cols * num_images)
  File "/usr/lib/python2.7/gzip.py", line 263, in read
    chunk = self.extrabuf\[offset: offset + size]
TypeError: only integer scalar arrays can be converted to a scalar index 

解决办法:

https://stackoverflow.com/questions/34010859/tensorflow-beginner-tutorial-read-data-sets-fails

也可以用我该好的程序input_data.py
链接:
链接: https://pan.baidu.com/s/1i49G3Hz 密码: 4b2n

曾经的尝试

anaconda3 4.2 + tensorflow0.12.0 这个是gpu版本 但是我的电脑没有GPU计算。。。然后
import tensorflow.examples.tutorials.mnist.input_data as input_data
mnist = input_data.read_data_sets(“MNIST_data/”, one_hot=True)
这两句一直出错。。。。

其实我想说这个方式安装真的没有省多少事。。。。

mnist手写字体softmax实现

softmax回归详解

http://blog.csdn.net/ly_ysys629/article/details/77618720

代码实现
import tensorflow as tf
import input_data
mnist = input_data.read_data_sets("mnist", one_hot=True)
Extracting mnist/train-images-idx3-ubyte.gz
Extracting mnist/train-labels-idx1-ubyte.gz
Extracting mnist/t10k-images-idx3-ubyte.gz
Extracting mnist/t10k-labels-idx1-ubyte.gz
print(mnist.train.images.shape,mnist.train.labels.shape)#训练模型
print(mnist.test.images.shape,mnist.test.images.shape)#在测试集熵评估模型
print(mnist.validation.images.shape,mnist.validation.images.shape)#调优模型
((55000, 784), (55000, 10))
((10000, 784), (10000, 784))
((5000, 784), (5000, 784))
#定义会话接口
sess = tf.InteractiveSession()

#存储输入数据的容器,一旦被使用,该数据就会被清除,
#None表示可以输入任意个样本点数,784为特征个数
x = tf.placeholder(tf.float32,[None,784])

#Variable()是用来存储模型参数,是永久存储,在模型训练过程中,参数可以被更新
#tf.zeros()表示对参数w,b进行0初始化。10表示类别个数。784表示特征个数。
w = tf.Variable(tf.zeros([784,10]))
b = tf.Variable(tf.zeros([10]))

#定义计算公式,y=softmax(wx+b)
#tf.nn包含了大量的圣经网络组件,tf.matmul()矩阵乘法函数
y = tf.nn.softmax(tf.matmul(x,w) + b)

#定义损失函数,softmax损失函数是交叉熵,y_true为实例的真实类别
y_true = tf.placeholder(tf.float32,[None,10])
#reduction_indices = [1]表示列方向。
cross_entropy = tf.reduce_mean(- tf.reduce_sum(y_true * tf.log(y),reduction_indices = [1]))

#指定训练过程中的优化器,0.5表示学习率
train_step = tf.train.GradientDescentOptimizer(0.5).minimize(cross_entropy)

#定义完成,执行计算图
init = tf.initialize_all_variables()
#sess = tf.Session()
sess.run(init)
#tf.global_variables_initializer().run()

#使用随机梯度下降算法,每次选择100个样本点,迭代的求解模型参数
for i in range(1000):
    batch_xs,batch_ys = mnist.train.next_batch(100)
    train_step.run({x: batch_xs,y_true: batch_ys})
#计算分类精度,tf.cast将输出的bool转换成float32
correct_prediction = tf.equal(tf.argmax(y,1),tf.argmax(y_true,1))
accuracy = tf.reduce_mean(tf.cast(correct_prediction,tf.float32))
print(accuracy.eval({x:mnist.test.images,y_true:mnist.test.labels}))

   #手写字体的分类精度
    0.9197
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

墨岚❤️

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值