吴裕雄 python 神经网络——TensorFlow 完整神经网络样例程序
import tensorflow as tf
from numpy.random import RandomState batch_size = 8
w1= tf.Variable(tf.random_normal([2, 3], stddev=1, seed=1))
w2= tf.Variable(tf.random_normal([3, 1], stddev=1, seed=1))
x = tf.placeholder(tf.float32, shape=(None, 2), name="x-input")
y_= tf.placeholder(tf.float32, shape=(None, 1), name='y-input') a = tf.matmul(x, w1)
y = tf.matmul(a, w2)
y = tf.sigmoid(y)
cross_entropy = -tf.reduce_mean(y_ * tf.log(tf.clip_by_value(y, 1e-10, 1.0))
+ (1 - y_) * tf.log(tf.clip_by_value(1 - y, 1e-10, 1.0)))
train_step = tf.train.AdamOptimizer(0.001).minimize(cross_entropy) rdm = RandomState(1)
X = rdm.rand(128,2)
Y = [[int(x1+x2 < 1)] for (x1, x2) in X] with tf.Session() as sess:
init_op = tf.global_variables_initializer()
sess.run(init_op) # 输出目前(未经训练)的参数取值。
print(sess.run(w1))
print(sess.run(w2))
print("\n") # 训练模型。
STEPS = 5000
for i in range(STEPS):
start = (i*batch_size) % 128
end = (i*batch_size) % 128 + batch_size
sess.run([train_step, y, y_], feed_dict={x: X[start:end], y_: Y[start:end]})
if i % 1000 == 0:
total_cross_entropy = sess.run(cross_entropy, feed_dict={x: X, y_: Y})
print("After %d training step(s), cross entropy on all data is %g" % (i, total_cross_entropy)) # 输出训练后的参数取值。
print("\n")
print(sess.run(w1))
print(sess.run(w2))

吴裕雄 python 神经网络——TensorFlow 完整神经网络样例程序的更多相关文章
- 80、tensorflow最佳实践样例程序
''' Created on Apr 21, 2017 @author: P0079482 ''' #-*- coding:utf-8 -*- import tensorflow as tf #定义神 ...
- 吴裕雄--天生自然 Tensorflow卷积神经网络:花朵图片识别
import os import numpy as np import matplotlib.pyplot as plt from PIL import Image, ImageChops from ...
- Android清理设备内存具体完整演示样例(二)
版权声明: https://blog.csdn.net/lfdfhl/article/details/27672913 MainActivity例如以下: package cc.c; import j ...
- FutureTask使用完整演示样例
MainActivity例如以下: package cc.cv; import java.util.concurrent.FutureTask; import android.os.Bundle; i ...
- 在Ubuntu下构建Bullet以及执行Bullet的样例程序
在Ubuntu下构建Bullet以及执行Bullet的样例程序 1.找到Bullet的下载页,地址是:https://code.google.com/p/bullet/downloads/list 2 ...
- SNF快速开发平台MVC-各种级联绑定方式,演示样例程序(包含表单和表格控件)
做了这么多项目,经常会使用到级联.联动的情况. 如:省.市.县.区.一级分类.二级分类.三级分类.仓库.货位. 方式:有表单需要做级联的,还是表格行上需要做级联操作的. 实现:实现方法也有很多种方式. ...
- Tuxedo安装、配置、以及演示样例程序 (学习网址)
Tuxedo安装.配置.以及演示样例程序 (学习网址): 1.http://liu9403.iteye.com/blog/1415684 2.http://www.cnblogs.com/fnng/a ...
- Java读取Excel文件(包括xls和xlsx)的样例程序
样例程序如下所示,其中: parseXls()函数依赖于jxl,只能读取xls格式文件: parseExcel()函数依赖于apache poi,能够读取xls和xlsx两种格式的文件. jxl的依赖 ...
- 吴裕雄 python 神经网络——TensorFlow TFRecord样例程序
import numpy as np import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_dat ...
随机推荐
- LED Decorative Light Supplier - LED Neon Application: 5 Advantages
In the past 100 years, lighting has gone a long way. LED decorative lighting is now designed to meet ...
- C++ 深拷贝实例-改变原生数组
深拷贝 main.cpp #include <stdio.h> #include "IntArray.h" int main() { IntArray a(); ; i ...
- TD - setAttribute()
添加指定的属性,并为其赋指定的值 this.sltLevelType.setAttribute("height", "100px");
- sql查询 —— 连接查询
-- 执行sql文件 test.sql -- 打开终端 -- cd sql文件所在路径 -- 进入mysql -- use 数据库 -- 执行 source test.sql; -- 自关联 -- 一 ...
- 解决windows10 OBS Studioobsstudio显示器捕获黑屏
前提设置显卡,下载OBS studio 64bit别下载32bit了 如果电脑desktop右键无法显示NAVIDIA 控制面板则需要win+R 输入 msconfig选取服务,勾选所有NAIVI ...
- HDU 2586 ( LCA/tarjan算法模板)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=2586 题意:n个村庄构成一棵无根树,q次询问,求任意两个村庄之间的最短距离 思路:求出两个村庄的LCA,d ...
- 刷题75. Sort Colors
一.题目说明 题目75. Sort Colors,给定n个整数的列表(0代表red,1代表white,2代表blue),排序实现相同颜色在一起.难度是Medium. 二.我的解答 这个是一个排序,还是 ...
- [学习笔记]用Python简易向喜欢的人表白
前几天是情人节,就用Python图像库PIL来搞点事情. 先看图: 其实这样看不出什么来,然后需要放大: 放大以后就能看到你相对女神说的话. 但是对于学计算机的我来说,更想琢磨是怎样的流程完成的这个图 ...
- MySQL起别名
好处: 便于理解 连接查询的时候,如果要查询的字段有重名的情况,使用别名可以区分开来 注意: 如果别名中有特殊符号 # 空格 ... ,需要用 "双引号" 把别名引起来单引号也行, ...
- EditPlus等编辑器选中列(块)的方法
EditPlus 1)菜单:编辑 -> 选择 -> 列选择2)先按下 Alt + C ,释放,然后移动鼠标或键盘上下左右键进行选择注意:在自动换行的模式下是不行的,改为不自动换行就行了. ...