gpt4 book ai didi

tensorflow - 是否可以将张量提供给占位符?

转载 作者:行者123 更新时间:2023-12-01 19:09:11 24 4
gpt4 key购买 nike

有没有办法将张量提供给占位符,或者在定义张量后连接张量的类似机制?

我一直在层中定义我的网络,但现在我发现自己需要为早期层提供来自后面层的张量。这是伪代码,如果有错误,我很抱歉。

...
# rnn layer
...
outputs, states = rnn.rnn(cell, inputs, ...)
...
# fc layer
...
logits = [tf.matmul(output, W_fc)+b_fc for output in outputs]
...
# predictions
...
preds = [to_one_hot(tf.argmax(logit, 1)) for logit in logits]
...
# now I want to connect preds[t] to inputs[t+1]

如果 input[1:] 可以是占位符并且我可以将 preds[:-1] 提供给它们,那就太好了。

如果没有办法,我打算使用的困惑方法是随着时间循环,从 rnn 开始,通过时间时间步定义反向传播的所有层。非常感谢任何帮助。

最佳答案

使用tensorflow.placeholder_with_default (...)

#!/usr/bin/python

import tensorflow as tf

s = tf.InteractiveSession()

x = tf.placeholder_with_default( [ [1,2,3,4,5,6] ] , [None , 6])

print s.run ( x )

关于tensorflow - 是否可以将张量提供给占位符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35786289/

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