import tensorflow as tf
import numpy as np from tensorflow.examples.tutorials.mnist import input_data def initWeights(shape):
return tf.Variable(tf.random_normal(shape, stddev = 0.1)) def initBiases(shape):
return tf.Variable(tf.random_normal(shape, stddev = 0.1)) def model(X, weights, baises):
return tf.matmul(X, weights) + baises mnist = input_data.read_data_sets('MNIST_data/', one_hot = True)
trX, trY, teX, teY = mnist.train.images, mnist.train.labels, mnist.test.images, mnist.test.labels X = tf.placeholder('float', [None, 784])
Y = tf.placeholder('float', [None, 10]) learning_rate = 0.05
epcoh = 100 weights = initWeights([784,10])
biases = initBiases([10]) y_ = model(X, weights, biases)
cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(y_, Y))
train_op = tf.train.GradientDescentOptimizer(learning_rate).minimize(cost)
predict_op = tf.argmax(y_, 1) with tf.Session() as sess:
tf.initialize_all_variables().run()
for i in range(epcoh):
for start, end in zip(range(0, len(trX), 128), range(128, len(trX)+1, 128)):
sess.run(train_op, feed_dict = {X: trX[start:end], Y: trY[start:end]})
print (i, np.mean(np.argmax(teY, axis=1) == sess.run(predict_op, feed_dict={X: teX})))

由浅入深之Tensorflow(2)----logic_regression实现的更多相关文章

  1. 由浅入深之Tensorflow(3)----数据读取之TFRecords

    转载自http://blog.csdn.net/u012759136/article/details/52232266 原文作者github地址 概述 关于Tensorflow读取数据,官网给出了三种 ...

  2. 由浅入深之Tensorflow(1)----linear_regression实现

    Tensorflow是目前非常流行的deeplearning框架,学习Tensorflow最好的方法是github上的tf项目https://github.com/tensorflow/tensorf ...

  3. 由浅入深之Tensorflow(4)----Saver&restore

    x = tf.placeholder(tf.float32) y = tf.placeholder(tf.float32) w = tf.Variable(tf.zeros([1, 1], dtype ...

  4. Tensorflow之卷积神经网络(CNN)

    前馈神经网络的弊端 前一篇文章介绍过MNIST,是采用的前馈神经网络的结构,这种结构有一个很大的弊端,就是提供的样本必须面面俱到,否则就容易出现预测失败.如下图: 同样是在一个图片中找圆形,如果左边为 ...

  5. TensorFlow中的通信机制——Rendezvous(一)本地传输

    背景 [作者:DeepLearningStack,阿里巴巴算法工程师,开源TensorFlow Contributor] 在TensorFlow源码中我们经常能看到一个奇怪的词——Rendezvous ...

  6. 基于tensorflow的逻辑分类

    #!/usr/local/bin/python3 ##ljj [2] ##logic classify model import tensorflow as tf import matplotlib. ...

  7. Tensorflow代码解析(一)

    http://www.leiphone.com/news/201702/n0uj58iHaNpW9RJG.html?utm_source=tuicool&utm_medium=referral ...

  8. 人工智能热门图书(深度学习、TensorFlow)免费送!

    欢迎访问网易云社区,了解更多网易技术产品运营经验. 这个双十一,人工智能市场火爆,从智能音箱到智能分拣机器人,人工智能已逐渐渗透到我们的生活的方方面面.网易云社区联合博文视点为大家带来人工智能热门图书 ...

  9. 学习TF:《TensorFlow机器学习实战指南》中文PDF+英文PDF+代码

    从实战角度系统讲解TensorFlow基本概念及各种应用实践.真实的应用场景和数据,丰富的代码实例,详尽的操作步骤,带你由浅入深系统掌握TensorFlow机器学习算法及其实现. <Tensor ...

随机推荐

  1. Spring_day02--log4j介绍_Spring整合web项目演示

    log4j介绍 1 通过log4j可以看到程序运行过程中更详细的信息 (1)经常使用log4j查看日志 2 使用 (1)导入log4j的jar包 (2)复制log4j的配置文件,复制到src下面 3 ...

  2. 在Eclipse中显示.project和.classpath和.setting目录

    在Eclipse中显示.project, .classpath, .gitignore文件和.setting文件夹 在Eclipse中使用git,并显示.gitigonre文件,进行项目管理 在Ecl ...

  3. 最受欢迎的五大BUG管理系统

    五大最受欢迎的BUG管理系统    Google在中国大*陆遭遇变故做出暂时性的退出大*陆市场,也使很多忠实的用户受到小小的挫折,以本公司为例,原本的BUG都是记录在google的EXCEL在线文档中 ...

  4. docker的本地仓库换成阿里云的镜像仓库

    1,阿里云上注册账号,我的已经注册好了,仓库名称:registry.cn-hangzhou.aliyuncs.com/woccb2/chen 2,本地安装docker: yum -y install ...

  5. 【BZOJ1135】[POI2009]Lyz 线段树

    [BZOJ1135][POI2009]Lyz Description 初始时滑冰俱乐部有1到n号的溜冰鞋各k双.已知x号脚的人可以穿x到x+d的溜冰鞋. 有m次操作,每次包含两个数ri,xi代表来了x ...

  6. LVS负载均衡服务

    LVS负载均衡服务 LVS负载均衡调度技术是在Linux内核中实现的,因此被称为Linux虚拟服务器.使用LVS时,不能直接配置内核中的ipvs,而需要使用ipvs的管理工具ipvsadm进行管理. ...

  7. ZOJ 3932 Deque and Balls

    There are n balls, where the i-th ball is labeled as pi. You are going to put n balls into a deque. ...

  8. Windows的445端口(文件共享)

    周鸿祎:教育网大量电脑445端口暴露,导致中招_科技_腾讯网 http://tech.qq.com/a/20170513/016133.htm 互联网周鸿祎2017-05-13 12:04   据36 ...

  9. Python 名称空间与作用域、闭包与装饰器

    Python 的名称 Python 的名称(Name)是对象的一个标识(Identifier).我们知道,在 Python 里面一切皆对象,名称就是用来引用对象的.说得有点玄乎,我们以例子说明. 例如 ...

  10. 在Win10上,Android Studio检测不到设备的解决方案

    下载ADB驱动程序安装器 运行ADBDriverInstaller.exe,可以看到设备状态不正常,点击Install 可能会弹出这样的对话框,点击Got it, Restart Now,按照提示完成 ...