提交 6f0e14a5 编写于 作者: z37757's avatar z37757

modify Pad

上级 853ebd9c
......@@ -167,20 +167,37 @@ class KeepKeys(object):
class Pad(object):
def __init__(self, size_div=32, **kwargs):
def __init__(self, size=None, size_div=32, **kwargs):
if size is not None and not isinstance(size, (int, list, tuple)):
raise TypeError("Type of target_size is invalid. Now is {}".format(
type(size)))
if isinstance(size, int):
size = [size, size]
self.size = size
self.size_div = size_div
def __call__(self, data):
img = data['image']
resize_h2 = max(int(math.ceil(img.shape[0] / 32) * 32), 32)
resize_w2 = max(int(math.ceil(img.shape[1] / 32) * 32), 32)
img_h, img_w = img.shape[0], img.shape[1]
if self.size:
resize_h2, resize_w2 = self.size
assert (
img_h < resize_h2 and img_w < resize_w2
), '(h, w) of target size should be greater than (img_h, img_w)'
else:
resize_h2 = max(
int(math.ceil(img.shape[0] / self.size_div) * self.size_div),
self.size_div)
resize_w2 = max(
int(math.ceil(img.shape[1] / self.size_div) * self.size_div),
self.size_div)
img = cv2.copyMakeBorder(
img,
0,
resize_h2 - img.shape[0],
resize_h2 - img_h,
0,
resize_w2 - img.shape[1],
resize_w2 - img_w,
cv2.BORDER_CONSTANT,
value=0)
data['image'] = img
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册