首页 PaddleGAN 帖子详情
数据增强之一的随机填充模块,填充之后物体消失了
收藏
快速回复
PaddleGAN 问答超分辨率 933 9
数据增强之一的随机填充模块,填充之后物体消失了
收藏
快速回复
PaddleGAN 问答超分辨率 933 9

数据增强之一的随机填充模块,填充之后物体消失了,只能看到彩色的小点点,这是为什么?有什么解决办法吗?

img :原图是彩色图(array[[[ ]]])

out_img: out_img的大小>=img的大小,就是把img随机的放到out_img

 out_img = np.zeros(('指定的高度', '指定的宽度', 3))

 out_img[off_y:off_y + h, off_x:off_x + w, :]  =  img

(off:y:off_y+h,off_x:off_x+w)这个元组   应该是右下角,指定结束的位置

 

 

0
收藏
回复
全部评论(9)
时间顺序
AIStudio810258
#2 回复于2020-03

随机填充是你自己写的模块还是第三方库?

0
回复
AIStudio810258
#3 回复于2020-03

随机填充后应该缩小原图和检测框。

0
回复
AIStudio810258
#4 回复于2020-03
# 随机填充
def random_expand(img,
                  gtboxes,
                  max_ratio=1.5,
                  fill=None,
                  keep_ratio=True,
                  thresh=0.5):
    #if random.random() > thresh:
    #    return img, gtboxes

    if max_ratio < 1.0:
        return img, gtboxes

    h, w, c = img.shape
    ratio_x = random.uniform(1, max_ratio)
    if keep_ratio:
        ratio_y = ratio_x
    else:
        ratio_y = random.uniform(1, max_ratio)
    oh = int(h * ratio_y)
    ow = int(w * ratio_x)
    off_x = random.randint(0, ow - w)
    off_y = random.randint(0, oh - h)

    out_img = np.zeros((oh, ow, c))
    if fill and len(fill) == c:
        for i in range(c):
            out_img[:, :, i] = fill[i] * 255.0

    out_img[off_y:off_y + h, off_x:off_x + w, :] = img
    gtboxes[:, 0] = ((gtboxes[:, 0] * w) + off_x) / float(ow)
    gtboxes[:, 1] = ((gtboxes[:, 1] * h) + off_y) / float(oh)
    gtboxes[:, 2] = gtboxes[:, 2] / ratio_x
    gtboxes[:, 3] = gtboxes[:, 3] / ratio_y

    return out_img.astype('uint8'), gtboxes
0
回复
bssn668
#5 回复于2020-03

# 随机填充
def random_expand(img,gtboxes,max_ratio=4.,fill=None,keep_ratio=True,thresh=0.5):
if random.random() > thresh:
return img, gtboxes

if max_ratio < 1.0:
return img, gtboxes

h, w, c = img.shape
ratio_x = random.uniform(1, max_ratio)
if keep_ratio:
ratio_y = ratio_x
else:
ratio_y = random.uniform(1, max_ratio)
oh = int(h * ratio_y)
ow = int(w * ratio_x)
off_x = random.randint(0, ow - w)
off_y = random.randint(0, oh - h)

out_img = np.zeros((oh, ow, c))
if fill and len(fill) == c:
for i in range(c):
out_img[:, :, i] = fill[i] * 255.0

out_img[off_y:off_y + h, off_x:off_x + w, :] = img
gtboxes[:, 0] = ((gtboxes[:, 0] * w) + off_x) / float(ow)
gtboxes[:, 1] = ((gtboxes[:, 1] * h) + off_y) / float(oh)
gtboxes[:, 2] = gtboxes[:, 2] / ratio_x
gtboxes[:, 3] = gtboxes[:, 3] / ratio_y

return out_img.astype('uint8'), gtboxes

0
回复
bssn668
#6 回复于2020-03

不是直接调用的第三方库。图片被随机填充到比它大(1-4)倍的图像中,物体的真实框也会随之移动,好像没有缩小原图和检测框那一步。

0
回复
bssn668
#7 回复于2020-03

好了,我在本地机器上跑一下就没有这种问题了,显示正常

0
回复
AIStudio810258
#8 回复于2020-03

加过任意角度旋转么?有没有让标注框跟随旋转的算法?

0
回复
AIStudio810258
#9 回复于2020-03
bssn668 #6
不是直接调用的第三方库。图片被随机填充到比它大(1-4)倍的图像中,物体的真实框也会随之移动,好像没有缩小原图和检测框那一步。

缩小不是必须的,图片的输入同一batch统一大小就行。

0
回复
水水水的老师
#10 回复于2020-03

加过任意角度旋转么??

0
回复
需求/bug反馈?一键提issue告诉我们
发现bug?如果您知道修复办法,欢迎提pr直接参与建设飞桨~
在@后输入用户全名并按空格结束,可艾特全站任一用户