change nms before get bboxes in maximum and add check negative score,add nms for infer-det-without-torch

pull/144/head
Ninenox 1 year ago
parent 8ce0d8bdba
commit 5d661f3f6f
  1. 6
      models/torch_utils.py
  2. 8
      models/utils.py

@ -70,13 +70,13 @@ def det_postprocess(data: Tuple[Tensor, Tensor, Tensor, Tensor]):
if nums == 0:
return bboxes.new_zeros((0, 4)), scores.new_zeros(
(0, )), labels.new_zeros((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)
# check score negative
scores[scores < 0] = 1 + scores[scores < 0]
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)
# 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