![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
tensorflow
大雄没有叮当猫
好好学习,天天向上
展开
-
使用tf.keras从零开始实现Softmax回归
公众号:数据挖掘与机器学习笔记3.6 使用tf.keras从零开始实现Softmax回归 这一节我们来动手实现softmax回归。首先导入本节实现所需的包或者模块%matplotlib inlineimport tensorflow as tfimport matplotlib.pyplot as pltfrom IPython import displayfrom tensorflow import kerasimport tensorflow.data as tfdatatf.e原创 2020-08-28 22:12:01 · 705 阅读 · 0 评论 -
tensorflow之损失函数:sparse_softmax_cross_entropy_with_logits 与 softmax_cross_entropy_with_logits的区别
原函数: tf.nn.sparse_softmax_cross_entropy_with_logits( _sentinel=None, labels=None, logits=None, name=None)tf.nn.softmax_cross_entropy_with_logits( _sentinel=None, labels=N...原创 2018-09-19 19:33:42 · 718 阅读 · 0 评论 -
tensorflow损失函数之:softmax_cross_entropy_with_logits和softmax_cross_entropy_with_logits_v2的区别
tf.nn.softmax_cross_entropy_with_logits( _sentinel=None, labels=None, logits=None, dim=-1, name=None)tf.nn.softmax_cross_entropy_with_logits_v2( _sentinel=None, label...原创 2018-09-19 20:06:15 · 2205 阅读 · 0 评论 -
tf.nn.bidirectional_dynamic_rnn和MultiRNNCell构建双向多层RNN(LSTM)
import tensorflow as tfimport numpy as npX = np.random.randn(10, 5, 5) # 输入数据,批次、序列长度、样本维度# 第二个样本的维度为3X[1, 2:] = 0stacked_rnn = []stacked_bw_rnn = []for i in range(3): stacked_rnn....原创 2018-09-19 20:39:49 · 2341 阅读 · 1 评论 -
tf.contrib.rnn.static_bidirectional_rnn和MultiRNNCell构建多层静态双向LSTM
import tensorflow as tfimport numpy as np# 设置训练参数learning_rate = 0.01max_examples = 40batch_size = 128display_step = 10 # 每间隔10次训练就展示一次训练情况n_input = 100#词向量维度n_steps = 300#时间步长fw_n_hidden...原创 2018-09-19 20:44:09 · 1895 阅读 · 2 评论 -
tf.nn.dynamic_rnn和MultiRNNCell构建多层动态LSTM
import tensorflow as tf;import numpy as np;X = tf.random_normal(shape=[3, 5, 6], dtype=tf.float32)X = tf.reshape(X, [-1, 5, 6])stacked_rnn=[]for i in range(3): stacked_rnn.append(tf.contrib...原创 2018-09-19 20:45:11 · 4218 阅读 · 0 评论 -
tensorflow之tf.nn.static_bidirectional_rnn详解
tf.nn.static_bidirectional_rnnAliases:tf.contrib.rnn.static_bidirectional_rnn tf.nn.static_bidirectional_rnntf.nn.static_bidirectional_rnn( cell_fw, cell_bw, inputs, initial_sta...原创 2018-09-20 21:33:51 · 4508 阅读 · 0 评论 -
tensorflow学习之BasicRNNCell详解
1.循环神经网络循环神经网络很像前馈神经网络,但是不同的是神经元有连接回指。如上左图,一个循环神经元可以把自己的输出作为自身的输入,但是这个输入是上一个时间点的输出,如果将上面左图展开就变成右边的图:一个神经元在时间轴上的运行。图右边的下标代表时间,循环神经元在时间 t 同时接受输入 x(t)和自己在上一时间 t−1的输出结果 y(t−1) 2.源码讲解BasicRNN...原创 2018-09-21 16:17:20 · 4126 阅读 · 0 评论 -
BasicRNNCell 和 BasicLSTMCell 的 output
在BasicRNNCell 和 BasicLSTMCell 的类中调用了call方法会得到output。由上图可知h对应了BasicRNNCell的state_size。 那么y是不是对应了BasicRNNCell的output_size呢? 答案是否定的!通过“ return output, output”,可以看出在 BasicRNNCell 中, output真实和隐状态的值...转载 2018-09-21 16:23:40 · 872 阅读 · 0 评论 -
tensorflow学习之static_rnn使用详解
tf.nn.static_rnnAliases:tf.contrib.rnn.static_rnn tf.nn.static_rnn使用指定的RNN神经元创建循环神经网络tf.nn.static_rnn( cell, inputs, initial_state=None, dtype=None, sequence_length=N...原创 2018-09-21 17:01:36 · 8117 阅读 · 0 评论 -
tensorflow学习之static_bidirectional_rnn使用详解
tf.nn.static_bidirectional_rnnAliases:tf.contrib.rnn.static_bidirectional_rnn tf.nn.static_bidirectional_rnn创建双向循环神经网络。与单向循环神经网络类似,只不过双向循环神经网络同时接受前向和反向的RNN神经元,最终对前向和反向的输出进行深度级联,输出的格式如: [time][...原创 2018-09-21 21:18:01 · 5178 阅读 · 1 评论 -
tensorflow学习之BasicLSTMCell详解
tf.contrib.rnn.BasicLSTMCell继承自:LayerRNNCellAliases:Class tf.contrib.rnn.BasicLSTMCell Class tf.nn.rnn_cell.BasicLSTMCell基础的LSTM循环网络单元,基于http://arxiv.org/abs/1409.2329.实现。将forget_bias(默认值:1)添加...原创 2018-09-21 23:13:06 · 21525 阅读 · 1 评论 -
tensorflow学习之LSTMCell详解
Class tf.contrib.rnn.LSTMCell继承自:LayerRNNCellAliases:Class tf.contrib.rnn.LSTMCell Class tf.nn.rnn_cell.LSTMCell长短时记忆单元循环网络单元。默认的non-peephole是基于http://www.bioinf.jku.at/publications/older/2604...原创 2018-09-22 11:27:55 · 23112 阅读 · 0 评论 -
tensorflow学习之dynamic_rnn使用详解
tf.nn.dynamic_rnn使用指定的RNNCell单元创建一个循环神经网络,对输入执行完全动态展开。tf.nn.dynamic_rnn( cell, inputs, sequence_length=None, initial_state=None, dtype=None, parallel_iterations=None, ...原创 2018-09-22 17:36:54 · 5520 阅读 · 1 评论 -
tensorflow学习之bidirectional_dynamic_rnn使用详解
tf.nn.bidirectional_dynamic_rnntf.nn.bidirectional_dynamic_rnn( cell_fw, cell_bw, inputs, sequence_length=None, initial_state_fw=None, initial_state_bw=None, dtype=None...原创 2018-09-22 19:48:04 · 5946 阅读 · 0 评论 -
tensorflow学习之LSTMStateTuple详解
Class LSTMStateTupleAliases:Class tf.contrib.rnn.LSTMStateTuple Class tf.nn.rnn_cell.LSTMStateTuple用于存储LSTM单元的state_size,zero_state和output state的元组。按顺序存储两个元素(c,h),其中c是隐藏状态,h是输出。只有在state_is_tuple...原创 2018-09-22 20:07:22 · 8323 阅读 · 1 评论 -
tensorflow之神经网络层:Flatten,flatten
1.tf.layers.FlattenClass Flatten:在保留第0轴的情况下对输入的张量进行Flatten(扁平化)代码示例: x=tf.placeholder(shape=(None,4,4),dtype='float32') y=tf.layers.Flatten()(x) print(y) 输出:Tensor("flatten/Re...原创 2018-09-19 17:53:22 · 38140 阅读 · 1 评论 -
tensorflow之神经网络层:Dense,dense,Dropout,dropout
1.tf.layers.DenseClass Dense:全连接层该层实现了outputs=activation(inputs*kernel+bias),其中激活函数是作为参数提供的,kernel是该层创建的权重矩阵,而bias是该层创建的偏置向量(仅当use_bias为True)。参数:units:Integer或者Long,输出空间的维度 activation:激活函数,如果...原创 2018-09-19 17:41:56 · 19030 阅读 · 0 评论 -
tensorflow之算术运算符:tf.add,tf.subtract,tf.multiply,tf.scalar_mul,tf.div
1.tf.addtf.add或tf.math.add:加法操作 tf.add( x, y, name=None ) 参数说明: x:一个张量。必须是下列类型之一:bfloat16, half, float32, float64, uint8, int8, int16, int32, int64, complex6...原创 2018-09-16 10:46:36 · 15667 阅读 · 1 评论 -
TensorFlow API之tf.estimator.Estimator
tfestimatorEstimator 属性 方法 tf.estimator.EstimatorEstimator class训练和测试TF模型。Estimator对象封装好通过model_fn指定的模型,给定输入和其它超参数,返回ops执行training, evaluation or prediction. 所有的输出(包含checkpoints, event files...转载 2018-09-16 14:38:22 · 696 阅读 · 0 评论 -
使用tf.estimator.Estimator训练神经网络
参考: https://github.com/aymericdamien/TensorFlow-Examples/ from __future__ import print_function from tensorflow.examples.tutorials.mnist import input_data mnist=input_data.read_data...转载 2018-09-16 14:49:15 · 1299 阅读 · 0 评论 -
tensorflow 优化器optimizer
1. 优化器的种类 Optimizer GradientDescentOptimizer AdagradOptimizer AdagradDAOptimizer MomentumOptimizer AdamOptimizer FtrlOptimizer RMSPropOptimizer 2. GradientDescentOptimizerwith tf.nam...转载 2018-09-16 20:08:19 · 630 阅读 · 0 评论 -
tensorflow之算术运算符:truediv、floordiv、realdiv、truncatediv
微信公众号:数据挖掘与分析学习1. tf.truediv按元素除法x / y(使用Python 3除法运算符语义)。注意:首选使用Tensor运算符或遵循Python除法运算符语义的tf.divide。此函数强制使用Python 3除法运算符语义,其中所有整数参数首先转换为浮点类型。 此op由Python 3中的正常x / y除法和带有__future__ import divisio...原创 2018-09-17 20:49:40 · 15985 阅读 · 0 评论 -
tensorflow神经网络训练流程
微信公众号:数据挖掘与分析学习1.导入所需的库 from __future__ import print_function from tensorflow.examples.tutorials.mnist import input_data import tensorflow as tf 2.数据准备 mnist=input_data.read_...原创 2018-09-17 20:51:56 · 1112 阅读 · 0 评论 -
tensorflow学习之GRUCell详解
tf.contrib.rnn.GRUCellAliases:Class tf.contrib.rnn.GRUCell Class tf.nn.rnn_cell.GRUCell门控循环单元cell__init__( num_units, activation=None, reuse=None, kernel_initializer=No...原创 2018-09-23 15:58:41 · 16675 阅读 · 2 评论 -
使用tensorflow对原始文本数据进行预处理
微信公众号:数据挖掘与分析学习现在关于tensorflow的教程还是太少了,有也都是歪果仁写的。比如以下几个: TensorFlow-Examples tensorflow_tutorials TensorFlow-Tutorials Tensorflow-101 个人感觉这些教程对于新手来说讲解的并不细致,几乎都是作者写好了代码放到ipython notebook上,大家下载到本地run一r...转载 2018-09-13 21:33:34 · 3556 阅读 · 0 评论 -
TensorFlow导入数据详解
微信公众号:数据挖掘与分析学习原文地址:https://www.tensorflow.org/programmers_guide/datasets 基础机制 Dataset构建 创建迭代器 从迭代器中获取数据 读入输入数据 使用Numpy数组 使用TFRecord数据 使用文本数据 使用Dataset.map() 预处理数据 解析...转载 2018-09-13 21:55:06 · 658 阅读 · 0 评论 -
tensorflow之神经网络层:AveragePooling1D、average_pooling1d、Conv1D和conv1d
1.tf.layers.AveragePooling1DClass AveragePooling1D:对一维的输入作平均池化参数:pool_size:一个整数或者一个单个整数的tuple/list,表示池化窗口的大小 Strides:一个整数或者一个单个整数的tuple/list,指定池化操作的移动步幅 padding:一个字符串。padding的方法:”valid”或者’same...原创 2018-09-19 12:53:18 · 7752 阅读 · 0 评论 -
tensorflow之神经网络层:AveragePooling2D、average_pooling2d、Conv2D和conv2d
微信公众号:数据挖掘与分析学习1. tf.layers.Conv2DClass Conv2D:2D卷积层,如图像上的空间卷积该层创建卷积核,该卷积核与层的输入卷积(实际上是交叉相关)以产生输出张量。 如果use_bias为True(并且提供了bias_initializer),则会创建偏置向量并将其添加到输出。 最后,如果激活函数不是None,它也会应用于输出。参数:filte...原创 2018-09-19 14:28:28 · 15164 阅读 · 0 评论 -
tensorflow学习之MultiRNNCell详解
tf.contrib.rnn.MultiRNNCellAliases:Class tf.contrib.rnn.MultiRNNCell Class tf.nn.rnn_cell.MultiRNNCell由多个简单的cells组成的RNN cell。用于构建多层循环神经网络。 __init__( cells, state_is_tuple=Tr...原创 2018-09-24 15:46:24 · 16883 阅读 · 3 评论 -
tensorflow学习之stack_bidirectional_rnn使用详解
tf.contrib.rnn.stack_bidirectional_rnntf.contrib.rnn.stack_bidirectional_rnn( cells_fw, cells_bw, inputs, initial_states_fw=None, initial_states_bw=None, dtype=None, seq...原创 2018-09-24 17:28:16 · 4582 阅读 · 2 评论 -
tensorflow之神经网络层:MaxPooling1D、max_pooling1d、MaxPooling2D、max_pooling2d
微信公众号:数据挖掘与分析学习1.tf.layers.MaxPooling1DClass MaxPooling1D:1D输入的最大池化层参数:pool_size:一个整数或者一个单个整数的tuple/list,表示池化窗口的大小 strides:一个整数或者一个单个整数的tuple/list,指定池化操作的移动步幅 padding:一个字符串。padding的方法:”valid...原创 2018-09-19 15:28:24 · 41751 阅读 · 6 评论 -
tensorflow学习之softmax使用详解
1. 什么是SoftmaxSoftmax 在机器学习和深度学习中有着非常广泛的应用。尤其在处理多分类(C > 2)问题,分类器最后的输出单元需要Softmax 函数进行数值处理。关于Softmax 函数的定义如下所示:其中,Vi 是分类器类别的输出。i 表示类别索引,总的类别个数为 C。Si 表示的是当前元素的指数与所有元素指数和的比值。Softmax 将多分类的输出数值转化为相...原创 2018-09-25 10:39:48 · 26325 阅读 · 0 评论 -
tensorflow实现logistic回归进行手写字识别
1.数据准备 import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data #加载mnist数据 mnist=input_data.read_data_sets('/data/machine_learning/mnist/',one_hot=True) #使用o...原创 2018-09-16 10:10:40 · 338 阅读 · 0 评论