zoukankan      html  css  js  c++  java
  • 『TensorFlow』函数查询列表_神经网络相关

    tf.Graph

    操作描述
    class tf.Graph tensorflow中的计算以图数据流的方式表示
    一个图包含一系列表示计算单元的操作对象
    以及在图中流动的数据单元以tensor对象表现
    tf.Graph.__init__() 建立一个空图
    tf.Graph.as_default() 一个将某图设置为默认图,并返回一个上下文管理器
    如果不显式添加一个默认图,系统会自动设置一个全局的默认图。
    所设置的默认图,在模块范围内所定义的节点都将默认加入默认图中
    tf.Graph.as_graph_def
    (from_version=None, add_shapes=False)
    返回一个图的序列化的GraphDef表示
    序列化的GraphDef可以导入至另一个图中(使用 import_graph_def())
    或者使用C++ Session API
    tf.Graph.finalize() 完成图的构建,即将其设置为只读模式
    tf.Graph.finalized 返回True,如果图被完成
    tf.Graph.control_dependencies(control_inputs) 定义一个控制依赖,并返回一个上下文管理器
    with g.control_dependencies([a, b, c]):
    # `d` 和 `e` 将在 `a`, `b`, 和`c`执行完之后运行.
    d = …
    e = …
    tf.Graph.device(device_name_or_function) 定义运行图所使用的设备,并返回一个上下文管理器
    with g.device('/gpu:0'): ...
    with g.device('/cpu:0'): ...
    tf.Graph.name_scope(name) 为节点创建层次化的名称,并返回一个上下文管理器
    tf.Graph.add_to_collection(name, value) 将value以name的名称存储在收集器(collection)中
    tf.Graph.get_collection(name, scope=None) 根据name返回一个收集器中所收集的值的列表
    tf.Graph.as_graph_element
    (obj, allow_tensor=True, allow_operation=True)
    返回一个图中与obj相关联的对象,为一个操作节点或者tensor数据
    tf.Graph.get_operation_by_name(name) 根据名称返回操作节点
    tf.Graph.get_tensor_by_name(name) 根据名称返回tensor数据
    tf.Graph.get_operations() 返回图中的操作节点列表
    tf.Graph.gradient_override_map(op_type_map) 用于覆盖梯度函数的上下文管理器

    神经网络(Neural Network)

    • 激活函数(Activation Functions)
    操作描述
    tf.nn.relu(features, name=None) 整流函数:max(features, 0)
    tf.nn.relu6(features, name=None) 以6为阈值的整流函数:min(max(features, 0), 6)
    tf.nn.elu(features, name=None) elu函数,exp(features) - 1 if < 0,否则features
    Exponential Linear Units (ELUs)
    tf.nn.softplus(features, name=None) 计算softplus:log(exp(features) + 1)
    tf.nn.dropout(x, keep_prob,
    noise_shape=None, seed=None, name=None)
    计算dropout,keep_prob为keep概率
    noise_shape为噪声的shape
    tf.nn.bias_add(value, bias, data_format=None, name=None) 对value加一偏置量
    此函数为tf.add的特殊情况,bias仅为一维,
    函数通过广播机制进行与value求和,
    数据格式可以与value不同,返回为与value相同格式
    tf.sigmoid(x, name=None) y = 1 / (1 + exp(-x))
    tf.tanh(x, name=None) 双曲线切线激活函数
    • 卷积函数(Convolution)
    操作描述
    tf.nn.conv2d(input, filter, strides, padding,
    use_cudnn_on_gpu=None, data_format=None, name=None)
    在给定的4D input与 filter下计算2D卷积
    输入shape为 [batch, height, width, in_channels]
    tf.nn.conv3d(input, filter, strides, padding, name=None) 在给定的5D input与 filter下计算3D卷积
    输入shape为[batch, in_depth, in_height, in_width, in_channels]
    • 池化函数(Pooling)
    操作描述
    tf.nn.avg_pool(value, ksize, strides, padding,
    data_format=’NHWC’, name=None)
    平均方式池化
    tf.nn.max_pool(value, ksize, strides, padding,
    data_format=’NHWC’, name=None)
    最大值方法池化
    tf.nn.max_pool_with_argmax(input, ksize, strides,
    padding, Targmax=None, name=None)
    返回一个二维元组(output,argmax),最大值pooling,返回最大值及其相应的索引
    tf.nn.avg_pool3d(input, ksize, strides,
    padding, name=None)
    3D平均值pooling
    tf.nn.max_pool3d(input, ksize, strides,
    padding, name=None)
    3D最大值pooling
    • 数据标准化(Normalization)
    操作描述
    tf.nn.l2_normalize(x, dim, epsilon=1e-12, name=None) 对维度dim进行L2范式标准化
    output = x / sqrt(max(sum(x**2), epsilon))
    tf.nn.sufficient_statistics(x, axes, shift=None,
    keep_dims=False, name=None)
    计算与均值和方差有关的完全统计量
    返回4维元组,*元素个数,*元素总和,*元素的平方和,*shift结果
    参见算法介绍
    tf.nn.normalize_moments(counts, mean_ss, variance_ss, shift, name=None) 基于完全统计量计算均值和方差
    tf.nn.moments(x, axes, shift=None,
    name=None, keep_dims=False)
    直接计算均值与方差
    • 损失函数(Losses)
    操作描述
    tf.nn.l2_loss(t, name=None) output = sum(t ** 2) / 2
    • 分类函数(Classification)
    操作描述
    tf.nn.sigmoid_cross_entropy_with_logits
    (logits, targets, name=None)*
    计算输入logits, targets的交叉熵
    tf.nn.softmax(logits, name=None) 计算softmax
    softmax[i, j] = exp(logits[i, j]) / sum_j(exp(logits[i, j]))
    tf.nn.log_softmax(logits, name=None) logsoftmax[i, j] = logits[i, j] - log(sum(exp(logits[i])))
    tf.nn.softmax_cross_entropy_with_logits
    (logits, labels, name=None)
    计算logits和labels的softmax交叉熵
    logits, labels必须为相同的shape与数据类型
    tf.nn.sparse_softmax_cross_entropy_with_logits
    (logits, labels, name=None)
    计算logits和labels的softmax交叉熵
    tf.nn.weighted_cross_entropy_with_logits
    (logits, targets, pos_weight, name=None)
    与sigmoid_cross_entropy_with_logits()相似,
    但给正向样本损失加了权重pos_weight
    • 符号嵌入(Embeddings)
    操作描述
    tf.nn.embedding_lookup
    (params, ids, partition_strategy=’mod’,
    name=None, validate_indices=True)
    根据索引ids查询embedding列表params中的tensor值
    如果len(params) > 1,id将会安照partition_strategy策略进行分割
    1、如果partition_strategy为”mod”,
    id所分配到的位置为p = id % len(params)
    比如有13个ids,分为5个位置,那么分配方案为:
    [[0, 5, 10], [1, 6, 11], [2, 7, 12], [3, 8], [4, 9]]
    2、如果partition_strategy为”div”,那么分配方案为:
    [[0, 1, 2], [3, 4, 5], [6, 7, 8], [9, 10], [11, 12]]
    tf.nn.embedding_lookup_sparse(params,
    sp_ids, sp_weights, partition_strategy=’mod’,
    name=None, combiner=’mean’)
    对给定的ids和权重查询embedding
    1、sp_ids为一个N x M的稀疏tensor,
    N为batch大小,M为任意,数据类型int64
    2、sp_weights的shape与sp_ids的稀疏tensor权重,
    浮点类型,若为None,则权重为全’1’
    • 循环神经网络(Recurrent Neural Networks)
    操作描述
    tf.nn.rnn(cell, inputs, initial_state=None, dtype=None,
    sequence_length=None, scope=None)
    基于RNNCell类的实例cell建立循环神经网络
    tf.nn.dynamic_rnn(cell, inputs, sequence_length=None,
    initial_state=None, dtype=None, parallel_iterations=None,
    swap_memory=False, time_major=False, scope=None)
    基于RNNCell类的实例cell建立动态循环神经网络
    与一般rnn不同的是,该函数会根据输入动态展开
    返回(outputs,state)
    tf.nn.state_saving_rnn(cell, inputs, state_saver, state_name,
    sequence_length=None, scope=None)
    可储存调试状态的RNN网络
    tf.nn.bidirectional_rnn(cell_fw, cell_bw, inputs,
    initial_state_fw=None, initial_state_bw=None, dtype=None,
    sequence_length=None, scope=None)
    双向RNN, 返回一个3元组tuple
    (outputs, output_state_fw, output_state_bw)

    tf.nn.rnn简要介绍
    cell: 一个RNNCell实例
    inputs: 一个shape为[batch_size, input_size]的tensor
    initial_state: 为RNN的state设定初值,可选
    sequence_length:制定输入的每一个序列的长度,size为[batch_size],值范围为[0, T)的int型数据
    其中T为输入数据序列的长度
    @
    @针对输入batch中序列长度不同,所设置的动态计算机制
    @对于在时间t,和batch的b行,有
    (output, state)(b, t) = ? (zeros(cell.output_size), states(b, sequence_length(b) - 1)) : cell(input(b, t), state(b, t - 1))


    • 求值网络(Evaluation)
    操作描述
    tf.nn.top_k(input, k=1, sorted=True, name=None) 返回前k大的值及其对应的索引
    tf.nn.in_top_k(predictions, targets, k, name=None) 返回判断是否targets索引的predictions相应的值
    是否在在predictions前k个位置中,
    返回数据类型为bool类型,len与predictions同

    对于有巨大量的多分类与多标签模型,如果使用全连接softmax将会占用大量的时间与空间资源,所以采用候选采样方法仅使用一小部分类别与标签作为监督以加速训练。

    操作描述
    Sampled Loss Functions  
    tf.nn.nce_loss(weights, biases, inputs, labels, num_sampled,
    num_classes, num_true=1, sampled_values=None,
    remove_accidental_hits=False, partition_strategy=’mod’,
    name=’nce_loss’)
    返回noise-contrastive的训练损失结果
    tf.nn.sampled_softmax_loss(weights, biases, inputs, labels,
    num_sampled, num_classes, num_true=1, sampled_values=None,
    remove_accidental_hits=True, partition_strategy=’mod’,
    name=’sampled_softmax_loss’)
    返回sampled softmax的训练损失
    参考- Jean et al., 2014第3部分
    Candidate Samplers  
    tf.nn.uniform_candidate_sampler(true_classes, num_true,
    num_sampled, unique, range_max, seed=None, name=None)
    通过均匀分布的采样集合
    返回三元tuple
    1、sampled_candidates 候选集合。
    2、期望的true_classes个数,为浮点值
    3、期望的sampled_candidates个数,为浮点值
    tf.nn.log_uniform_candidate_sampler(true_classes, num_true,
    num_sampled, unique, range_max, seed=None, name=None)
    通过log均匀分布的采样集合,返回三元tuple
    tf.nn.learned_unigram_candidate_sampler
    (true_classes, num_true, num_sampled, unique,
    range_max, seed=None, name=None)
    根据在训练过程中学习到的分布状况进行采样
    返回三元tuple
    tf.nn.fixed_unigram_candidate_sampler(true_classes, num_true,
    num_sampled, unique, range_max, vocab_file=”,
    distortion=1.0, num_reserved_ids=0, num_shards=1,
    shard=0, unigrams=(), seed=None, name=None)
    基于所提供的基本分布进行采样

    保存与恢复变量

    操作描述
    类tf.train.Saver(Saving and Restoring Variables)  
    tf.train.Saver.__init__(var_list=None, reshape=False,
    sharded=False, max_to_keep=5,
    keep_checkpoint_every_n_hours=10000.0,
    name=None, restore_sequentially=False,
    saver_def=None, builder=None)
    创建一个存储器Saver
    var_list定义需要存储和恢复的变量
    tf.train.Saver.save(sess, save_path, global_step=None,
    latest_filename=None, meta_graph_suffix=’meta’,
    write_meta_graph=True)
    保存变量
    tf.train.Saver.restore(sess, save_path) 恢复变量
    tf.train.Saver.last_checkpoints 列出最近未删除的checkpoint 文件名
    tf.train.Saver.set_last_checkpoints(last_checkpoints) 设置checkpoint文件名列表
    tf.train.Saver.set_last_checkpoints_with_time(last_checkpoints_with_time) 设置checkpoint文件名列表和时间戳

  • 相关阅读:
    java中计算两个时间差
    增强for循环用法
    SQLServer类型与Java类型转换问题解决
    有关SQL模糊查询
    js 弹出div窗口 可移动 可关闭 (转)
    登陆sqlserver及修改端口号 (转)
    C#判断IP地址是否合法函数-使用正则表达式-2个 (转)
    c#图像处理入门(-bitmap类和图像像素值获取方法) 转
    MongoDB C#驱动中Query几个方法 (转)
    微信公众帐号自定义菜单创建及事件响应开发教程 附源代码(转)
  • 原文地址:https://www.cnblogs.com/hellcat/p/6906065.html
Copyright © 2011-2022 走看看