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)
构建bbounding box
最新推荐文章于 2024-06-20 17:00:29 发布