forked from mindspore-Ecosystem/mindspore
!3937 Change comment and nms in yolov3-darknet53.
Merge pull request !3937 from yangyongjie/master
This commit is contained in:
commit
691ee5f19c
|
@ -90,35 +90,35 @@ class DetectionEngine:
|
||||||
for i in keep_index]
|
for i in keep_index]
|
||||||
self.det_boxes.extend(keep_box)
|
self.det_boxes.extend(keep_box)
|
||||||
|
|
||||||
def _nms(self, dets, thresh):
|
def _nms(self, predicts, threshold):
|
||||||
"""Calculate NMS."""
|
"""Calculate NMS."""
|
||||||
# conver xywh -> xmin ymin xmax ymax
|
# conver xywh -> xmin ymin xmax ymax
|
||||||
x1 = dets[:, 0]
|
x1 = predicts[:, 0]
|
||||||
y1 = dets[:, 1]
|
y1 = predicts[:, 1]
|
||||||
x2 = x1 + dets[:, 2]
|
x2 = x1 + predicts[:, 2]
|
||||||
y2 = y1 + dets[:, 3]
|
y2 = y1 + predicts[:, 3]
|
||||||
scores = dets[:, 4]
|
scores = predicts[:, 4]
|
||||||
|
|
||||||
areas = (x2 - x1 + 1) * (y2 - y1 + 1)
|
areas = (x2 - x1 + 1) * (y2 - y1 + 1)
|
||||||
order = scores.argsort()[::-1]
|
order = scores.argsort()[::-1]
|
||||||
|
|
||||||
keep = []
|
reserved_boxes = []
|
||||||
while order.size > 0:
|
while order.size > 0:
|
||||||
i = order[0]
|
i = order[0]
|
||||||
keep.append(i)
|
reserved_boxes.append(i)
|
||||||
xx1 = np.maximum(x1[i], x1[order[1:]])
|
max_x1 = np.maximum(x1[i], x1[order[1:]])
|
||||||
yy1 = np.maximum(y1[i], y1[order[1:]])
|
max_y1 = np.maximum(y1[i], y1[order[1:]])
|
||||||
xx2 = np.minimum(x2[i], x2[order[1:]])
|
min_x2 = np.minimum(x2[i], x2[order[1:]])
|
||||||
yy2 = np.minimum(y2[i], y2[order[1:]])
|
min_y2 = np.minimum(y2[i], y2[order[1:]])
|
||||||
|
|
||||||
w = np.maximum(0.0, xx2 - xx1 + 1)
|
intersect_w = np.maximum(0.0, min_x2 - max_x1 + 1)
|
||||||
h = np.maximum(0.0, yy2 - yy1 + 1)
|
intersect_h = np.maximum(0.0, min_y2 - max_y1 + 1)
|
||||||
inter = w * h
|
intersect_area = intersect_w * intersect_h
|
||||||
ovr = inter / (areas[i] + areas[order[1:]] - inter)
|
ovr = intersect_area / (areas[i] + areas[order[1:]] - intersect_area)
|
||||||
|
|
||||||
inds = np.where(ovr <= thresh)[0]
|
indexs = np.where(ovr <= threshold)[0]
|
||||||
order = order[inds + 1]
|
order = order[indexs + 1]
|
||||||
return keep
|
return reserved_boxes
|
||||||
|
|
||||||
def write_result(self):
|
def write_result(self):
|
||||||
"""Save result to file."""
|
"""Save result to file."""
|
||||||
|
|
|
@ -73,42 +73,35 @@ def statistic_normalize_img(img, statistic_norm):
|
||||||
|
|
||||||
|
|
||||||
def get_interp_method(interp, sizes=()):
|
def get_interp_method(interp, sizes=()):
|
||||||
"""Get the interpolation method for resize functions.
|
"""
|
||||||
|
Get the interpolation method for resize functions.
|
||||||
The major purpose of this function is to wrap a random interp method selection
|
The major purpose of this function is to wrap a random interp method selection
|
||||||
and a auto-estimation method.
|
and a auto-estimation method.
|
||||||
|
|
||||||
Parameters
|
Note:
|
||||||
----------
|
|
||||||
interp : int
|
|
||||||
interpolation method for all resizing operations
|
|
||||||
|
|
||||||
Possible values:
|
|
||||||
0: Nearest Neighbors Interpolation.
|
|
||||||
1: Bilinear interpolation.
|
|
||||||
2: Bicubic interpolation over 4x4 pixel neighborhood.
|
|
||||||
3: Nearest Neighbors. [Originally it should be Area-based,
|
|
||||||
as we cannot find Area-based, so we use NN instead.
|
|
||||||
Area-based (resampling using pixel area relation). It may be a
|
|
||||||
preferred method for image decimation, as it gives moire-free
|
|
||||||
results. But when the image is zoomed, it is similar to the Nearest
|
|
||||||
Neighbors method. (used by default).
|
|
||||||
4: Lanczos interpolation over 8x8 pixel neighborhood.
|
|
||||||
9: Cubic for enlarge, area for shrink, bilinear for others
|
|
||||||
10: Random select from interpolation method metioned above.
|
|
||||||
Note:
|
|
||||||
When shrinking an image, it will generally look best with AREA-based
|
When shrinking an image, it will generally look best with AREA-based
|
||||||
interpolation, whereas, when enlarging an image, it will generally look best
|
interpolation, whereas, when enlarging an image, it will generally look best
|
||||||
with Bicubic (slow) or Bilinear (faster but still looks OK).
|
with Bicubic or Bilinear.
|
||||||
More details can be found in the documentation of OpenCV, please refer to
|
|
||||||
http://docs.opencv.org/master/da/d54/group__imgproc__transform.html.
|
|
||||||
sizes : tuple of int
|
|
||||||
(old_height, old_width, new_height, new_width), if None provided, auto(9)
|
|
||||||
will return Area(2) anyway.
|
|
||||||
|
|
||||||
Returns
|
Args:
|
||||||
-------
|
interp (int): Interpolation method for all resizing operations.
|
||||||
int
|
|
||||||
interp method from 0 to 4
|
- 0: Nearest Neighbors Interpolation.
|
||||||
|
- 1: Bilinear interpolation.
|
||||||
|
- 2: Bicubic interpolation over 4x4 pixel neighborhood.
|
||||||
|
- 3: Nearest Neighbors. Originally it should be Area-based, as we cannot find Area-based,
|
||||||
|
so we use NN instead. Area-based (resampling using pixel area relation).
|
||||||
|
It may be a preferred method for image decimation, as it gives moire-free results.
|
||||||
|
But when the image is zoomed, it is similar to the Nearest Neighbors method. (used by default).
|
||||||
|
- 4: Lanczos interpolation over 8x8 pixel neighborhood.
|
||||||
|
- 9: Cubic for enlarge, area for shrink, bilinear for others.
|
||||||
|
- 10: Random select from interpolation method mentioned above.
|
||||||
|
|
||||||
|
sizes (tuple): Format should like (old_height, old_width, new_height, new_width),
|
||||||
|
if None provided, auto(9) will return Area(2) anyway. Default: ()
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
int, interp method from 0 to 4.
|
||||||
"""
|
"""
|
||||||
if interp == 9:
|
if interp == 9:
|
||||||
if sizes:
|
if sizes:
|
||||||
|
|
Loading…
Reference in New Issue