0

仍在学习 Tensorflow,我正在尝试更改 Darkflow 中某些代码中的损失函数

网络输出形状为 [49,3,2] 的给定张量。我想取张量最后一部分中的两个元素并用一些代码处理它们。然后我想返回数据。所以有点像一张可以与 Tensorflow 一起使用的地图。

更多上下文 -我要更改的文件的https://github.com/thtrieu/darkflow/blob/master/darkflow/net/yolo/train.py 。

所以不确定如何做到这一点,如果我对这个问题不够清楚,请询问更多信息。我仍然试图弄清楚我想做的事情。

例如

S = 7
SS = S * S 
C = 8 
B = 3

size1 = [None, SS, C]
size2 = [None, SS, B]


# Extract the coordinate prediction from net.out
coords = net_out[:, SS * (C + B):]
# Take flatten array and make it back into a tensor.
coords = tf.reshape(coords, [-1, SS, B, 4])
wh = tf.pow(coords[:,:,:,2:4], 2) * S # unit: grid cell
area_pred = wh[:,:,:,0] * wh[:,:,:,1] # unit: grid cell^2
centers = coords[:,:,:,0:2] # [batch, SS, B, 2]
floor = centers - (wh * .5) # [batch, SS, B, 2]
ceil  = centers + (wh * .5) # [batch, SS, B, 2]

# calculate the intersection areas 
# WHAT HAPPENS CURRENTLY 
intersect_upleft   = tf.maximum(floor, _upleft)
intersect_botright = tf.minimum(ceil , _botright)
intersect_wh = intersect_botright - intersect_upleft
intersect_wh = tf.maximum(intersect_wh, 0.0)
intersect = tf.multiply(intersect_wh[:,:,:,0], intersect_wh[:,:,:,1])

 # I WANT TO CALCULATE THE AREA OF INTERSECTION THE BOX DIFFERENTLY SO 
   I WOULD HAVE 
   MY OWN FUNCTION DOING SOMETHING. BUT I ONLY WANT IT DONE FOR CENTERS 
   AND THEN RETURN A BIT LIKE A MAP FUNCTION BUT I NEED IT TO WORK WITH 
   TENSORFLOW PLACEHOLDERS 

任何提示或建议都会很好,谢谢家伙:D

4

1 回答 1

0

看来该tf.map_fn功能符合您的需求。该文档解释了您可以将 Python 可调用对象应用于张量或张量序列。

当前文档的摘录,关于函数的主要参数:

fn:要执行的调用。它接受一个参数,该参数将具有与 elems 相同的(可能是嵌套的)结构。如果提供了一个,它的输出必须与 dtype 具有相同的结构,否则它必须与 elems 具有相同的结构。

elems:张量或(可能是嵌套的)张量序列,每个张量都将沿着它们的第一维展开。结果切片的嵌套序列将应用于 fn。

此功能从 TensorFlow 0.8 开始提供,因此几乎始终可用。

于 2018-04-02T02:27:14.980 回答