zoukankan      html  css  js  c++  java
  • 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])
    
  • 相关阅读:
    笔记本
    物料主档建立(PP模组)
    烦!烦!烦!
    Windows Live Writer试用
    SAP系统中发送公告的几种办法
    [CSS样式表之] 渐变色的实现
    今天终于开通了这个博客了
    MFC消息映射机制过程
    绘图
    C++ 内存分配和指针
  • 原文地址:https://www.cnblogs.com/yaos/p/14014102.html
Copyright © 2011-2022 走看看