TensorFlow 1.0
TensorFlow从环境搭建到精通
手撕机
娱乐博主。
展开
-
[TensorFlow笔记] GPU环境搭建
系统:Ubuntu 16.04安装首先要下载NVIDIA公司提供的两个文件:CUDA(下载地址)和cuDNN(下载地址),下载需要注册账号,有点坑爹。CUDA建议下载runfile(local)文件类型,cuDNN要同时下载Runtime和Development两个deb包。注意一定要下载匹配TensorFlow的版本,如下: TensorFlow版本 CUDA...原创 2018-04-06 17:46:19 · 558 阅读 · 0 评论 -
TensorFlow教程——常用函数解析
以下函数均返回一个Tensor对象,类似矩阵数据,包括单个值,向量,多维矩阵。基本的两个创建常量Tensor的函数tf.constant(value, dtype=None, shape=None, name="Const", verify_shape=False)根据value和shape来创建一个常量Tensor。value可以是一个数,也可以是一个list。 如果是一个数,那么这个常量中所有值原创 2017-11-16 19:56:24 · 958 阅读 · 0 评论 -
TensorFlow教程——Bi-LSTM+CRF进行序列标注(代码浅析)
Bi-LSTM使用TensorFlow构建Bi-LSTM时经常是下面的代码:cell_fw = tf.contrib.rnn.LSTMCell(num_units=100)cell_bw = tf.contrib.rnn.LSTMCell(num_units=100)(outputs, output_states) = tf.nn.bidirectional_dynamic_rn...原创 2018-01-12 16:47:19 · 31167 阅读 · 14 评论 -
TensorFlow教程——nest.flatten()函数解析
函数作用:将嵌套结构压平,返回Python的list。例子一,嵌套列表:from tensorflow.python.util import nestinput = [['a', 'b', 'c'], ['d', 'e', 'f'], ['1', '2', '3']]result = nest.flatten(input)Out:<c...原创 2018-02-04 21:40:39 · 7561 阅读 · 0 评论 -
[TensorFlow笔记] TensorArray解析
TensorArray可以看做是具有动态size功能的Tensor数组。通常都是跟while_loop或map_fn结合使用。例子1:将[2.4, 3.5]写进TensorArray三次import tensorflow as tfdef condition(time, output_ta_l): return tf.less(time, 3)def body(ti...原创 2018-02-04 23:54:10 · 14500 阅读 · 4 评论 -
[TensorFlow笔记] RNNCell源码浅析
RNNCell是一个抽象类,BasicRNNCell,BasicLSTMCell,GRUCell都是继承于它的。class RNNCell(base_layer.Layer): def __call__(self, inputs, state, scope=None): if scope is not None: with vs.vari...原创 2018-02-05 21:53:40 · 624 阅读 · 0 评论 -
[TensorFlow笔记] BasicRNNCell源码浅析
BasicRNNCell是抽象类RNNCell的一个最简单的实现。class BasicRNNCell(RNNCell): def __init__(self, num_units, activation=None, reuse=None): super(BasicRNNCell, self).__init__(_reuse=reuse) self...原创 2018-02-06 19:56:53 · 2067 阅读 · 1 评论 -
TensorFlow教程——BasicLSTMCell源码浅析
源码分析class BasicLSTMCell(RNNCell): def __init__(self, num_units, forget_bias=1.0, state_is_tuple=True, activation=None, reuse=None): super(BasicLSTMCell, self).__init__(_reuse=reuse)...原创 2018-02-06 20:03:08 · 2996 阅读 · 3 评论 -
[TensorFlow笔记] 获取Tensor的维度(tf.shape(x)、x.shape和x.get_shape()的区别)
import tensorflow as tfinput = tf.constant([[0,1,2],[3,4,5]])print(type(input.shape))print(type(input.get_shape()))print(type(tf.shape(input)))Out:<class 'tensorflow.python.framework.ten...原创 2018-02-07 16:54:29 · 55926 阅读 · 5 评论 -
TensorFlow教程——梯度爆炸与梯度裁剪
在较深的网络,如多层CNN或者非常长的RNN,由于求导的链式法则,有可能会出现梯度消失(Gradient Vanishing)或梯度爆炸(Gradient Exploding )的问题。(这部分知识后面补充)原理问题:为什么梯度爆炸会造成训练时不稳定而且不收敛? 梯度爆炸,其实就是偏导数很大的意思。回想我们使用梯度下降方法更新参数:w1w2=w1−α∂J(w)∂w1=w2−α...原创 2018-03-13 21:38:09 · 14243 阅读 · 2 评论 -
[TensorFlow笔记] TensorBoard可视化
多元线性回归(数据是经典的Boston房价预测):# coding=utf-8import numpy as npimport tensorflow as tffrom sklearn.datasets import load_boston# NumPy dataX, y = load_boston(return_X_y=True)X = X.astype(np.float3...原创 2018-03-27 19:37:10 · 552 阅读 · 1 评论