mobilenetdet.py 文件源码

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

项目:MobileNet 作者: Zehaos 项目源码 文件源码
def set_anchors(img_shape, fea_shape):
  """Set anchors.

  Args:
    img_shape: 1-D list with shape `[2]`.
    fea_shape: 1-D list with shape `[2]`.

  Returns:
    anchors: 4-D tensor with shape `[fea_h, fea_w, num_anchors, 4]`

  """
  H = fea_shape[0]
  W = fea_shape[1]
  B = config.NUM_ANCHORS

  anchor_shape = tf.constant(config.ANCHOR_SHAPE, dtype=tf.float32)
  anchor_shapes = tf.reshape(
    tf.concat(
      [anchor_shape for i in range(W * H)],
      0
    ),
    [H, W, B, 2]
  )

  center_x = tf.truediv(
    tf.range(1, W + 1, 1, dtype=tf.float32),  # * img_w,
    float(W + 1)
  )
  center_x = tf.concat(
    [center_x for i in range(H * B)], 0
  )
  center_x = tf.reshape(center_x, [B, H, W])
  center_x = tf.transpose(center_x, (1, 2, 0))
  center_x = tf.reshape(center_x, [H, W, B, 1])

  center_y = tf.truediv(
    tf.range(1, H + 1, 1, dtype=tf.float32),  # * img_h,
    float(H + 1)
  )
  center_y = tf.concat(
    [center_y for i in range(W * B)], 0
  )
  center_y = tf.reshape(center_y, [B, W, H])
  center_y = tf.transpose(center_y, (2, 1, 0))
  center_y = tf.reshape(center_y, [H, W, B, 1])

  anchors = tf.concat([center_x, center_y, anchor_shapes], 3)

  return anchors
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号