从tf.map_fn返回

2024-05-14 19:04:16 发布

您现在位置:Python中文网/ 问答频道 /正文

bbox_organize()的两种返回类型。来自if statement的第一个是[5],来自else statement is (2,5)的第二个是

我怎样才能把它放进盒子里

import tensorflow as tf
tf.enable_eager_execution();

boxes = tf.constant([[1.0,2.0,2.3,3.4,0,0,0,0],[2.0,3.2,4.2,4.0,0,0,0,0],[3.0,4.0,1.0,2.1,1.2,1.4,1.2,1.5],[1.2,1.3,3.4,4.5,1,2,3,4]])
rows = tf.expand_dims(tf.range(tf.shape(boxes)[0], dtype=tf.int32), 1)
def bbox_organize(box, i):
   if(tf.reduce_sum(box[4:]).numpy() == 0):
      box=tf.slice(box, [0], [4])
      const_=tf.constant(i.numpy()[0], dtype="float32", shape=[1])
      box=tf.concat([const_, box], 0)

   else:
      box=tf.reshape(box, [2, 4])
      const_=tf.constant(i.numpy()[0], dtype="float32", shape=[2, 1])
      box=tf.concat([const_, box], 1)

   return box 

boxes_=tf.map_fn(lambda x: (bbox_organize(x[0], x[1])), (boxes, rows), dtype="float32")
print(boxes_)

Tags: numpyboxiftfelserowsstatementshape

热门问题