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. WinFrom 第三方控件 TeleRik控件

    1.首先从工具-拓展与应用中下载安装  TeleRik WinFroms VsExtensions   TeleRik dll文件     2.工具箱控件  将Telerik控件更新过来 3.新建一个 ...

  2. Sql创建约束

    add constraint pk_studentno primary key(StudentNo) //主键 add constraint fk_student_grade_gradeid fore ...

  3. iOS开发之--使用storyboard进行跳转

    iOS开发中使用故事板进行开发是非常高效的一种方式,虽然有这样那样的问题,但是不得不承认,使用sb可以在最短的时间内完成整个项目的布局,节约开发者大量的时间,而且便于修改,非常直观,虽然可能不太灵活, ...

  4. solr初认识

    Solr : Search On Lucene Replication Solr 基本概况 Apache Solr (读音: SOLer) 是一个开源的搜索服务器.Solr 使用 Java 语言开发, ...

  5. open() 函数以 a+ 模式打开文件

    这种模式打开文件,可读可写,从文件顶部读取内容,从文件底部追加内容,文件不存在则自动创建 [root@localhost ~]$ cat 1.txt aaa bbb ccc In [1]: data ...

  6. 开发VS2008 AddIn 入门Sample

    本文主要介绍的是VS2008插件开发 环境要求:VS2008:.Net3.5 目标:开发插件功能为“在VS中创建文本文档,并在文本开头输入//This code was created For Tes ...

  7. 170321、Spring+Quartz实现定时任务的配置方法

    Quartz是Java版开源定时调度器. 核心概念: Job 表示一个工作,要执行的具体内容.此接口中只有一个方法 void execute(JobExecutionContext context): ...

  8. ubuntu中vi编辑器键盘错乱的问题

    Ubuntu安装完成后vi编辑器键盘不能正常使用,使用下面方法解决: 编辑文件/etc/vim/vimrc.tiny,将“compatible”改成“nocompatible”非兼容模式: 并添加一句 ...

  9. netty/example/src/main/java/io/netty/example/http/snoop/

    netty/example/src/main/java/io/netty/example/http/snoop at 4.1 · netty/netty https://github.com/nett ...

  10. Elasticsearch提示low disk watermark [85%] exceeded on [UTyrLH40Q9uIzHzX-yMFXg][Sonofelice][/Users/baidu/Documents/work/soft/data/nodes/0] free: 15.2gb[13.4%], replicas will not be assigned to this node

    mac本地启动es之后发现运行一段时间一分钟就能打印好几条info日志: [--13T10::,][INFO ][o.e.c.r.a.DiskThresholdMonitor] [Sonofelice ...