构建bbounding box

import tensorflow as tf
from object_detection.utils import ops

image_size =[300,300,3]
anchor_number_size = [57,57]
im_width = tf.to_float(image_size[0])  # 300
im_height = tf.to_float(image_size[1])
anchor_strides = [im_width/ tf.to_float(anchor_number_size[0]), im_height/ tf.to_float(anchor_number_size[1])]
anchor_size = anchor_strides
anchor_offsets = [0.5 * anchor_strides[0], 0.5 * anchor_strides[1]]

x_centers = tf.to_float(tf.range(anchor_number_size[0]))
x_centers = x_centers * anchor_strides[0] + anchor_offsets[0]
y_centers = tf.to_float(tf.range(anchor_number_size[1]))
y_centers = y_centers * anchor_strides[1] + anchor_offsets[1]
x_centers, y_centers = ops.meshgrid(x_centers, y_centers)
widths_grid, x_centers_grid = ops.meshgrid(anchor_size[0], x_centers)
heights_grid, y_centers_grid = ops.meshgrid(anchor_size[1], y_centers)

bbox_centers = tf.stack([y_centers_grid, x_centers_grid], axis=2)
bbox_sizes = tf.stack([heights_grid, widths_grid], axis=2)
bbox_centers = tf.reshape(bbox_centers, [-1, 2])
bbox_sizes = tf.reshape(bbox_sizes, [-1, 2])
bbox_corners = tf.concat([bbox_centers - .5 * bbox_sizes, bbox_centers + .5 * bbox_sizes], 1)
# bbox_corners_re = tf.reshape(bbox_corners,[57,57,4])
with tf.Session() as sess:
    f = sess.run(bbox_centers)
    print(f)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值