Check and fix neg scores

Check and fix neg scores
pull/160/head
triple Mu 1 year ago committed by GitHub
commit c1c7dadaf0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      models/torch_utils.py
  2. 8
      models/utils.py

@ -64,19 +64,19 @@ def det_postprocess(data: Tuple[Tensor, Tensor, Tensor, Tensor]):
iou_thres: float = 0.65
num_dets, bboxes, scores, labels = data[0][0], data[1][0], data[2][
0], data[3][0]
# check score negative
scores[scores < 0] = 1 + scores[scores < 0]
nums = num_dets.item()
if nums == 0:
return bboxes.new_zeros((0, 4)), scores.new_zeros(
(0, )), labels.new_zeros((0, ))
# check score negative
scores[scores < 0] = 1 + scores[scores < 0]
# add nms
idx = nms(bboxes, scores, iou_thres)
bboxes, scores, labels = bboxes[idx], scores[idx], labels[idx]
bboxes = bboxes[:nums]
scores = scores[:nums]
labels = labels[:nums]
# add nms
idx = nms(bboxes, scores, iou_thres)
bboxes, scores, labels = bboxes[idx], scores[idx], labels[idx]
return bboxes, scores, labels

@ -4,6 +4,7 @@ from typing import List, Tuple, Union
import cv2
import numpy as np
from numpy import ndarray
from torchvision.ops import nms
# image suffixs
SUFFIXS = ('.bmp', '.dng', '.jpeg', '.jpg', '.mpo', '.png', '.tif', '.tiff',
@ -87,11 +88,18 @@ def crop_mask(masks: ndarray, bboxes: ndarray) -> ndarray:
def det_postprocess(data: Tuple[ndarray, ndarray, ndarray, ndarray]):
assert len(data) == 4
iou_thres: float = 0.65
num_dets, bboxes, scores, labels = (i[0] for i in data)
nums = num_dets.item()
if nums == 0:
return np.empty((0, 4), dtype=np.float32), np.empty(
(0, ), dtype=np.float32), np.empty((0, ), dtype=np.int32)
# check score negative
scores[scores < 0] = 1 + scores[scores < 0]
# add nms
idx = nms(bboxes, scores, iou_thres)
bboxes, scores, labels = bboxes[idx], scores[idx], labels[idx]
bboxes = bboxes[:nums]
scores = scores[:nums]
labels = labels[:nums]

Loading…
Cancel
Save