All Projects → cookeem → Tensorflow_learning_notes

cookeem / Tensorflow_learning_notes

tensorflow学习笔记,来源于电子书:《Tensorflow实战Google深度学习框架》

Projects that are alternatives of or similar to Tensorflow learning notes

Tensorflow Dataset Tutorial
Notebook for my medium article about how to use Dataset API in TensorFlow
Stars: ✭ 158 (-60.79%)
Mutual labels:  jupyter-notebook, tensorflow-tutorials
Tensorflow 101
TensorFlow Tutorials
Stars: ✭ 2,565 (+536.48%)
Mutual labels:  jupyter-notebook, tensorflow-tutorials
Yolov3 Tf2
YoloV3 Implemented in Tensorflow 2.0
Stars: ✭ 2,327 (+477.42%)
Mutual labels:  jupyter-notebook, tensorflow-tutorials
Entailment With Tensorflow
Accompanying notebook for the Entailment with Tensorflow article.
Stars: ✭ 81 (-79.9%)
Mutual labels:  jupyter-notebook, tensorflow-tutorials
Deep reinforcement learning course
Implementations from the free course Deep Reinforcement Learning with Tensorflow and PyTorch
Stars: ✭ 3,232 (+701.99%)
Mutual labels:  jupyter-notebook, tensorflow-tutorials
Learn Machine Learning In Two Months
Những kiến thức cần thiết để học tốt Machine Learning trong vòng 2 tháng. Essential Knowledge for learning Machine Learning in two months.
Stars: ✭ 1,726 (+328.29%)
Mutual labels:  jupyter-notebook, tensorflow-tutorials
Tensorflow Deep Learning
All course materials for the Zero to Mastery Deep Learning with TensorFlow course.
Stars: ✭ 170 (-57.82%)
Mutual labels:  jupyter-notebook, tensorflow-tutorials
Fish detection
Fish detection using Open Images Dataset and Tensorflow Object Detection
Stars: ✭ 67 (-83.37%)
Mutual labels:  jupyter-notebook, tensorflow-tutorials
Dlpython course
Примеры для курса "Программирование глубоких нейронных сетей на Python"
Stars: ✭ 266 (-34%)
Mutual labels:  jupyter-notebook, tensorflow-tutorials
Docs L10n
Translations of TensorFlow documentation
Stars: ✭ 262 (-34.99%)
Mutual labels:  jupyter-notebook, tensorflow-tutorials
Tf Serving K8s Tutorial
A Tutorial for Serving Tensorflow Models using Kubernetes
Stars: ✭ 78 (-80.65%)
Mutual labels:  jupyter-notebook, tensorflow-tutorials
Tensorflow chessbot
Predict chessboard FEN layouts from images using TensorFlow
Stars: ✭ 362 (-10.17%)
Mutual labels:  jupyter-notebook, tensorflow-tutorials
Mit Deep Learning
Tutorials, assignments, and competitions for MIT Deep Learning related courses.
Stars: ✭ 8,912 (+2111.41%)
Mutual labels:  jupyter-notebook, tensorflow-tutorials
Deep Learning With Python
Example projects I completed to understand Deep Learning techniques with Tensorflow. Please note that I do no longer maintain this repository.
Stars: ✭ 134 (-66.75%)
Mutual labels:  jupyter-notebook, tensorflow-tutorials
Tensorflow Brasil
Códigos e materiais sobre TensorFlow em Português
Stars: ✭ 74 (-81.64%)
Mutual labels:  jupyter-notebook, tensorflow-tutorials
Gans From Theory To Production
Material for the tutorial: "Deep Diving into GANs: from theory to production"
Stars: ✭ 182 (-54.84%)
Mutual labels:  jupyter-notebook, tensorflow-tutorials
Tensorflow Tutorials For Time Series
TensorFlow Tutorial for Time Series Prediction
Stars: ✭ 1,067 (+164.76%)
Mutual labels:  jupyter-notebook, tensorflow-tutorials
Duke Tsinghua Mlss 2017
Duke-Tsinghua Machine Learning Summer School 2017
Stars: ✭ 65 (-83.87%)
Mutual labels:  jupyter-notebook, tensorflow-tutorials
Deeppicar
Deep Learning Autonomous Car based on Raspberry Pi, SunFounder PiCar-V Kit, TensorFlow, and Google's EdgeTPU Co-Processor
Stars: ✭ 242 (-39.95%)
Mutual labels:  jupyter-notebook, tensorflow-tutorials
Tf tutorial plus
Tutorials for TensorFlow APIs the official documentation doesn't cover
Stars: ✭ 293 (-27.3%)
Mutual labels:  jupyter-notebook, tensorflow-tutorials

tensorflow学习笔记

Tensorflow实战Google深度学习框架

对样例中python2.x代码以及注释进行补充和修正,修正为python3.x代码。代码使用jupyter/jupyter进行交互演示,运行以下命令演示:

git clone https://github.com/cookeem/TensorFlow_learning_notes
cd TensorFlow_learning_notes
jupyter notebook

目录:

  1. 第3章 TensorFlow入门
  2. 第4章 深层神经网络
  3. 第5章 MNIST数字识别问题
  4. 第6章 图像识别与卷积神经网络
  5. 第7章 图像数据处理
  6. 第8章 循环神经网络
  7. 第9章 TensorBoard可视化
  8. 第10章 TensorFlow计算加速

学习笔记:

1、多层:使用多层权重,例如多层全连接方式

以下定义了三个隐藏层的全连接方式的神经网络 样例代码:

import tensorflow as tf

l1 = tf.matmul(x, w1)
l2 = tf.matmul(l1, w2)
y = tf.matmul(l2,w3)

2、激活层:引入激活函数,让每一层去线性化

激活函数有多种,例如常用的: tf.nn.relu tf.nn.tanh tf.nn.sigmoid tf.nn.elu 样例代码:

import tensorflow as tf

a = tf.nn.relu(tf.matmul(x, w1) + biase1)
y = tf.nn.relu(tf.matmul(a, w2) + biase2)

3、损失函数:

经典损失函数,交叉熵(cross entropy) 用于计算预测结果矩阵Y和实际结果矩阵Y_之间的距离 样例代码:

import tensorflow as tf

cross_entropy = -tf.reduce_mean(y_ * tf.log(tf.clip_by_value(y, 1e-10, 1.0)))
import tensorflow as tf

v = tf.constant([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]])
tf.reduce_mean(tf.clip_by_value(v, 0.0, 10.0))

对于分类问题,通常把交叉熵与softmax回归一起使用

import tensorflow as tf

cross_entropy = tf.nn.softmax_cross_entropy_with_logits(y, y_)

对于回归问题,通常使用mse(均方误差函数)计算损失函数

import tensorflow as tf

mse_loss = tf.reduce_mean(tf.square(y_ - y))

# 与以下函数计算结果完全一致
dataset_size = 1000
mse_loss = tf.reduce_sum(tf.pow(y_ - y, 2)) / dataset_size

自定义条件化的损失函数

import tensorflow as tf

loss_less = 10
loss_more = 1
loss = tf.reduce_sum(tf.where(tf.greater(y, y_), (y - y_) * loss_more, (y_ - y) * loss_less))
train_step = tf.train.AdamOptimizer(0.001).minimize(loss)

4、神经网络优化算法,训练优化器

一般优化器的目标是优化权重W和偏差biases,最小化损失函数的结果 以下优化器会不断优化W和biases

import tensorflow as tf

LEARNING_RATE = 0.001
mse_loss = tf.reduce_mean(tf.square(y_ - y))
train_op = tf.train.AdamOptimizer(LEARNING_RATE).minimize(mse_loss)

5、优化学习率LEARNING_RATE

学习率设置过大可能导致无法收敛,学习率设置过小可能导致收敛过慢

import tensorflow as tf

global_step = tf.Variable(0)
learning_rate = tf.train.exponential_decay(
    learning_rate=0.1, 
    global_step=global_step, 
    decay_steps=100, 
    decay_rate=0.96, 
    staircase=True, 
    name=None
)
train_op = tf.train.AdamOptimizer(learning_rate).minimize(loss, global_step=global_step)

6、过拟合问题(正则化)

避免训练出来的模型过分复杂,即模型记住了所有数据(包括噪声引起的误差) 因此需要引入正则化函数叠加的方式,避免模型出现过拟合

import tensorflow as tf

v_lambda = 0.001
w = tf.Variable(tf.random_normal([2, 1], stddev=1, seed=1))
y = tf.matmul(x, w)
mse_loss = tf.reduce_mean(tf.square(y_ - y) + tf.contrib.layers.l2_regularizer(v_lambda)(w))

7、滑动平均模型

用于控制模型的变化速度,可以控制权重W以及偏差biases 例如:avg_class.average(w) avg_class.average(biases)

import tensorflow as tf

v1 = tf.Variable(0, dtype=tf.float32)
step = tf.Variable(0, trainable=False)
ema = tf.train.ExponentialMovingAverage(decay=0.99, num_updates=step)
# 每一次操作的时候,列表变量[v1]都会被更新
maintain_averages_op = ema.apply([v1]) 

with tf.Session() as sess:
    
    # 初始化
    init_op = tf.global_variables_initializer()
    sess.run(init_op)
    print(sess.run([v1, ema.average(v1)]))
    
    # 更新step和v1的取值
    sess.run(tf.assign(step, 10000))  
    sess.run(tf.assign(v1, 10))
    sess.run(maintain_averages_op)
    print(sess.run([v1, ema.average(v1)]))
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].