TensorFlow学习记录2——基于softmax回归的分类算法
2019-05-29 16:16
417 查看
版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/JavenLau/article/details/90673061
主要参考博客
LightRNN:深度学习之以小见大
TensorFlow学习记录2——基于softmax回归的分类算法
主要参考博客
LightRNN:深度学习之以小见大
深入MNIST——
import tensorflow as tf import numpy as np import matplotlib.pylab as plt # prepare mnist data from tensorflow.examples.tutorials.mnist import input_data MNIST_data_folder = "D:\pycharm\OCR_Test_SH\src\LightRNN\MNIST_data" mnist = input_data.read_data_sets(MNIST_data_folder, one_hot=True) im = mnist.train.images[1] im=im.reshape(-1,28) print('input:', mnist.train.images.shape) # plt.imshow(im) # plt.show() sess = tf.InteractiveSession() x = tf.placeholder("float", shape=[None, 784]) y_ = tf.placeholder("float", shape=[None, 10]) W = tf.Variable(tf.zeros([784, 10])) b = tf.Variable(tf.zeros([10])) sess.run(tf.initialize_all_variables()) y = tf.nn.softmax(tf.matmul(x, W) + b) cross_entropy = -tf.reduce_sum(y_ * tf.log(y)) train_step = tf.train.GradientDescentOptimizer(0.01).minimize(cross_entropy) correct_prediction = tf.equal(tf.argmax(y, 1), tf.argmax(y_, 1)) accuracy = tf.reduce_mean(tf.cast(correct_prediction, "float")) for i in range(1000): batch = mnist.train.next_batch(50) train_step.run(feed_dict={x: batch[0], y_: batch[1]}) print(i, accuracy.eval(feed_dict={x: batch[0], y_: batch[1]})) print(accuracy.eval(feed_dict={x: mnist.test.images, y_: mnist.test.labels})) for i in range(0, len(mnist.test.images)): result_prediction = correct_prediction.eval(feed_dict={x: np.array([mnist.test.images[i]]), y_: np.array([mnist.test.labels[i]])}) if not result_prediction: label_arr = sess.run(y, feed_dict={x: np.array([mnist.test.images[i]]), y_: np.array([mnist.test.labels[i]])}) predict_arr = sess.run(y_, feed_dict={x: np.array([mnist.test.images[i]]), y_: np.array([mnist.test.labels[i]])}) label = tf.argmax(label_arr, 1) predict = tf.argmax(predict_arr, 1) print('the predict result of {} is error, the label is {} and the predict is {}'.format(i, label, predict)) current_image_arr = np.reshape(mnist.test.images[i], (28, 28)) current_image = np.matrix(current_image_arr, dtype="float") plt.imshow(current_image) plt.show() # break
待做:代码46行
相关文章推荐
- tensorflow学习笔记----当多分类问题遇见softmax
- 机器学习-分类算法-逻辑回归
- STL学习记录(十三):排序类算法及基于排序的算法
- TensorFlow学习Day3读取csv文件,动手写个logistic,softmax分类模型
- 深度学习-基于softmax神经网络分类的源码实现
- 【深度学习】笔记6:基于CIFAR10网络,训练自己的分类网络的记录
- 基于Tensorflow学习神经网络- NN(神经网络)发展-分类
- 【强化学习实战】基于gym和tensorflow的强化学习算法实现
- 斯坦福CS20SI:基于Tensorflow的深度学习研究课程笔记,Lecture note3:TensorFlow上的线性回归和逻辑回归
- Tensorflow实战学习(十)【softmax分类】
- tensorflow 学习专栏(四):使用tensorflow在mnist数据集上使用逻辑回归logistic Regression进行分类
- 基于概率论的分类方法:朴素贝叶斯算法实践学习
- [TensorFlow深度学习入门]实战四·逻辑回归鸢尾花进行分类(对比均方根误差与softmax交叉熵误差区别)
- 傻瓜式学习——基于MATLAB的SVM算法实现图像分类
- 人工智能算法学习笔记(七)——SoftMax回归
- tensorflow学习(三)基于mnist数据的十分类
- DeepLearning (四) 基于自编码算法与softmax回归的手写数字识别
- 基于概率论的分类方法:朴素贝叶斯算法实践学习
- 基于tensorflow的mnist的softmax分类
- caffe学习记录(三):多标签分类/回归训练(下)