【发布时间】:2017-03-10 12:39:13
【问题描述】:
我想使用 Tensorflow 为 RNN 应用程序做滑动窗口转换。
对于 4 的窗口大小,通过 Tensorflow 简单整形,我们可以变换以下张量:
[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]
到:
[[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16],[17,18,19,20]]
但我希望它的步幅为 1,如以下张量:
[[1,2,3,4],[2,3,4,5],[3,4,5,6],[7,8,9,10],...,[17,18,19,20]]
使用 TensorFlow 平铺我可以得到:
[[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20],
[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20],
[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20],
[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]]
我认为通过一些转变,我可以得到我想要的。你有什么想法吗?
我生成上述平铺结果的代码很简单,如下所示。但是每个元素将是一个表示瓶颈(来自 CNN 的特征向量)的一维张量,而不是我上面示例中的数字。
model.logits, model.end_points = inception_v3.inception_v3(model.X_Norm, num_classes=nbrOfOutputNeurons, is_training=is_training)
model.bottleneck = slim.flatten(model.end_points['PreLogits']) # The ouput before FC
x = tf.reshape(model.bottleneck, [1, -1, bottleneck_tensor_size])
x = tf.tile(x, [rnn_time_steps, 1, 1])
【问题讨论】:
-
s=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]和d = [s[i:i+4] for i in range(len(s)) if len(s[i:i+4])> 3] -
@Hesham 您目前使用什么代码来生成您正在展示的这些输出?
-
@dantiston 我已经编辑了我的问题。
-
@dsgdfg 谢谢。但是用 Pyhton 列表做这件事很简单,问题是如何在 TF 图上表示?
标签: python tensorflow