zoukankan      html  css  js  c++  java
  • tf.reduce_mean() || tf.contrib.rnn.BasicRnnCell || tf.contrib.rnn.BasicLSTMCell || tf.reshape()

    tf.reduce_mean()

    (或tf.reduce_max()一个是求平均值,一个是求最大值)

    # 'x' is [[1., 2.]
    #         [3., 4.]]
    
    x是一个2维数组,分别调用reduce_*函数如下:
    
    首先求平均值:
    
    tf.reduce_mean(x) ==> 2.5 #如果不指定第二个参数,那么就在所有的元素中取平均值
    tf.reduce_mean(x, 0) ==> [2.,  3.] #指定第二个参数为0,则第一维的元素取平均值,即每一列求平均值
    tf.reduce_mean(x, 1) ==> [1.5,  3.5] #指定第二个参数为1,则第二维的元素取平均值,即每一行求平均值
    
    同理,还可用tf.reduce_max()求最大值等

    tf.contrib.rnn.BasicRnnCell

    BasicRNNCell是最基本的RNN cell单元。 
    输入参数:
    num_units:RNN层神经元的个数 input_size(该参数已被弃用) activation: 内部状态之间的激活函数 reuse: Python布尔值, 描述是否重用现有作用域中的变量

    tf.contrib.rnn.BasicLSTMCell

    BasicLSTMCell类是最基本的LSTM循环神经网络单元。 
    输入参数:
    num_units: LSTM cell层中的单元数 
    forget_bias: forget gates中的偏置 
    state_is_tuple: 还是设置为True吧, 返回 (c_state , m_state)的二元组 
    activation: 状态之间转移的激活函数 
    reuse: Python布尔值, 描述是否重用现有作用域中的变量

    tf.reshape()

    reshape即把矩阵的形状变一下
    看一下例子:
    
    tensor = tf.constant([1, 2, 3, 4, 5, 6, 7,8])
    
     sess.run(tf.initialize_all_variables())
    #[1 2 3 4 5 6 7 8]
    
    tensorReshape = tf.reshape(tensor,[2,4])
    #[[1 2 3 4]
    #[5 6 7 8]]
    
    tensorReshape = tf.reshape(tensor,[1,2,4])
    #[[[1 2 3 4]
    #[5 6 7 8]]]
    
    tensorReshape = tf.reshape(tensor,[-1,2,2])
    #[[[1 2]
    #[3 4]]
    
    #[[5 6]
    #[7 8]]]
    #所以-1代表的含义是不用我们自己指定这一维的大小,函数会自动计算,但列表中只能存在一个-1
    #比如:

  • 相关阅读:
    IDEA Rider Express expected
    .netCore与Framework相同位数下生成的hashcode是不一样的
    IDEA Rider代码错误提示关闭
    VS C# 项目一个解决方案包含多个git库项目问题
    Git Updates were rejected because the tip of your current branch is behind 一例解决方案
    IISExpress 管道模式、集成模式切换
    vs 下TGIT插件
    git常用命令
    自建git项目管理库及ssh方式使用
    Ext.net store数据加载事件
  • 原文地址:https://www.cnblogs.com/hozhangel/p/8087193.html
Copyright © 2011-2022 走看看