在operators.py中按照文档新增预处理数据增强算子,无法训练
Created by: AN-ZE
在operators.py新增padding算子,将图片扩展到固定尺寸中,训练不能运行,停止不动
@register_op
class PaddingImage(BaseOperator):
def __init__(self, pad=1280, mean=[127.5, 127.5, 127.5]):
super(PaddingImage, self).__init__()
self.pad = pad
self.mean = mean
def __call__(self, sample, context):
assert 'image' in sample, 'not found image data'
im = sample['image']
gt_bbox = sample['gt_bbox']
gt_class = sample['gt_class']
im_width = sample['w']
im_height = sample['h']
if self.pad >= 0:
height = int(self.pad)
width = int(self.pad)
h_off = math.floor(np.random.uniform(0, height - im_height))
w_off = math.floor(np.random.uniform(0, width - im_width))
expand_bbox = [
-w_off / im_width, -h_off / im_height,
(width - w_off) / im_width, (height - h_off) / im_height
]
expand_im = np.ones((height, width, 3))
expand_im = np.uint8(expand_im * np.squeeze(self.mean))
expand_im = Image.fromarray(expand_im)
im = Image.fromarray(im)
expand_im.paste(im, (int(w_off), int(h_off)))
expand_im = np.asarray(expand_im)
gt_bbox, gt_class, _ = filter_and_process(expand_bbox, gt_bbox,
gt_class)
sample['image'] = expand_im
sample['gt_bbox'] = gt_bbox
sample['gt_class'] = gt_class
sample['w'] = width
sample['h'] = height
return sample