Tensorflow结合的图像候选区域非最大值抑制

2024-06-25 23:13:52 发布

您现在位置:Python中文网/ 问答频道 /正文

我想在一组中运行组合非最大抑制 用于图像的窗口。 我正在使用tensorflow的tf.image.combined_non_max_抑制,如下所示:

import matplotlib.pyplot as plt
import matplotlib.patches as patches
from PIL import Image
import numpy as np
import tensorflow as tf 



boxesX=np.array(([200,100,150,100],[220,120,150,100],[190,110,150,100],[210,112,150,100])).astype('float32')
scoresX=np.array(([0.2,0.7,0.1],[0.1,0.8,0.1],[0.3,0.6,0.1],[0.05,0.9,0.05]))
boxes1=tf.reshape(boxesX,(1,4,1,4))
boxes2=tf.dtypes.cast(boxes1, tf.float32)
scores1=tf.reshape(scoresX,(1,4,3))
scores2=tf.dtypes.cast(scores1, tf.float32)

boxes, scores, classes, valid_detections = tf.image.combined_non_max_suppression(
boxes=boxes2,
scores=scores2,
max_output_size_per_class=10,
max_total_size=10,
iou_threshold=0.5,
score_threshold=0.2)

但输出“框”只是一个0和1的数组:

array([[[1., 1., 1., 1.],
    [1., 1., 1., 1.],
    [1., 1., 1., 1.],
    [0., 0., 0., 0.],
    [0., 0., 0., 0.],
    [0., 0., 0., 0.],
    [0., 0., 0., 0.],
    [0., 0., 0., 0.],
    [0., 0., 0., 0.],
    [0., 0., 0., 0.]]], dtype=float32)>

Tags: imageimportmatplotlibtftensorflowasnparray
1条回答
网友
1楼 · 发布于 2024-06-25 23:13:52

这些框被夹在[0,1]之间。您只需添加参数clip_boxes=False

boxes, scores, classes, valid_detections = tf.image.combined_non_max_suppression(
boxes=boxes2,
scores=scores2,
max_output_size_per_class=10,
max_total_size=10,
iou_threshold=0.5,
score_threshold=0.2,
clip_boxes=False)

相关问题 更多 >