gpt4 book ai didi

python - static_rnn 和 dynamic_rnn 有什么区别?

转载 作者:太空狗 更新时间:2023-10-30 00:47:20 26 4
gpt4 key购买 nike

在tensorflow中,tf.nn.static_rnntf.nn.dynamic_rnn有什么区别,什么时候用?

两者都采用一个 sequence_length 参数,使计算适应输入的实际长度;这不像 static_rnn 仅限于固定大小的输入,对吧?

dynamic_rnn 具有以下额外参数:

  • parallel_iterations
  • swap_memory
  • time_major

但我想这些只是微小的差异。

那么 tf.nn.static_rnntf.nn.dynamic_rnn 之间的主要区别是什么?我们什么时候应该使用其中一个?

最佳答案

这仍然是一个有用的资源(尽管是几年前写的): http://www.wildml.com/2016/08/rnns-in-tensorflow-a-practical-guide-and-undocumented-features/

其中,Denny Britz 对静态/动态问题有以下评论:

静态

Internally, tf.nn.rnn creates an unrolled graph for a fixed RNN length. That means, if you call tf.nn.rnn with inputs having 200 time steps you are creating a static graph with 200 RNN steps. First, graph creation is slow. Second, you’re unable to pass in longer sequences (> 200) than you’ve originally specified.

动态

tf.nn.dynamic_rnn solves this. It uses a tf.While loop to dynamically construct the graph when it is executed. That means graph creation is faster and you can feed batches of variable size.

总的来说,他得出的结论是使用 tf.nn.static_rnn 并没有真正的好处,而且在大多数情况下你会想要求助于 tf.nn.dynamic_rnn

不管怎样,我自己也有过同样的经历。

关于python - static_rnn 和 dynamic_rnn 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51425803/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com