【问题标题】:TensorFlow placeholder decoupling for external python codeTensorFlow占位符解耦外部python代码
【发布时间】:2018-04-01 03:43:56
【问题描述】:

仍在学习 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

【问题讨论】:

    标签: python tensorflow yolo darkflow


    【解决方案1】:

    看来tf.map_fn 函数符合您的需求。 documentation 解释了您可以将 Python 可调用对象应用于张量或张量序列。

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

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

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

    此函数从 TensorFlow 0.8 开始可用,因此几乎始终可用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多