我有以下形状的视频帧张量 (frames, 128, 128, 3) 其中帧在 25 到 36 之间变化。现在我希望张量具有固定大小 (36, 128, 128, 3) 通过将最后一帧重复 36 帧 次。
我可以通过以下方式提取形状为 (128, 128, 3) 的最后一帧:
shape = tf.shape(视频) last_frame = tf.gather_nd(video, [shape[0]-1])
我现在想重复 36-shape[0] 次并将其添加到 video 的末尾。 我该怎么做?
谢谢。
请您参考如下方法:
您可以通过选择最后一个元素,使用 tf.tile 将其复制 n 次,然后连接您的结果来做到这一点。
last = frames[-1]
last_35 = tf.tile(tf.expand_dims(last, 0), [35-tf.shape(frames)[0] ,1,1,1])
frames = tf.concat([frames, last_35], 0)
