不显示 TensorFlow 的对象检测结果的可视化
Posted
技术标签:
【中文标题】不显示 TensorFlow 的对象检测结果的可视化【英文标题】:Visualization of results from object detection with TensorFlow not displaying 【发布时间】:2021-12-20 03:21:32 【问题描述】:我正在尝试在 TensorFlow 中测试 SSD: Single Shot MultiBox Detector detection model pre-trained on the DOTA dataset。我遵循了 Google 的指南,一切正常,但有错误。
但是,在运行下面的代码后,我希望看到结果的可视化。但是什么也没发生。
with detection_graph.as_default():
with tf.compat.v1.Session(graph=detection_graph) as sess:
for image_path in TEST_IMAGE_PATHS:
image = Image.open(image_path)
# the array based representation of the image will be used later in order to prepare the
# result image with boxes and labels on it.
image_np = load_image_into_numpy_array(image)
# Expand dimensions since the model expects images to have shape: [1, None, None, 3]
image_np_expanded = np.expand_dims(image_np, axis=0)
image_tensor = detection_graph.get_tensor_by_name('image_tensor:0')
# Each box represents a part of the image where a particular object was detected.
boxes = detection_graph.get_tensor_by_name('detection_boxes:0')
# Each score represent how level of confidence for each of the objects.
# Score is shown on the result image, together with the class label.
scores = detection_graph.get_tensor_by_name('detection_scores:0')
classes = detection_graph.get_tensor_by_name('detection_classes:0')
num_detections = detection_graph.get_tensor_by_name('num_detections:0')
# Actual detection.
(boxes, scores, classes, num_detections) = sess.run(
[boxes, scores, classes, num_detections],
feed_dict=image_tensor: image_np_expanded)
# Visualization of the results of a detection.
vis_util.visualize_boxes_and_labels_on_image_array(
image_np,
np.squeeze(boxes),
np.squeeze(classes).astype(np.int32),
np.squeeze(scores),
category_index,
use_normalized_coordinates=True,
line_thickness=8)
plt.figure(figsize=IMAGE_SIZE)
plt.imshow(image_np)
会是什么?谢谢!
【问题讨论】:
【参考方案1】:您在代码末尾缺少plt.show()
,因此该图正在创建但从未显示。
【讨论】:
以上是关于不显示 TensorFlow 的对象检测结果的可视化的主要内容,如果未能解决你的问题,请参考以下文章
为啥 TensorFlow 对象检测 2.x 在训练模型时不显示 mAP
TensorFlow 自定义对象检测结果令人失望 - 为啥?
可视化不出现在Tensorflow-PyCharm IDE中