tensorflow - 用tensorflow 2预测前得到模型提出的区域
问题描述
我尝试使用 tensorflow 2 进行对象检测,但我不知道如何执行以下操作:
在教程 TF2 对象检测中,获取一张图像中某些元素的推断,如以下代码所示:
image_np = load_image_into_numpy_array(image_path)
input_tensor = tf.convert_to_tensor(image_np)
input_tensor = input_tensor[tf.newaxis, ...]
detections = detect_fn(input_tensor)
但我需要在类推理之前获取元素或区域。我需要访问所有建议进行更改或插入新区域的区域,然后获取每个区域的类。
我的代码如下:
def make_inference(image_path,counter,image_save):
print('Running inference for {}... '.format(image_path), end='')
image_np = load_image_into_numpy_array(image_path)
input_tensor = tf.convert_to_tensor(image_np)
input_tensor = input_tensor[tf.newaxis, ...]
detections = detect_fn(input_tensor)
num_detections = int(detections.pop('num_detections'))
detections = {key: value[0, :num_detections].numpy()
for key, value in detections.items()}
detections['num_detections'] = num_detections
detections['detection_classes'] = detections['detection_classes'].astype(np.int64)
image_np_with_detections = image_np.copy()
viz_utils.visualize_boxes_and_labels_on_image_array(
image_np_with_detections,
detections['detection_boxes'],
detections['detection_classes'],
detections['detection_scores'],
category_index,
use_normalized_coordinates=True,
max_boxes_to_draw=200,
min_score_thresh=.5,
agnostic_mode=False)
plt.axis('off')
plt.imshow(image_np_with_detections)
nombre = str(counter)+'.jpg'
plt.savefig('/content/RESULTADOS/'+nombre, dpi=dpi ,bbox_inches='tight')
counter = counter+1
plt.clf()
提前致谢。
解决方案
推荐阅读
- java - Spring boot Hibernate 一对多关系
- wpf - 如何将 WPF 框架扩展到其父宽度?
- multithreading - 阻止除一个之外的所有线程的最佳方法是什么?
- javascript - Material UI Theme - 交换原色和副色
- sql - 计算SQL中两个日期之间的月数
- scala - scala:使用while循环检查是否是素数
- javascript - 我在 PHP 回显语句中用完了引号
- javascript - 更新图表时修改chart.js中的标签
- javascript - Grouped_select,如何显示以前选择的项目和/或类别
- android - Flutter:Android启动主题和普通主题图像中的Shift