Tensorflow学习笔记
  • Introduction
  • Tensorflow基础框架
    • 处理结构
    • 例子2
    • Session 会话控制
    • Variable 变量
    • Placeholder 传入值
    • 激励函数
  • 建造第一个神经网络
    • 添加层 def add_layer()
    • 建造神经网络
    • 结果可视化
    • Optimizer
    • Daterset
  • 可视化好助手Tensorboard
    • Tensorboard可视化好帮手1
    • Tensorboard 可视化好帮手 2
  • 高阶内容
    • Classification 分类学习
    • Dropout 解决 overfitting
    • CNN 卷积神经网络 1
    • CNN 卷积神经网络 2
    • Saver 保存读取
    • RNN LSTM 循环神经网络 (分类例子)
    • RNN LSTM (回归例子)
    • RNN LSTM (回归例子可视化)
    • 自编码Autoencoder(非监督学习)
    • scope 命名方法
    • Batch Normalization 批标准化
    • 用 Tensorflow 可视化梯度下降
Powered by GitBook
On this page
  • 创建数据
  • 搭建模型
  • 计算误差
  • 传播误差
  • 训练

Was this helpful?

  1. Tensorflow基础框架

例子2

创建数据

import tensorflow as tf
import numpy as np

# create data
x_data = np.random.rand(100).astype(np.float32)
y_data = x_data*0.1 + 0.3

搭建模型

用 tf.Variable 来创建描述 y 的参数

神经网络也就是学着把 Weights 变成 0.1, biases 变成 0.3

Weights = tf.Variable(tf.random_uniform([1], -1.0, 1.0))
biases = tf.Variable(tf.zeros([1]))

y = Weights*x_data + biases

计算误差

loss = tf.reduce_mean(tf.square(y-y_data))

传播误差

误差传递方法是梯度下降法: Gradient Descent

用 optimizer 来进行参数的更新.

optimizer = tf.train.GradientDescentOptimizer(0.5)
train = optimizer.minimize(loss)

训练

使用这个结构之前, 必须先初始化所有之前定义的Variable

init = tf.global_variables_initializer()

用 Session 来执行 init 初始化步骤

并且, 用 Session 来 run 每一次 training 的数据. 逐步提升神经网络的预测准确性.

sess = tf.Session()
sess.run(init)          # Very important

for step in range(201):
    sess.run(train)
    if step % 20 == 0:
        print(step, sess.run(Weights), sess.run(biases))
Previous处理结构NextSession 会话控制

Last updated 6 years ago

Was this helpful?