莫烦tensorflow教程笔记(五)
来源:互联网 发布:mac c4d软件下载 编辑:程序博客网 时间:2024/06/07 06:27
import tensorflow as tfimport numpy as npimport matplotlib.pyplot as pltdef 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 outputx_data = np.linspace(-1,1,300)[:,np.newaxis]#.astype(np.float32)noise = np.random.normal(0,0.05,x_data.shape)print(x_data.dtype)y_data = np.square(x_data) - 0.5 + noisexs = tf.placeholder(tf.float32,[None,1])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]))train_step = tf.train.GradientDescentOptimizer(0.1).minimize(loss)init = tf.global_variables_initializer()session = tf.Session()session.run(init)fig = plt.figure()ax = fig.add_subplot(1,1,1)ax.scatter(x_data,y_data)plt.ion() ###开启interactive 模式 能连续作图plt.show()for step in range(1000): session.run(train_step,feed_dict={xs:x_data,ys:y_data}) if step % 50 == 0: print(step,session.run(loss,feed_dict={xs:x_data,ys:y_data})) try: ax.lines.remove(lines[0]) except Exception: pass prediction_value = session.run(prediction,feed_dict={xs:x_data,ys:y_data}) lines = ax.plot(x_data,prediction_value,'r-',lw=5) plt.pause(0.1)plt.ioff() ##如果不加入这两句 在pycharm中迭代完成后图像会自动关闭plt.show()
阅读全文
0 0
- 莫烦tensorflow教程笔记(五)
- 莫烦tensorflow教程笔记(一)
- 莫烦tensorflow教程笔记(二)
- 莫烦tensorflow教程笔记(三)
- 莫烦tensorflow教程笔记(四)
- 莫烦tensorflow教程笔记(六)
- TensorFlow学习笔记(五)
- TensorFlow学习笔记(五)
- TensorFlow官方教程学习笔记(五)——前馈神经网络
- TensorFlow学习笔记(五): Tensorflow on Android
- tensorflow学习笔记(五):cnn
- 深度学习笔记——深度学习框架TensorFlow(五)[TensorFlow大规模线性模型教程]
- TensorFlow 教程 - 新手入门笔记
- tensorflow教程 cifar10 笔记
- TensorFlow简要教程系列(五)TensorFlow实现卷积神经网络(CNN)
- TensorFlow官方教程学习笔记之1-TensorFlow入门教程(Getting Started With TensorFlow)
- tensorflow学习笔记(五):变量保存与导入
- tensorflow学习笔记五:mnist实例--卷积神经网络(CNN)
- MySQL innodb中各种SQL语句加锁分析
- 机器学习算法之聚类算法(K-means&DBSCAN)
- Java学习 java--变量
- [erlang] 为什么叫random的随机数是伪随机数
- Linux环境下,db2 restore操作对文件系统的预分配
- 莫烦tensorflow教程笔记(五)
- HTML图片变(鼠标移上去变另一张)
- keil中flash download添加列表中没有的芯片flash型号的方法
- 多线程高并发
- 导弹拦截之升级版(1164)
- 机器学习笔记(11)-PCA/SVD
- python装饰器的十种用法
- 二叉树
- Android studio中指定查找路径