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])
    
  • 相关阅读:
    docker进入交互界面
    FCN训练注意事项
    centos7 常用命令
    vim锁定,不能动
    爬虫三之beautifulsoup
    爬虫二之Requests
    爬虫一之基本操作
    MathType的配置问题;将word中的公式转换为mathtype格式失败,缺少OMML2MML.XSL
    神经网络实现Discuz验证码识别
    修改linux环境变量配置文件
  • 原文地址:https://www.cnblogs.com/yaos/p/14014148.html
Copyright © 2011-2022 走看看