tensor_ops.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:hart 作者: akosiorek 项目源码 文件源码
def intersection_within(bbox, within):
    """Returns the coordinates of the intersection of `bbox` and `within`
    with respect to `within`

    :param bbox:
    :param within:
    :return:
    """
    x1 = tf.maximum(bbox[..., 1], within[..., 1])
    y1 = tf.maximum(bbox[..., 0], within[..., 0])
    x2 = tf.minimum(bbox[..., 1] + bbox[..., 3], within[..., 1] + within[..., 3])
    y2 = tf.minimum(bbox[..., 0] + bbox[..., 2], within[..., 0] + within[..., 2])
    w = x2 - x1
    w = tf.where(tf.less_equal(w, 0), tf.zeros_like(w), w)
    h = y2 - y1
    h = tf.where(tf.less_equal(h, 0), tf.zeros_like(h), h)

    y = y1 - within[..., 0]
    x = x1 - within[..., 1]

    area = h * w
    y = tf.where(tf.greater(area, 0.), y, tf.zeros_like(y))
    x = tf.where(tf.greater(area, 0.), x, tf.zeros_like(x))

    rank = len(bbox.get_shape()) - 1
    return tf.stack((y, x, h, w), rank)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号