仍在学习tensorflow,我正在尝试在darkflow中的某些代码中更改损失函数
网络输出具有形状的给定张量[49,3,2]。我想在张量的最后一部分中取两个元素,并使用一些代码对其进行处理。然后,我想退还数据。因此,有点像可以与TensorFlow一起使用的地图。
更多上下文-https://github.com/thtrieu/darkflow/blob/master/master/darkflow/net/yolo/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
看来tf.map_fn
功能适合您的需求。该文档说明您可以将Python可呼叫应用于张量或一系列张量。
当前文档的提取,介绍该功能的主要参数:
fn:要执行的可调用。它接受一个参数,该参数将具有与Elems相同的(可能嵌套(结构。如果提供了它的输出,则必须具有与dtype相同的结构,否则必须具有与元素相同的结构。
Elems:张量或(可能嵌套的(张量序列,每个张量将沿其第一个尺寸拆开。所得切片的嵌套序列将应用于fn。
此功能可从TensorFlow 0.8获得,因此几乎总是可用。