要禁止TensorFlow显示每个类的检测分数,以使边界框预测可读,可以通过以下步骤实现:
import tensorflow as tf
from object_detection.utils import visualization_utils as viz_utils
# 加载模型
model = tf.saved_model.load('path/to/saved_model')
# 加载标签映射
category_index = label_map_util.create_category_index_from_labelmap('path/to/label_map.pbtxt', use_display_name=True)
# 获取模型的签名函数
infer = model.signatures['serving_default']
# 执行推理
detections = infer(image)
# 禁用检测分数的显示
viz_utils.visualize_boxes_and_labels_on_image_array(
image,
detections['detection_boxes'][0].numpy(),
detections['detection_classes'][0].numpy().astype(int),
category_index,
use_normalized_coordinates=True,
max_boxes_to_draw=200,
min_score_thresh=0.0,
agnostic_mode=False)
# 显示预测结果
plt.imshow(image)
plt.show()
在上述代码中,我们通过加载模型和标签映射来准备进行推理。然后,我们获取模型的签名函数,并执行推理以获取检测结果。最后,我们使用visualize_boxes_and_labels_on_image_array
函数来可视化边界框和标签,并通过将min_score_thresh
参数设置为0.0来禁用检测分数的显示。
请注意,上述代码中的路径需要根据实际情况进行修改。此外,腾讯云提供了一系列与云计算相关的产品,可以根据具体需求选择适合的产品进行开发和部署。
领取专属 10元无门槛券
手把手带您无忧上云