首页 > 解决方案 > 如何改变 rnn 网络的输出形状?

问题描述

如何将tf.nn.dynamic_rnn[batch_size, max_stepsize, num_hidden] 的输出更改为 [batch_size, num_hidden]?

self.outputs = tf.reshape(outputs, [-1, num_hidden]) 给出 [batch_size * max_stepsize, num_hidden] 但我正在寻找 [batch_size , num_hidden] 而我不想使用 tf.reshape(outputs, [batch_size, num_hidden]). 我试过了shape = tf.shape(outputs)[1]tf.squeeze(outputs, shape)但它给出了错误:

TypeError: Expected list for 'axis' argument to 'squeeze' Op, not <tf.Tensor 'lstm/strided_slice:0' shape=() dtype=int32>.

任何解决方案?

标签: recurrent-neural-network

解决方案


推荐阅读