未验证 提交 67e0d761 编写于 作者: W wangguanzhong 提交者: GitHub

fix gridmask (#2694)

上级 ecc33160
...@@ -45,8 +45,7 @@ class Gridmask(object): ...@@ -45,8 +45,7 @@ class Gridmask(object):
self.prob = self.st_prob * min(1, 1.0 * curr_iter / self.upper_iter) self.prob = self.st_prob * min(1, 1.0 * curr_iter / self.upper_iter)
if np.random.rand() > self.prob: if np.random.rand() > self.prob:
return x return x
# image should be C, H, W format h, w, _ = x.shape
_, h, w = x.shape
hh = int(1.5 * h) hh = int(1.5 * h)
ww = int(1.5 * w) ww = int(1.5 * w)
d = np.random.randint(2, h) d = np.random.randint(2, h)
...@@ -74,7 +73,7 @@ class Gridmask(object): ...@@ -74,7 +73,7 @@ class Gridmask(object):
if self.mode == 1: if self.mode == 1:
mask = 1 - mask mask = 1 - mask
mask = np.expand_dims(mask, axis=0) mask = np.expand_dims(mask, axis=-1)
if self.offset: if self.offset:
offset = (2 * (np.random.rand(h, w) - 0.5)).astype(np.float32) offset = (2 * (np.random.rand(h, w) - 0.5)).astype(np.float32)
x = (x * mask + offset * (1 - mask)).astype(x.dtype) x = (x * mask + offset * (1 - mask)).astype(x.dtype)
......
...@@ -46,7 +46,7 @@ class GridMask(object): ...@@ -46,7 +46,7 @@ class GridMask(object):
if np.random.rand() > self.prob: if np.random.rand() > self.prob:
return x return x
# image should be C, H, W format # image should be C, H, W format
_, h, w = x.shape h, w, _ = x.shape
hh = int(1.5 * h) hh = int(1.5 * h)
ww = int(1.5 * w) ww = int(1.5 * w)
d = np.random.randint(2, h) d = np.random.randint(2, h)
...@@ -74,7 +74,7 @@ class GridMask(object): ...@@ -74,7 +74,7 @@ class GridMask(object):
if self.mode == 1: if self.mode == 1:
mask = 1 - mask mask = 1 - mask
mask = np.expand_dims(mask, axis=0) mask = np.expand_dims(mask, axis=-1)
if self.offset: if self.offset:
offset = (2 * (np.random.rand(h, w) - 0.5)).astype(np.float32) offset = (2 * (np.random.rand(h, w) - 0.5)).astype(np.float32)
x = (x * mask + offset * (1 - mask)).astype(x.dtype) x = (x * mask + offset * (1 - mask)).astype(x.dtype)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册