tf_神经网络的简单搭建
来源:互联网 发布:分期贷款软件 编辑:程序博客网 时间:2024/04/30 23:18
import tensorflow as tf import numpy as np def add_layer(inputs, in_size, out_size, activation_function=None): Weights = tf.Variable(tf.random_normal([in_size,out_size])) biases = tf.Variable(tf.zeros([1,out_size])) Wx_plus_b = tf.matmul(inputs,Weights) + biases
# 矩阵的广播机制
if activation_function is None: outputs = Wx_plus_b else: outputs = activation_function(Wx_plus_b) return outputs x_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 xs = tf.placeholder(tf.float32,[None,1]) ys = tf.placeholder(tf.float32,[None,1]) l1 = add_layer(xs, 1, 10, activation_function=tf.nn.relu) prediction = add_layer(l1, 10, 1, activation_function=None) # loss = tf.reduce_mean(tf.reduce_sum(tf.square(ys - prediction),reduction_indices=[1])) same as following loss = tf.reduce_mean(tf.square(ys - prediction)) train_step = tf.train.GradientDescentOptimizer(0.5).minimize(loss) init = tf.global_variables_initializer() sess = tf.Session() sess.run(init) for i in range(1000): sess.run(train_step,feed_dict={xs:x_data,ys:y_data}) if i%20 == 0: print(i,sess.run(loss,feed_dict={xs:x_data,ys:y_data}))
关于tf.reduce_mean,tf.reduce_sum等函数中reduction_indices的用法在这里
一目了然,当没有设置该参数时,该参数的默认值是None,将tensor降到0维,也就是一个数
阅读全文
0 0
- tf_神经网络的简单搭建
- tf_矩阵的广播机制
- 基于tensorflow的简单BP神经网络的结构搭建
- 基于tensorflow的简单BP神经网络的结构搭建
- 基于tensorflow的简单BP神经网络的结构搭建
- Tensorflow 搭建简单神经网络 | Python
- 利用tensorflow keras搭建一个简单的卷积神经网络
- 深层神经网络的搭建
- 神经网络的简单理解
- 神经网络的简单理解
- Tensorflow简单的神经网络
- 实现简单的神经网络
- 简单的卷积神经网络
- tensorflow之安装及简单神经网络搭建
- 神经网络: 计算简单的加法
- 神经网络BP的简单实现
- 简单的理解BP神经网络
- 一个简单的神经网络例子
- 如何去掉thymeleaf的严格的模板校验
- 加密、解密详解及CA的实现
- 新消费时代,哪些企业最具2017消费升级商业力量?
- 三.PullToRefreshScrollView 整体下拉刷新下拉加载 主方法里面
- Android Studio创建的Android项目一般需要忽略
- tf_神经网络的简单搭建
- static关键字,静态变量,静态方法,静态代码块,静态导入
- 大数据与AI的碰撞:这两家科技企业要让“1+1>2”
- CSDN第一篇博客
- VUE 饿了么组件 1.4 table 属性之一
- R packages
- C++ 栈基本操作
- 吐司
- 事务