Quick and easy function to filter out results based on the saved detection scores for each proposed object.
| Parameters: |
-
pred
(ndarray)
–
name of the segmentation output data - assumed to be output of this software
-
thresh
(int, default:
0
)
–
Threshold for filtering low scores; between 0 and 1. Defaults to 0.
-
save
(bool, default:
False
)
–
Set to True if image is to be saved. Defaults to False.
|
Source code in MinDet/thresholding.py
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36 | def threshold_labs(pred, thresh = 0, save = False):
"""Quick and easy function to filter out results based on the saved detection scores for each proposed object.
Args:
pred (ndarray): name of the segmentation output data - assumed to be output of this software
thresh (int, optional): Threshold for filtering low scores; between 0 and 1. Defaults to 0.
save (bool, optional): Set to True if image is to be saved. Defaults to False.
Returns:
_type_: _description_
"""
#assume here the output of this software is used (the .npz file)
pred_data = np.load(pred, allow_pickle=True)
img = pred_data["img"]
scores = pred_data["scores"].item()
#find label values with score below threshold
filter_out = {k:v for k, v in scores.item() if v < thresh}
#remove those label values
for item in filter_out.keys():
img[img == item] = 0
if save == True:
plt.imsave("pred_img.png", img, dpi = 300)
else:
pass
return img
|