【发布时间】:2016-04-05 12:54:01
【问题描述】:
我正在尝试使用 seq2seq.rnn_decoder() 在 Tensorflow 中设置顺序 RNN。 rnn_decoder() 想要的输入是张量列表,因此为了生成它,我传入了一个 rank-3 张量并使用 tf.unpack() 将其放入列表中。当我传入的 float32 数组通过 tf.unpack() 变成 float64 张量时,就会出现问题,使其与模型的其余部分不兼容。这是我整理的代码,以使我相信罪魁祸首是 tf.unpack():
inputDat = loader.getSequential(BATCH_SIZE)
print(inputDat.shape)
输出(BATCH_SIZE 为 5,序列长度为 10):
(10, 5, 3)
然后我可以在 Tensorflow 会话中加载这些数据:
sess = tf.InteractiveSession()
input_tensor = tf.constant(inputDat.astype('float32'), dtype=tf.float32)
print "Input tensor type: " + str(type(input_tensor.eval()[0,0,0]))
input_tensor = tf.unpack(inputDat)
print "Input tensor shape: " + str(len(input_tensor)) + "x" + str(input_tensor[0].eval().shape)
print "Input tensor type: " + str(type(input_tensor[0].eval()[0,0]))
输出:
Input tensor type: <type 'numpy.float32'>
Input tensor shape: 10x(5, 3)
Input tensor type: <type 'numpy.float64'>
这里发生了什么?使用 FOR 循环遍历每个顺序条目并重新转换它似乎是错误的方法,而且我无法在 Tensorflow 中找到一个方法来转换列表的每个成员。
【问题讨论】:
标签: python numpy tensorflow