TensorFlow学习笔记
来源:互联网 发布:儿童编程 ipad 编辑:程序博客网 时间:2024/06/06 05:26
1、拟合直线
# Import the libraryimport tensorflow as tfimport numpy as np# Prepare train datatrain_X = np.linspace(-1, 1, 100)#temp1 = *train_X,#temp2 = *train_X.shape,#*argc 解包,把数组打开#temp3 = train_X.shape,train_Y = 2 * train_X + np.random.randn(*train_X.shape) * 0.33 + 10# Define the ModelX = tf.placeholder("float")Y = tf.placeholder("float")w = tf.Variable(0.0, name="weght")b = tf.Variable(0.0, name="bias")loss = tf.square(Y - tf.multiply(X, w) - b)#loss = tf.square(Y - tf.mul(X, w) - b)train_op = tf.train.GradientDescentOptimizer(0.01).minimize(loss)# Create session to runwith tf.Session() as sess: sess.run(tf.initialize_all_variables()) epoch = 1 for i in range(10): for (x, y) in zip(train_X, train_Y): _, w_value, b_value = sess.run([train_op, w, b], feed_dict={X:x, Y:y}) print("Epoch: {}, w: {}, b: {}".format(epoch, w_value, b_value)) epoch += 1
调试这段代码遇到了几个问题
*train_X.shape中 * 的意思表示将一个数组解压,比如a = [1, 2, 3],那*a则是 1, 2, 3,把数组打开了,这么用是因为randn函数的参数需求
tf.mul运行报错,需要改为tf.multiply
阅读全文
0 0
- TensorFlow学习笔记-1
- TensorFlow学习笔记
- TensorFlow 深度学习笔记
- TensorFlow学习笔记1
- tensorflow-Alexnet学习笔记
- TensorFlow学习笔记
- Tensorflow学习笔记
- Tensorflow学习笔记(1)
- Tensorflow学习笔记(2)
- tensorflow学习笔记
- Tensorflow学习笔记
- tensorflow基础学习笔记
- TensorFlow--学习笔记
- tensorflow学习笔记
- TensorFlow学习笔记----TensorBoard_1
- TensorFlow学习笔记----TensorBoard_2
- Tensorflow学习笔记
- TensorFlow学习笔记
- C语言(七)--函数
- Linux下安装antiword
- C语言(八)--变量的存储类型
- [LeetCode] 453.Minimum Moves to Equal Array Elements
- 多模块小项目~~简*学生管理系统(重点思路咯)小白撸代码第30天
- TensorFlow学习笔记
- Scratch 游戏项目学习法 —— 接苹果(完)改良你的游戏
- PAT 甲级 1118. Birds in Forest (25)
- 第一次玩CsdnBOKE
- 198. House Robber
- 如何快速生成十九大会议内容摘要
- 多项式相加减【数据结构实验报告】
- webview高度自适应图文详情
- 197. Rising Temperature