在 tensorflow 中使用对象检测 api 时如何将边界框作为图像保存到磁盘

How to save the bounding boxes to disk as images while using object detection api in tensorflow

与此相关 post -

下面是我试图更改的 tensorflow 对象检测 API 示例中的代码片段

我面对的两个questions/issues 1) 如果我想要第一个边界框图像,我应该在框中使用 "i" 的值是多少?是否第一个边界框为 0,第二个边界框为 1?

2) 我在尝试绘制图像时在最后一行出现错误 - plt.imshow "TypeError: Image data can not convert to float"

  ymin = boxes[0,0,0]
  xmin = boxes[0,0,1]
  ymax = boxes[0,0,2]
  xmax = boxes[0,0,3]
  (im_width, im_height) = image.size
  (xminn, xmaxx, yminn, ymaxx) = (xmin * im_width, xmax * im_width, ymin * im_height, ymax * im_height)
  cropped_image = tf.image.crop_to_bounding_box(image_np, int(yminn), int(xminn),int(ymaxx - yminn), int(xmaxx - xminn))
  plt.figure(figsize=IMAGE_SIZE)
  plt.imshow(cropped_image)

cropped_image 是张量。您需要在会话中评估张量以获得 numpy 数组。例如:

import tensorflow as tf

# <insert the rest of your graph building code before here>
cropped_image = ...
sess = tf.Session()
img_data = sess.run(cropped_image)
sess.close()

plt.figure(figsize=IMAGE_SIZE)
plt.imshow(img_data)