Skip to content

Commit

Permalink
fix ci
Browse files Browse the repository at this point in the history
  • Loading branch information
nemonameless committed May 11, 2021
1 parent 4049b0c commit 3855679
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 5 deletions.
3 changes: 0 additions & 3 deletions ppdet/data/source/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,18 +139,15 @@ class ImageFolder(DetDataset):
def __init__(self,
dataset_dir=None,
image_dir=None,
anno_path=None,
sample_num=-1,
use_default_label=None,
keep_ori_im=False,
**kwargs):
super(ImageFolder, self).__init__(
dataset_dir,
image_dir,
anno_path,
sample_num=sample_num,
use_default_label=use_default_label)
self.sample_num = sample_num
self.keep_ori_im = keep_ori_im
self._imid2path = {}
self.roidbs = None
Expand Down
6 changes: 5 additions & 1 deletion ppdet/data/source/mot.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,11 @@ def parse_dataset(self):
if len(self.img_files[data_name]) == 0:
continue
else:
data_dir = self.img_files[data_name][0].split('/')[0]
# self.img_files[data_name] each line following this:
# {self.dataset_dir}/MOT17/images/..
first_path = self.img_files[data_name][0]
data_dir = first_path.replace(self.dataset_dir,
'').split('/')[1]
data_dir = os.path.join(self.dataset_dir, data_dir)
assert os.path.exists(data_dir), \
"The data directory {} does not exist.".format(data_dir)
Expand Down
2 changes: 1 addition & 1 deletion ppdet/data/transform/mot_operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import copy
import numpy as np

from .operators import BaseOperator
from .operators import BaseOperator, register_op
from ppdet.modeling.bbox_utils import bbox_iou_np_expand
from ppdet.core.workspace import serializable
from ppdet.utils.logger import setup_logger
Expand Down
49 changes: 49 additions & 0 deletions ppdet/modeling/bbox_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,3 +570,52 @@ def pd_rbox2poly(rrects):
polys[:, 5] += y_ctr
polys[:, 7] += y_ctr
return polys


def bbox_iou_np_expand(box1, box2, x1y1x2y2=True, eps=1e-16):
"""
Calculate the iou of box1 and box2 with numpy.
Args:
box1 (ndarray): [N, 4]
box2 (ndarray): [M, 4], usually N != M
x1y1x2y2 (bool): whether in x1y1x2y2 stype, default True
eps (float): epsilon to avoid divide by zero
Return:
iou (ndarray): iou of box1 and box2, [N, M]
"""
N, M = len(box1), len(box2) # usually N != M
if x1y1x2y2:
b1_x1, b1_y1 = box1[:, 0], box1[:, 1]
b1_x2, b1_y2 = box1[:, 2], box1[:, 3]
b2_x1, b2_y1 = box2[:, 0], box2[:, 1]
b2_x2, b2_y2 = box2[:, 2], box2[:, 3]
else:
# cxcywh style
# Transform from center and width to exact coordinates
b1_x1, b1_x2 = box1[:, 0] - box1[:, 2] / 2, box1[:, 0] + box1[:, 2] / 2
b1_y1, b1_y2 = box1[:, 1] - box1[:, 3] / 2, box1[:, 1] + box1[:, 3] / 2
b2_x1, b2_x2 = box2[:, 0] - box2[:, 2] / 2, box2[:, 0] + box2[:, 2] / 2
b2_y1, b2_y2 = box2[:, 1] - box2[:, 3] / 2, box2[:, 1] + box2[:, 3] / 2

# get the coordinates of the intersection rectangle
inter_rect_x1 = np.zeros((N, M), dtype=np.float32)
inter_rect_y1 = np.zeros((N, M), dtype=np.float32)
inter_rect_x2 = np.zeros((N, M), dtype=np.float32)
inter_rect_y2 = np.zeros((N, M), dtype=np.float32)
for i in range(len(box2)):
inter_rect_x1[:, i] = np.maximum(b1_x1, b2_x1[i])
inter_rect_y1[:, i] = np.maximum(b1_y1, b2_y1[i])
inter_rect_x2[:, i] = np.minimum(b1_x2, b2_x2[i])
inter_rect_y2[:, i] = np.minimum(b1_y2, b2_y2[i])
# Intersection area
inter_area = np.maximum(inter_rect_x2 - inter_rect_x1, 0) * np.maximum(
inter_rect_y2 - inter_rect_y1, 0)
# Union Area
b1_area = np.repeat(
((b1_x2 - b1_x1) * (b1_y2 - b1_y1)).reshape(-1, 1), M, axis=-1)
b2_area = np.repeat(
((b2_x2 - b2_x1) * (b2_y2 - b2_y1)).reshape(1, -1), N, axis=0)

ious = inter_area / (b1_area + b2_area - inter_area + eps)
return ious

0 comments on commit 3855679

Please sign in to comment.