CNN网络介绍与实践:王者荣耀英雄图片识别 (6)

先按q跳过开头的license,接着输入accept接受协议,然后按y键选择安装驱动程序,在之后的选择中,我们选择不安装OpenGL,否则可能出现在登录界面循环登录的问题。然后按n键选择不安装samples。

接下来安装cuDNN,cuDNN是NVIDIA推出的深度学习中的CNN和RNN的高度优化的实现,底层使用了很多先进的技术和接口,因此比其他GPU上的神经网络库性能高不少。首先从官网上下载cuDNN,这一步需要先注册NVIDIA的帐号,并等待审核。执行

cd /usr/local sudo tar -xzvf ~/Downloads/cudnn-8.0-linux-x64-v6.0.tgz

就完可以成了cuDNN的安装。

(2) 安装Tensorflow

在github上下载对应的版本,这里下载的是tensorflow_gpu-1.2.1-cp35-cp35m-

linux_x86_64.whl。然后执行如下命令即可完成安装。

pip install tensorflow_gpu-1.2.1-cp35-cp35m-linux_x86_64.whl

2.2 Hello World-MINST手写数字识别 2.2.1 使用线性模型 并使用softmax分类器

import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data mnist = input_data.read_data_sets("MNIST_data/", one_hot=True)print(mnist.train.images.shape, mnist.train.labels.shape)print(mnist.test.images.shape, mnist.test.labels.shape)print(mnist.validation.images.shape, mnist.validation.labels.shape) sess = tf.InteractiveSession() x = tf.placeholder(tf.float32, [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(tf.float32, [None, 10]) cross_entropy = tf.reduce_mean(-tf.reduce_sum(y_ * tf.log(y), reduction_indices=[1])) train_step = tf.train.GradientDescentOptimizer(0.5).minimize(cross_entropy) tf.global_variables_initializer().run() for i in range(1000): batch_xs, batch_ys = mnist.train.next_batch(1000) train_step.run({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, tf.float32))print(accu

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wpxjyd.html