• RNN神经网络层的输出格式和形状


    tf.keras.layers.RNN(
        cell, return_sequences=False, return_state=False, go_backwards=False,
        stateful=False, unroll=False, time_major=False, **kwargs
    )
    

    RNN的输出非常tricky,官方文档要细读。
    If return_state: a list of tensors. The first tensor is the output. The remaining tensors are the last states, each with shape [batch_size, state_size], where state_size could be a high dimension tensor shape.
    If return_sequences: N-D tensor with shape [batch_size, timesteps, output_size], where output_size could be a high dimension tensor shape, or [timesteps, batch_size, output_size] when time_major is True.
    Else, N-D tensor with shape [batch_size, output_size], where output_size could be a high dimension tensor shape.

    如果return_state=Truereturn_sequences=True,输出的一个list,第一个元素是output,shape [batch_size, timesteps, output_size],第二个元素是latest states,注意是latest,最后时刻的states,而不是每个时刻的states,所以shape [batch_size, state_size]

    out = keras.layers.RNN(LNSimpleRNNCell(20), return_sequences=True, return_state=True,
                         input_shape=[None, 1])(X_train)
    
    X_train.shape # (7000, 50, 1)
    out[0].shape # ([7000, 50, 20])
    out[1].shape # ([7000, 20])
    
  • 相关阅读:
    第一节 49_ref_out 简单
    第一节 38函数 简单
    第二节 2面向对像简介 简单
    第一节 42字符串基础 简单
    第二节 3属性 简单
    第一节 33enum枚举 简单
    Java jdbc 数据库
    css 使IE和FIREFOX下变为手型
    JS调用PageMethods
    USB设备量产导致通用串行总线控制器显示感叹号解决办法
  • 原文地址:https://www.cnblogs.com/yaos/p/14014102.html
Copyright © 2020-2023  润新知