Reputation: 7908
Given:
[batch_size, num_points, 2]
,[batch_size, height, width, 3]
,how can we draw the points on the image?
There is tf.image.draw_bounding_boxes
to draw bounding box on top of the image pixels but I did not find an equivalent for drawing key points.
A tensorflow-nic answer that would not require the use of pure python with tf.py_func
would be preferred.
Upvotes: 2
Views: 1459
Reputation: 198
I use boxes with zero size to draw points:
def draw_points(images, points, tf_summary_writer, step):
"""
:param images: [batch_size, height, width, 3], tf.float32, from 0 to 1
:param points: [batch_size, num_points, 2], tf.float32, from 0 to 1
:param tf_summary_writer: SummaryWriter
:param step: int
"""
with tf_summary_writer.as_default():
x_min = points[:, :, 0] # shape [bs, np]
y_min = points[:, :, 1] # shape [bs, np]
x_max = points[:, :, 0] # shape [bs, np]
y_max = points[:, :, 1] # shape [bs, np]
boxes = tf.stack([y_min, x_min, y_max, x_max], axis=-1) # shape [bs, np, 4]
image_with_points = tf.image.draw_bounding_boxes(images, boxes, colors=[[1, 0, 0, 1]]) # RGBA red color
tf.summary.image('points', image_with_points, step)
Upvotes: 1