在 tensorflow 中使用对象检测 api 时如何将边界框作为图像保存到磁盘 [英] How to save the bounding boxes to disk as images while using object detection api in tensorflow

查看:70
本文介绍了在 tensorflow 中使用对象检测 api 时如何将边界框作为图像保存到磁盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

与这篇文章相关 - 裁剪图像到边界Tensorflow 对象检测 API 中的框

以下是我正在尝试更改的 tensorflow 对象检测 API 示例中的代码片段

Below is snippet of code from the tensorflow object detection API sample that I am trying to change

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

Two questions/issues that I am facing 1) What would be the value of "i" should I use in the boxes if I want the first bounding box image? Is it 0 for first bounding box and 1 for second bounding box?

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

2) I am getting error on last line when trying to plot the image - 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 数组.例如:

cropped_image is a Tensor. You need to evaluate the tensor in a session to get a numpy array. E.g.:

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)

这篇关于在 tensorflow 中使用对象检测 api 时如何将边界框作为图像保存到磁盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆