吴裕雄 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 ...
随机推荐
- Codeforces Round #623 (Div. 1, based on VK Cup 2019-2020 - Elimination Round, Engine)A(模拟,并查集)
#define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; pair<]; bool cmp( ...
- 后台执行linux命令
/** * * 方法说明:移植执行linux命令 * * @param cmdStr 需要执行的linux命令 * @return 执行命令后的输出(如果是启动一个进程,则可能一直无法返回) * @t ...
- UES
Spring-core-4.3.16 ObjectUtils.java public static boolean isEmpty(Object obj) { if (obj == null) { r ...
- IntelliJ IDEA 2017.3尚硅谷-----配置 Maven
- 查看war包编译时使用的jdk版本
第一种方式:找到war包的其中一个class文件,用UE打开,看第一行 34(对应十进制的50):JDK1.8 33(对应十进制的50):JDK1.7 32(对应十进制的50):JDK1.6 31(对 ...
- MySQL学习(八)删除表数据
表空洞的产生 删除某个行数据 或删除某个页 如下图所示,这个删除过程只是标记了某行的位置为删除,假如此时在300与600之间插入了一行数据,那么 同理,当删除某个页时,该页就会被复用.所以当删 ...
- AC3 IMDCT
AC3 encoder 在进行MDCT时,使用两种长度的block. 512 samples的block用于输入信号频谱是stationary,或者在时间上变化缓慢.在fs 为48k时,使用512 s ...
- calloc函数的使用和对内存free的认识
#include<stdlib.h> void *calloc(size_t n, size_t size): free(); 目前的理解: n是多少个这样的size,这样的使用类似有f ...
- 画图软件gliffy
网上的资源真是海量丫: https://segmentfault.com/q/1010000000310976 gliffy软件在线网址:https://chrome.google.com/webst ...
- es6模块化设计
//导出 //方式一 export const name = 'hello' export let addr = 'chengdu' export var list = [1,2,3] //方式二 c ...