Skip to content

Commit

Permalink
fix parse_dataset register_op
Browse files Browse the repository at this point in the history
  • Loading branch information
nemonameless committed May 10, 2021
1 parent e9ae23d commit 1cce13e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 25 deletions.
27 changes: 14 additions & 13 deletions ppdet/data/source/mot.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class MOTDataSet(DetDataset):
label_list (str): if use_default_label is False, will load
mapping between category and class index.
Notes:
MOT datasets root following this:
MOT datasets root directory following this:
dataset/mot
|——————image_lists
| |——————caltech.train
Expand Down Expand Up @@ -81,25 +81,34 @@ def __init__(self,
dataset_dir=dataset_dir,
data_fields=data_fields,
sample_num=sample_num)
self.dataset_dir = dataset_dir
self.image_lists = image_lists
self.label_list = label_list
if isinstance(self.image_lists, str):
self.image_lists = [self.image_lists]

def get_anno(self):
if self.image_lists == []:
return
# only used to get categories and metric
return os.path.join(self.dataset_dir, 'image_lists',
self.image_lists[0])

def parse_dataset(self):
self.img_files = OrderedDict()
self.img_start_index = OrderedDict()
self.label_files = OrderedDict()
self.tid_num = OrderedDict()
self.tid_start_index = OrderedDict()

if isinstance(self.image_lists, str):
self.image_lists = [self.image_lists]
img_index = 0
for data_name in self.image_lists:
with open(
os.path.join(dataset_dir, 'image_lists', data_name),
os.path.join(self.dataset_dir, 'image_lists', data_name),
'r') as file:
self.img_files[data_name] = file.readlines()
self.img_files[data_name] = [
os.path.join(dataset_dir, x.strip())
os.path.join(self.dataset_dir, x.strip())
for x in self.img_files[data_name]
]
self.img_files[data_name] = list(
Expand Down Expand Up @@ -146,14 +155,6 @@ def __init__(self,
logger.info('identity start index: {}'.format(self.tid_start_index))
logger.info('=' * 80)

def get_anno(self):
if self.image_lists == []:
return
# only used to get categories and metric
return os.path.join(self.dataset_dir, 'image_lists',
self.image_lists[0])

def parse_dataset(self):
# mapping category name to class id
# first_class:0, second_class:1, ...
records = []
Expand Down
20 changes: 8 additions & 12 deletions ppdet/data/transform/mot_operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,7 @@
__all__ = ['LetterBoxResize', 'Gt2JDETargetThres', 'Gt2JDETargetMax']


def register_mot_op(cls):
return serializable(cls)


@register_mot_op
@register_op
class LetterBoxResize(BaseOperator):
def __init__(self, target_size):
"""
Expand All @@ -65,17 +61,17 @@ def apply_image(self, img, height, width, color=(127.5, 127.5, 127.5)):
ratio = min(ratio_h, ratio_w)
new_shape = (round(shape[1] * ratio),
round(shape[0] * ratio)) # [width, height]
dw = (width - new_shape[0]) / 2 # width padding
dh = (height - new_shape[1]) / 2 # height padding
top, bottom = round(dh - 0.1), round(dh + 0.1)
left, right = round(dw - 0.1), round(dw + 0.1)
padw = (width - new_shape[0]) / 2
padh = (height - new_shape[1]) / 2
top, bottom = round(padh - 0.1), round(padh + 0.1)
left, right = round(padw - 0.1), round(padw + 0.1)

img = cv2.resize(
img, new_shape, interpolation=cv2.INTER_AREA) # resized, no border
img = cv2.copyMakeBorder(
img, top, bottom, left, right, cv2.BORDER_CONSTANT,
value=color) # padded rectangular
return img, ratio, dw, dh, ratio_h, ratio_w
return img, ratio, padw, padh, ratio_h, ratio_w

def apply_bbox(self, bbox0, h, w, ratio, padw, padh):
bboxes = bbox0.copy()
Expand Down Expand Up @@ -112,7 +108,7 @@ def apply(self, sample, context=None):
return sample


@register_mot_op
@register_op
class Gt2JDETargetThres(BaseOperator):
__shared__ = ['num_classes']
"""
Expand Down Expand Up @@ -274,7 +270,7 @@ def __call__(self, samples, context=None):
return samples


@register_mot_op
@register_op
class Gt2JDETargetMax(BaseOperator):
__shared__ = ['num_classes']
"""
Expand Down

0 comments on commit 1cce13e

Please sign in to comment.