[英]Metric for evaluating predicted bounding boxes from semantic segmentation on an object level outside of training
[英]Semantic Segmentation to Bounding Boxes
假設您正在執行語義分割。 為簡單起見,讓我們假設這是1D分割而不是2D(即,我們只關心查找具有寬度的對象)。
因此,我們模型的期望輸出可能是這樣的:
[
[0, 0, 0, 0, 1, 1, 1], # label channel 1
[1, 1, 1, 0, 0, 1, 1], # label channel 2
[0, 0, 0, 1, 1, 1, 0], # label channel 3
#...
]
但是,我們訓練有素的不完美模型可能更像
[
[0.1, 0.1, 0.1, 0.4, 0.91, 0.81, 0.84], # label channel 1
[0.81, 0.79, 0.85, 0.1, 0.2, 0.61, 0.91], # label channel 2
[0.3, 0.1, 0.24, 0.87, 0.62, 1, 0 ], # label channel 3
#...
]
使用python獲取標簽(或邊界框)邊界的有效方式是什么
例如(零索引)
[
[[4, 6]], # "objects" of label 1
[[0, 2], [5, 6]] # "objects" of label 2
[[3, 5]], # "objects" of label 3
]
如果有幫助,也許將其轉換為二進制掩碼會更有用?
def binarize(arr, cutoff=0.5):
return (arr > cutoff).astype(int)
使用二進制掩碼,我們只需要查找非零值索引的連續整數:
def連續(數據,步驟大小= 1):返回np.split(數據,np.where(np.diff(數據)!=步驟大小)[0] +1)
找到標簽“運行”:
def binary_boundaries(labels, cutoff=0.5):
return [consecutive(channel.nonzero()[0]) for channel in binarize(labels, cutoff)]
根據頻道名稱命名對象:
def binary_objects(labels, cutoff=0.5, channel_names=None):
if channel_names == None:
channel_names = ['channel {}'.format(i) for i in range(labels.shape[0])]
return dict(zip(channel_names, binary_boundaries(labels, cutoff)))
您訓練有素的模型返回的是float image
而不是您要查找的int image
(如果小數困擾您,它不是“不完美”),是的! 您確實需要對其進行threshold
處理以獲得binary image
。
一旦有了二進制映像,就讓skimage
做一些工作。
label_mask = measure.label(mask)
props = measure.regionprops(label_mask)
面具是你的二值圖像,在這里你有props
所有被檢測的對象實際上是區域的屬性。
在這些屬性中,存在邊界框!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.