Tensorflow 搭建神经网络(单层)
来源:互联网 发布:查看淘宝买家退货率 编辑:程序博客网 时间:2024/05/22 03:33
#coding=utf-8import tensorflow as tfimport numpy as np#add layerdef add_layer(inputs,in_size,out_size,activation_function=None):# add one more layer and return the output of this layerw = tf.Variable(tf.random_normal([in_size,out_size]))b = tf.Variable(tf.zeros([1,out_size])+0.1)y = tf.matmul(inputs,w)+bif activation_function is None:outputs = yelse:outputs = activation_function(y)return outputs#make train datax_data = np.linspace(-1,1,300)[:,np.newaxis]noise = np.random.normal(0,0.05,x_data.shape)y_data = np.square(x_data) - 0.5 + noise#print (x_data)#print (y_data)#define placeholderxs = tf.placeholder(tf.float32,[None,1])ys = tf.placeholder(tf.float32,[None,1])#add hidden layerl1 = add_layer(xs,1,10,activation_function = tf.nn.relu)#add output layerprediction = add_layer(l1,10,1,activation_function = None)#define loss functionloss = tf.reduce_mean(tf.reduce_sum(tf.square(ys-prediction),reduction_indices = [1]))#定义用什么方法减少lossoptimizer = tf.train.GradientDescentOptimizer(0.1).minimize(loss)with tf.Session() as sess:sess.run(tf.initialize_all_variables())for i in range(1001):sess.run(optimizer,feed_dict = {xs:x_data,ys:y_data})if i%100 == 0:print (sess.run(loss,feed_dict = {xs:x_data,ys:y_data}))#pre = sess.run(prediction,feed_dict = {xs:x_data,ys:y_data})#aa = np.abs(pre - y_data)#print (aa)
阅读全文
1 0
- Tensorflow 搭建神经网络(单层)
- TensorFlow入门(3)-单层神经网络实现方法
- Tensorflow学习:单层神经网络的建立
- 单层神经网络
- 译文 | 与TensorFlow的第一次接触 第四章:单层神经网络
- 莫烦 tensorflow 笔记 (一)搭建神经网络
- tensorflow之搭建神经网络
- 人工神经网络(二)单层感知器
- 人工神经网络(二)单层感知器
- 用TensorFlow自己动手搭建神经网络
- Tensorflow 搭建简单神经网络 | Python
- tensorflow-搭建两层神经网络
- TensorFlow搭建CNN卷积神经网络
- Python搭建tensorflow三层神经网络
- 单层感知器神经网络
- 第一次实现单层神经网络
- TensorFlow学习笔记(九)tf搭建神经网络基本流程
- TensorFlow学习笔记(十)tf搭建神经网络可视化结果
- ride创建桌面快捷方式
- Android短视频开发
- codevs 2832 6个朋友 并查集 解题报告
- 【头条】为医疗大数据再加码 神州控股参与成立中国健康医疗大数据公司
- 多线程编程ThreadLocal
- Tensorflow 搭建神经网络(单层)
- java的类之间的关系:泛化、依赖、关联、实现、聚合、组合
- java后台书单
- JVM类加载过程
- bzoj2827千山鸟飞绝(Treap)
- 欢迎使用CSDN-markdown编辑器
- 常规容器下SpringBootServletInitializer如何实现web.xml作用解析
- 创建Hibernate项目的步骤
- Android png转xml