コード例 #1
0
ファイル: multibox.py プロジェクト: hsaputra/tvm
 def transform_loc(loc, loc_base_idx, anchor, anchor_base_idx, clip, vx, vy,
                   vw, vh):
     """Transform prior anchor box to output box through location predictions."""
     al = anchor[anchor_base_idx]
     at = anchor[anchor_base_idx + 1]
     ar = anchor[anchor_base_idx + 2]
     ab = anchor[anchor_base_idx + 3]
     aw = ar - al
     ah = ab - at
     ax = (al + ar) / 2.0
     ay = (at + ab) / 2.0
     px = loc[loc_base_idx]
     py = loc[loc_base_idx + 1]
     pw = loc[loc_base_idx + 2]
     ph = loc[loc_base_idx + 3]
     ox = px * vx * aw + ax
     oy = py * vy * ah + ay
     ow = exp(pw * vw) * aw / 2.0
     oh = exp(ph * vh) * ah / 2.0
     return (
         tvm.tir.if_then_else(clip, tvm.te.max(0.0,
                                               tvm.te.min(1.0, ox - ow)),
                              ox - ow),
         tvm.tir.if_then_else(clip, tvm.te.max(0.0,
                                               tvm.te.min(1.0, oy - oh)),
                              oy - oh),
         tvm.tir.if_then_else(clip, tvm.te.max(0.0,
                                               tvm.te.min(1.0, ox + ow)),
                              ox + ow),
         tvm.tir.if_then_else(clip, tvm.te.max(0.0,
                                               tvm.te.min(1.0, oy + oh)),
                              oy + oh),
     )
コード例 #2
0
ファイル: multibox.py プロジェクト: chisuhua/tvm-ppflow
def _hybridy_transform_loc(box, pred_loc, variance, clip):
    """Transform prior anchor box to output box through location predictions.
    """
    al = box[0]
    at = box[1]
    ar = box[2]
    ab = box[3]

    px = pred_loc[0]
    py = pred_loc[1]
    pw = pred_loc[2]
    ph = pred_loc[3]

    vx = variance[0]
    vy = variance[1]
    vw = variance[2]
    vh = variance[3]

    output = output_tensor((4, ), pred_loc.dtype)

    aw = ar - al
    ah = ab - at
    ax = (al + ar) / 2.0
    ay = (at + ab) / 2.0
    ox = px * vx * aw + ax
    oy = py * vy * ah + ay
    ow = exp(pw * vw) * aw / 2.0
    oh = exp(ph * vh) * ah / 2.0
    output[0] = max(0.0, min(1.0, ox - ow)) if clip else ox - ow
    output[1] = max(0.0, min(1.0, oy - oh)) if clip else oy - oh
    output[2] = max(0.0, min(1.0, ox + ow)) if clip else ox + ow
    output[3] = max(0.0, min(1.0, oy + oh)) if clip else oy + oh
    return output