tensorflow & mnist & CNN
来源:互联网 发布:福建农林大学网络教学 编辑:程序博客网 时间:2024/06/07 03:07
import tensorflow as tffrom tensorflow.examples.tutorials.mnist import input_dataimport cv2import numpy as np# import osmnist = input_data.read_data_sets('./1/', one_hot=True)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]))x1 = tf.arg_max(y,1)y1 = tf.arg_max(y_,1)sess = tf.InteractiveSession()tf.global_variables_initializer().run()saver = tf.train.Saver()saver.restore(sess, "./SoftmaxSaver/model.ckpt") # restore the softmax modelfor i in range(10): # bat_x, bat_y = mnist.test.next_batch(1) bat_x, bat_y = mnist.test.next_batch(1) print len(bat_x[0]) img = np.reshape(bat_x,(28,28)) cv2.imshow("s",img) cv2.waitKey() print "forecast %g"%sess.run(x1, feed_dict={x: bat_x}) # return the forecast(predictable) labels print "accurate %d"%sess.run(y1,feed_dict={y_: bat_y}) # return the accurate labels # x2 = tf.arg_max(bat_y, 1) # print x2 # print bat_ycorrect_prediction = tf.equal(tf.arg_max(y, 1), tf.arg_max(y_, 1))accuracy = tf.reduce_mean(tf.cast(correct_prediction, "float"))print sess.run(x1,feed_dict={x:mnist.test.images})print sess.run(accuracy, feed_dict={x: mnist.test.images, y_: mnist.test.labels})
阅读全文
0 0
- tensorflow CNN for mnist
- TensorFlow入门-MNIST & CNN
- tensorflow & mnist & CNN
- 暑期 tensorflow+CNN+mnist
- TensorFlow MNIST CNN LeNet5模型
- 【TensorFlow】MNIST(使用CNN)
- tensorflow入门 ubuntu mnist cnn例程
- Tensorflow训练CNN网络识别mnist
- Tensorflow中mnist数据使用CNN训练
- Tensorflow + Mnist (两层CNN,两层全连接)
- tensorflow中CNN对mnist识别
- tensorflow进行MNIST手写数字识别-CNN
- Tensorflow实战-CNN网络Mnist识别
- Tensorflow Cnn mnist 的一些细节
- tensorflow学习之---CNN识别MNIST
- tensorflow之用CNN识别MNIST
- TensorFlow的cnn做mnist例子
- Tensorflow的MNIST进阶教程CNN网络参数理解
- java,super()的位置和参数
- git fetch 和 git pull 的区别
- win8中写好的程序,在win7中没办法运行
- Codeforces Round #418 (Div. 2) C. An impassioned circulation of affection 预处理
- NOIP2017模拟赛(四)总结
- tensorflow & mnist & CNN
- SSH框架
- 实现拦截一条有序广播
- 你的坚持,终将美好
- Struts.xml文件编辑时没有提示的问题
- RNA-seq中的基因表达量计算和表达差异分析
- KNN实现
- 计蒜客复赛B题 Windows 画图
- 文本输出的变量插入