https://blog.csdn.net/weixin_39673686/article/details/81068582


import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_data
#  自己下载 MNIST_data 数据集,  csdn  上下载很快
mnist_data_folder="/home/zhangjun/miniconda3/envs/tensorflow/MNIST_data"
mnist=input_data.read_data_sets(mnist_data_folder,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.matmul(x, W) + b# Define loss and optimizer y_ = tf.placeholder(tf.float32, [None, 10]) # The raw formulation of cross-entropy, # # tf.reduce_mean(-tf.reduce_sum(y_ * tf.log(tf.nn.softmax(y)), # reduction_indices=[1])) #
# can be numerically unstable. #
# So here we use tf.nn.softmax_cross_entropy_with_logits on the raw
# outputs of 'y', and then average across the batch.cross_entropy = tf.reduce_mean( tf.nn.softmax_cross_entropy_with_logits(labels=y_, logits=y))train_step = tf.train.GradientDescentOptimizer(0.5).minimize(cross_entropy)
sess = tf.InteractiveSession()tf.global_variables_initializer().run()# Train
for _ in range(1000): batch_xs, batch_ys = mnist.train.next_batch(100) sess.run(train_step, feed_dict={x: batch_xs, y_: batch_ys})
# Test trained modelcorrect_prediction = tf.equal(tf.argmax(y, 1), tf.argmax(y_, 1))
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
print(sess.run(accuracy, feed_dict={x: mnist.test.images, y_: mnist.test.labels}))

Tensorflow mnist 数据集测试代码 + 自己下载数据相关推荐

  1. MATLAB实现基于BP神经网络的手写数字识别+GUI界面+mnist数据集测试

    文章目录 MATLAB实现基于BP神经网络的手写数字识别+GUI界面+mnist数据集测试 一.题目要求 二.完整的目录结构说明 三.Mnist数据集及数据格式转换 四.BP神经网络相关知识 4.1 ...

  2. TensorFlow Mnist数据集下载问题

    安装好TensorFlow后,按教程输入如下命令时,会出现不能下载数据的问题. from tensorflow.examples.tutorials.mnist import input_data m ...

  3. GAN生成对抗网络基本概念及基于mnist数据集的代码实现

    本文主要总结了GAN(Generative Adversarial Networks) 生成对抗网络的基本原理并通过mnist数据集展示GAN网络的应用. GAN网络是由两个目标相对立的网络构成的,在 ...

  4. 原始GAN-pytorch-生成MNIST数据集(代码)

    文章目录 原始GAN生成MNIST数据集 1. Data loading and preparing 2. Dataset and Model parameter 3. Result save pat ...

  5. junit编写测试代码_编写数据访问代码测试-不测试框架

    junit编写测试代码 当我们向数据访问代码编写测试时,是否应该测试其公共API的每种方法? 一开始听起来很自然. 毕竟,如果我们不测试所有内容,那么如何知道我们的代码可以按预期工作? 这个问题为我们 ...

  6. junit编写测试代码_编写数据访问代码测试–绿色建筑不够好

    junit编写测试代码 开始为数据访问代码编写集成测试之前,我们要做的第一件事是决定如何配置测试用例. 我们有两种选择:正确的一种和错误的一种. 不幸的是,许多开发人员选择错误. 我们如何避免犯同样的 ...

  7. Tensorflow— MNIST数据集分类简单版本

    代码: import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data#载入数据集 #当前路径 m ...

  8. 【深度学习】2个经典的练手CNN源码与MNIST数据集测试结果

    对刚入门深度学习的童鞋,这2个简单的工程可快速入门.建议手敲一遍,可快速熟悉代码和CNN的实现流程. #1.导入相关库 import numpy as np import tensorflow as ...

  9. TensorFlow笔记(3)——利用TensorFlow和MNIST数据集训练一个最简单的手写数字识别模型...

    前言 当我们开始学习编程的时候,第一件事往往是学习打印"Hello World".就好比编程入门有Hello World,机器学习入门有MNIST. MNIST是一个入门级的计算机 ...

最新文章

  1. 简单套路发高分文章--杨树内生和根际微生物组结构
  2. 73. 解决ExtJS TreePanel 的 iconCls设置问题
  3. css叠层_CSS 中重要的层叠概念
  4. AngularJS 国际化 支持记录语言刷新后语言不变
  5. java.util.concurrent 学习(一)
  6. 设置kafka_2.13-3.0.0开机自启动
  7. DOS常用命令(从入门到精通)
  8. 360浏览器导出Excel闪退BUG
  9. python3安装setuptools步骤_详解Python3中setuptools、Pip安装教程
  10. 2021年下半年软考信息安全工程师下午案例题及解析
  11. 《一封神气的情书》李敖
  12. 一文读懂 12种卷积方法(含1x1卷积、转置卷积和深度可分离卷积等)
  13. 金蝶k3服务器物理内存过高,物理内存过高的解决办法
  14. 算法题(六十二)头条2017年笔试题——头条校招
  15. 时间颗粒度相关数据处理
  16. 使用gitbook记录笔记
  17. 居家隔离没事干?进来秒变算法工程师
  18. 图像边缘Canny算子提取
  19. 微信公众号开发之接收与发送消息
  20. usb万能驱动win7_win7还是win10?选对系统你就是国服最强王者

热门文章

  1. LeetCode 236. 二叉树的最近公共祖先
  2. 第二十四课.循环神经网络RNN
  3. 【问题收录】Ubuntu(14.04)那些我遇到的各种事
  4. php微信支付参数动态配置,支付,微信开发_微信支付动态如何获取$jsApiParameters参数,支付,微信开发 - phpStudy...
  5. linux 查进程对应用户,linux进程状态查询
  6. R语言完美重现STAMP结果图
  7. QIIME 2用户文档. 21图形界面q2studio(2019.7)
  8. NBT | 利用血液代谢组预测肠道微生物组的多样性
  9. USEARCH —— 最简单易学的扩增子分析流程
  10. linux 极简统计分析工具 datamash 必看教程