Tensorflow - 迭代两个张量

我有两个相似的张量;一个拥有所有找到的有效框,另一个拥有它们所属的所有索引。

Tensor("valid_boxes:0", shape=(?, 9), dtype=float32)

Tensor("valid_boxes_indexes:0", shape=(?, 4), dtype=int64)

我需要一个map_fun访问这两个变量的。我试过这个:

operation = tf.map_fn(lambda x: generate_bounding_box(x[0], x[1][1], x[1][0], x[1][2], grid_h, grid_w, anchors), (valid_boxes, valid_boxes_indexes))

Tensorflow 给了我以下内容:

ValueError: 这两个结构没有相同的嵌套结构。

第一个结构:type=tuple str=(tf.float32, tf.int64)

第二种结构:type=Tensor str=Tensor("map_14/while/stack:0", shape=(5,), dtype=float32)

更具体地说:子结构 "type=tuple str=(tf.float32, tf.int64)" 是一个序列,而子结构 "type=Tensor str=Tensor("map_14/while/stack:0", shape=(5,) , dtype=float32)" 不是

有没有办法正确地做到这一点?


海绵宝宝撒
浏览 188回答 1
1回答

慕尼黑的夜晚无繁华

dtype当输入和输出值不具有相同的结构时,您需要指定 a 。从文档tf.map_fn:此外,fn可能会发出与其输入不同的结构。例如,fn可能看起来像:fn = lambda t1: return (t1 + 1, t1 - 1)。在这种情况下,dtype参数不是可选的:dtype必须是与fn.试试这个:operation = tf.map_fn(    lambda x: generate_bounding_box(x[0], x[1][1], x[1][0], x[1][2],                                    grid_h, grid_w, anchors),    (valid_boxes, valid_boxes_indexes)    dtype=tf.float32)
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python