Pay Attention to the Constraint Cue
zgs731 opened this issue · 1 comments
zgs731 commented
你好
How to Train Your Robust Human Pose Estimator:Pay Attention to the Constraint Cue
请问这篇文章的实现代码,在什么地方?
文章中,遮挡中心的偏移量δ,怎么随机的?有范围限制吗?
每次都会选择一个关键点做增强吗?这个有没有随机概率?
HuangJunJie2017 commented
@zgs731 paper has been updated https://arxiv.org/abs/2008.07139 ,and here is the source code which have not been public available and can be use in mmpose project, we will make it public available in mmpose recently. Thanks for your attention~
@PIPELINES.register_module()
class AID:
"""AID: Augmentation by Informantion Dropping.
Args:
transforms (List): ToTensor & Normalize
prob_cutout (Float): Probability of performing cutout.
radius_factor (Float): Size factor of cutout area.
num_patch (Float): Number of patches to be cutout.
prob_has (Float): Probability of performing hide-and-seek.
prob_has_hideprob (Float): Probability of dropping patches.
"""
def __init__(self, prob_cutout=0.0, radius_factor=0.2, num_patch=1,
prob_has=1.0, prob_has_hideprob=0.5):
self.prob_cutout = prob_cutout
self.radius_factor = radius_factor
self.num_patch = num_patch
self.prob_has = prob_has
self.prob_has_hideprob = prob_has_hideprob
def hide_and_seek(self, img):
# get width and height of the image
ht, wd, _ = img.shape
# possible grid size, 0 means no hiding
grid_sizes = [0, 16, 32, 44, 56]
# randomly choose one grid size
grid_size = grid_sizes[np.random.randint(0, len(grid_sizes) - 1)]
# hide the patches
if grid_size != 0:
for x in range(0, wd, grid_size):
for y in range(0, ht, grid_size):
x_end = min(wd, x + grid_size)
y_end = min(ht, y + grid_size)
if np.random.rand() <= self.prob_has_hideprob:
img[x:x_end, y:y_end, :] = 0
return img
def cutout(self, img):
height, width, _ = img.shape
img = img.reshape((height * width, -1))
feat_x_int = np.arange(0, width)
feat_y_int = np.arange(0, height)
feat_x_int, feat_y_int = np.meshgrid(feat_x_int, feat_y_int)
feat_x_int = feat_x_int.reshape((-1,))
feat_y_int = feat_y_int.reshape((-1,))
for _ in range(self.num_patch):
center = [np.random.rand() * width, np.random.rand() * height]
radius = self.radius_factor * (1 + np.random.rand(2)) * width
x_offset = (center[0] - feat_x_int) / radius[0]
y_offset = (center[1] - feat_y_int) / radius[1]
dis = x_offset ** 2 + y_offset ** 2
keep_pos = np.where((dis <= 1) & (dis >= 0))[0]
img[keep_pos, :] = 0
img = img.reshape((height, width, -1))
return img
def __call__(self, results):
img = results['img']
factor = np.random.rand()
if factor < self.prob_cutout:
img = self.cutout(img)
elif factor < (self.prob_cutout + self.prob_has):
img = self.hide_patch(img)
results['img'] = img
return results