莫烦tensorflow教程笔记(四)
来源:互联网 发布:上海哪里有mac专柜 编辑:程序博客网 时间:2024/06/14 08:05
import tensorflow as tfimport numpy as np
def add_layer(inputs,in_size,out_size,activation=None): Weights = tf.Variable(tf.random_normal([in_size,out_size])) biases = tf.Variable(tf.zeros([1,out_size]) + 0.1) Wx_plus_b = tf.matmul(inputs,Weights) + biases if activation is None: output = Wx_plus_b else: output = activation(Wx_plus_b) return output
x_data = np.linspace(-1,1,300)[:,np.newaxis].astype(np.float32) noise = np.random.normal(0,0.05,x_data.shape)y_data = np.square(x_data) - 0.5 + noisexs = tf.placeholder(tf.float32,[None,1]) ##None的意思是xs可以是任意行的数据ys = tf.placeholder(tf.float32,[None],1)L1 = add_layer(xs,in_size=1,out_size=10,activation=tf.nn.relu)prediction = add_layer(L1,in_size=10,out_size=1,activation=None)loss = tf.reduce_mean(tf.reduce_sum(tf.square(ys - prediction),reduction_indices=[1])) #reduction_indices=[1]表示按行求和,在本例中x只有一维,不求和也一样train_step = tf.train.GradientDescentOptimizer(0.1).minimize(loss)init = tf.global_variables_initializer()session = tf.Session()session.run(init)for i in range(1000): session.run(train_step,feed_dict={xs:x_data,ys:y_data}) if i % 50 == 0: print(i,session.run(loss,feed_dict={xs:x_data,ys:y_data}))
阅读全文
0 0
- 莫烦tensorflow教程笔记(四)
- 莫烦tensorflow教程笔记(一)
- 莫烦tensorflow教程笔记(二)
- 莫烦tensorflow教程笔记(三)
- 莫烦tensorflow教程笔记(五)
- 莫烦tensorflow教程笔记(六)
- TensorFlow学习笔记(四)
- TensorFlow简要教程系列(四)TensorFlow实现Softmax回归
- TensorFlow官方教程学习笔记(四)——MNIST数据集的读取
- tensorflow学习笔记(四):激活函数
- tensorflow学习笔记(四):mnist
- tensorflow学习笔记(四):TensorBoard
- (四) tensorflow笔记:常用函数说明
- TensorFlow 教程 - 新手入门笔记
- tensorflow教程 cifar10 笔记
- TensorFlow官方教程学习笔记之1-TensorFlow入门教程(Getting Started With TensorFlow)
- Tensorflow教程--新手入门笔记--安装
- TensorFlow 笔记(四):常用的函数和说明
- ruby环境搭建
- BUI+Springboot,问题总结
- 页面内容的隐藏和显示-hide()方法和show()方法
- CentOS 7.0关闭默认防火墙启用iptables防火墙
- 用户验证
- 莫烦tensorflow教程笔记(四)
- bootstrap
- Linux下基于RPM BUNDLE包安装MySQL
- Android笔试和面试常见题目(五)
- java提供的函数式接口
- 改变a默认样式
- 反射机制
- 670. Maximum Swap
- 前台与PHP与Mysql