一.TensorFlow高层次机器学习API (tf.contrib.learn) 1.tf.contrib.learn.datasets.base.load_csv_with_header 加载csv格式数据 2.tf.contrib.learn.DNNClassifier 建立DNN模型(classifier) 3.classifer.fit 训练模型 4.classifier.evaluate 评价模型 5.classifier.predict 预测新样本 完整代码: from __fut…
TensorFlow高层次机器学习API (tf.contrib.learn) 1.tf.contrib.learn.datasets.base.load_csv_with_header 加载csv格式数据 2.tf.contrib.learn.DNNClassifier 建立DNN模型(classifier) 3.classifer.fit 训练模型 4.classifier.evaluate 评价模型 5.classifier.predict 预测新样本 完整代码: 1 from __fut…
tf.contrib.learn.preprocessing.VocabularyProcessor (max_document_length, min_frequency=0, vocabulary=None, tokenizer_fn=None) 参数: max_document_length: 文档的最大长度.如果文本的长度大于最大长度,那么它会被剪切,反之则用0填充. min_frequency: 词频的最小值,出现次数小于最小词频则不会被收录到词表中. vocabulary: Cate…
这里的num_units参数并不是指这一层油多少个相互独立的时序lstm,而是lstm单元内部的几个门的参数,这几个门其实内部是一个神经网络,答案来自知乎: class TRNNConfig(object): """RNN配置参数""" # 模型参数 embedding_dim = 100 # 词向量维度 seq_length = 100 # 序列长度 num_classes = 2 # 类别数 vocab_size = 10000 # 词汇表达…
TensorBoard TensorFlow自带的可视化工具,能够以直观的流程图的方式,清楚展示出整个神经网络的结构和框架,便于理解模型和发现问题. 可视化学习:https://www.tensorflow.org/guide/summaries_and_tensorboard 图的直观展示:https://www.tensorflow.org/guide/graph_viz 直方图信息中心:https://www.tensorflow.org/guide/tensorboard_histogr…
"""Constructor. Sets the properties `cluster_spec`, `is_chief`, `master` (if `None` in the    args), `num_ps_replicas`, `task_id`, and `task_type` based on the    `TF_CONFIG` environment variable, if the pertinent information is    present.…
tensorboard的使用 官方文档 # writer.add_scalar() # 添加标量 """ Args: tag (string): Data identifier # 图表的Title scalar_value (float or string/blobname): Value to save # 对应的y轴 global_step (int): Global step value to record # 对应的x轴 walltime (float): Opti…
前言 本文接着上一篇继续来聊Tensorflow的接口,上一篇中用较低层的接口实现了线性模型,本篇中将用更高级的API--tf.estimator来改写线性模型. 还记得之前的文章<机器学习笔记2 - sklearn之iris数据集>吗?本文也将使用tf.estimator改造该示例. 本文代码都是基于API版本r1.4.本文中本地开发环境为Pycharm,在文中不再赘述. tf.estimator 内置模型 比起用底层API"较硬"的编码方式,tf.estimator的在…
这里涉及到的高级别API主要是使用Estimator类来编写机器学习的程序,此外你还需要用到一些数据导入的知识. 为什么使用Estimator Estimator类是定义在tf.estimator.Estimator中的,你可以使用其中已经有的Estimator,叫做预创建的Estimator,也可以自定义Estimator.Estimator已经封装了训练(train),评估(evaluate),预测(predict),导出以供使用等方法. 此外,Estimator会为我们提供诸如图构建.创建…
TensorFlow的高级机器学习API(tf.estimator)可以轻松配置,训练和评估各种机器学习模型. 在本教程中,您将使用tf.estimator构建一个神经网络分类器,并在Iris数据集上对其进行训练,以基于萼片/花瓣几何学来预测花朵种类. 您将编写代码来执行以下五个步骤: 将包含Iris训练/测试数据的CSV加载到TensorFlow数据集中 构建一个神经网络分类器 使用训练数据训练模型 评估模型的准确性 分类新样品 注:在开始本教程之前,请记住在您的机器上安装TensorFlow…
转载请注明出处:http://www.cnblogs.com/willnote/p/6758953.html 官方API定义 tf.argmax(input, axis=None, name=None, dimension=None) Returns the index with the largest value across axes of a tensor. Args: input: A Tensor. Must be one of the following types: float32…
在TensorFlow中封装好了一个高级库,tf.contrib.layers库封装了很多的函数,使用这个高级库来开发将会提高效率,卷积函数使用tf.contrib.layers.conv2d,池化函数使用tf.contrib.layers.max_pool2d和tf.contrib.layers.avg_pool2d,全连接函数使用 tf.contrib.layers.fully_connected,下面来看里面封装好的函数接口: 以最复杂的卷积为例,其他的几个函数与之类似: layers.c…
在分析训练代码的时候,遇到了,tf.contrib.crf.crf_log_likelihood,这个函数,于是想简单理解下: 函数的目的:使用crf 来计算损失,里面用到的优化方法是:最大似然估计 使用方法: tf.contrib.crf.crf_log_likelihood(inputs, tag_indices, sequence_lengths, transition_params=None) See the guide: CRF (contrib) Computes the log-l…
tf.contrib.rnn.DropoutWrapper Defined in tensorflow/python/ops/rnn_cell_impl.py. def __init__(self, cell, input_keep_prob=1.0, output_keep_prob=1.0, state_keep_prob=1.0, variational_recurrent=False, input_size=None, dtype=None, seed=None): Args: cell…
tf.nn.l2_loss()与tf.contrib.layers.l2_regularizerd()都是TensorFlow中的L2正则化函数,tf.contrib.layers.l2_regularizerd()函数在tf 2.x版本中被弃用了. 两者都能用来L2正则化处理,但运算有一点不同. import tensorflow as tf sess = InteractiveSession() a = tf.constant([1, 2, 3], dtype=tf.float32) b =…
MNIST(Mixed National Institute of Standards and Technology)http://yann.lecun.com/exdb/mnist/ ,入门级计算机视觉数据集,美国中学生手写数字.训练集6万张图片,测试集1万张图片.数字经过预处理.格式化,大小调整并居中,图片尺寸固定28x28.数据集小,训练速度快,收敛效果好. MNIST数据集,NIST数据集子集.4个文件.train-label-idx1-ubyte.gz 训练集标记文件(28881字节)…
TF.Contrib,开源社区贡献,新功能,内外部测试,根据反馈意见改进性能,改善API友好度,API稳定后,移到TensorFlow核心模块.生产代码,以最新官方教程和API指南参考. 统计分布.TF.contrib.ditributions模块,Bernoulli.Beta.Binomial.Gamma.Ecponential.Normal.Poisson.Uniform等统计分布,统计研究.应用中常用,各种统计.机器学习模型基石,概率模型.图形模型依赖. 每个不同统计分布不同特征.函数,同…
这一节,介绍TensorFlow中的一个封装好的高级库,里面有前面讲过的很多函数的高级封装,使用这个高级库来开发程序将会提高效率. 我们改写第十三节的程序,卷积函数我们使用tf.contrib.layers.conv2d(),池化函数使用tf.contrib.layers.max_pool2d()和tf.contrib.layers.avg_pool2d(),全连接函数使用tf.contrib.layers.fully_connected(). 一 tf.contrib.layers中的具体函数…
开源框架---通过Bazel编译使用tensorflow c++ API 记录 tensorflow python API,在python中借用pip安装tensorflow,真的很方便,几句指令就完成了. tensorflow c++ API,通过Bazel编译tensorflow源码方式接通C++接口,配了好几天,终于顺利结束.第一次这么配置,真的是一路踩坑,不断的解决,已经忘了如何一步步完成的.就是遇到问题就解决,奋力爬出坑.总结不顺利的几点原因: 1,版本问题.不兼容,或高或低.tf +…
#!/usr/bin/env python # -*- coding: utf-8 -*- import tensorflow as tf import numpy as np params=np.random.normal(loc=0.0,scale=1.0,size=[10,10]) encoder_inputs=tf.placeholder(dtype=tf.int32,shape=[10,10]) decoder_inputs=tf.placeholder(dtype=tf.int32,…
问题:LSTM的输出值output和state是否是一样的 1. rnn.LSTMCell(num_hidden, reuse=tf.get_variable_scope().reuse)  # 构建单层的LSTM网络 参数说明:num_hidden表示隐藏层的个数,reuse表示LSTM的参数进行复用 2.rnn.DropoutWrapper(cell, output_keep_prob=keep_prob) # 表示对rnn的输出层进行dropout 参数说明:cell表示单层的lstm,o…
For Tensorflow 1.2 and Keras 2.0, the line tf.contrib.rnn.core_rnn_cell.BasicLSTMCell should be replaced by tf.contrib.rnn.BasicLSTMCell.…
------------------------------------ 写在开头:此文参照莫烦python教程(墙裂推荐!!!) ------------------------------------ TensorFlow之建造第一个神经网络 1 定义添加层 import tensorflow as tf def add_layer(inputs,in_size,out_size,activation_function=None): Weights = tf.Variable(tf.rand…
# TensorFlow dataset API 使用 由于本人感兴趣的是自然语言处理,所以下面有关dataset API 的使用偏向于变长数据的处理. 1. 从迭代器中引入数据 import numpy as np import tensorflow as tf def gen(): for _ in range(10): sz = np.random.randint(3, 20, 1)[0] yield np.random.randint(1, 100, sz), np.random.ran…
来自:https://cloud.tencent.com/developer/labs/lab/10324 TensorFlow - 相关 API TensorFlow 相关函数理解 任务时间:时间未知 tf.nn.conv2d conv2d( input, filter, strides, padding, use_cudnn_on_gpu=True, data_format='NHWC', name=None ) 功能说明: 卷积的原理可参考 A guide to convolution a…
TensorFlow — 相关 API TensorFlow 相关函数理解 任务时间:时间未知 tf.truncated_normal truncated_normal( shape, mean=0.0, stddev=1.0, dtype=tf.float32, seed=None, name=None ) 功能说明: 产生截断正态分布随机数,取值范围为[mean - 2 * stddev, mean + 2 * stddev]. 参数列表: 参数名 必选 类型 说明 shape 是 1 维整…
1. tf.add(a, b) 与 a+b 在神经网络前向传播的过程中,经常可见如下两种形式的代码: tf.add(tf.matmul(x, w), b) tf.matmul(x, w) + b 简而言之,就是 tf.add(a, b) 与 a + b二者的区别,类似的也有,tf.assign 与 =(赋值运算符)的差异. 在计算精度上,二者并没有差别.运算符重载的形式a+b,会在内部转换为,a.__add__(b),而a.__add__(b)会再一次地映射为tf.add,在 math_ops.…
#CMakeLists.txt cmake_minimum_required (VERSION ) project (tf_example) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -std=c++11 -W") #link_directories(./lib) include_directories( /home/u/tf1./tensorflow-GPU /home/u/tf1./tensorflow-GPU/bazel-genfile…
tf.contrib.layers.fully_connected 添加完全连接的图层. tf.contrib.layers.fully_connected(    inputs,    num_outputs,    activation_fn=tf.nn.relu,    normalizer_fn=None,    normalizer_params=None,    weights_initializer=initializers.xavier_initializer(),    wei…
TensorFlow提供了一个用于保存模型的工具以及一个可视化方案 这里使用的TensorFlow为1.3.0版本 一.保存模型数据 模型数据以文件的形式保存到本地: 使用神经网络模型进行大数据量和复杂模型训练时,训练时间可能会持续增加,此时为避免训练过程出现不可逆的影响,并验证训练效果,可以考虑分段进行,将训练数据模型保存,然后在继续训练时重新读取: 此外,模型训练完毕,获取一个性能良好的模型后,可以保存以备重复利用: 模型保存形式如下: 保存模型数据的基本方法: save_dir = 'mo…