augmentation.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:Triplet_Loss_SBIR 作者: TuBui 项目源码 文件源码
def augment(self,im):
    """
    augmentation includes: mean subtract, random crop, random mirror, random rotation
    """
    #random rotation
    if self.rot != 0:
      rot_ang = np.random.randint(self.rot[0], high = self.rot[1]+1)
      im = ndimage.rotate(im.astype(np.uint8), rot_ang, \
                          cval=255,reshape = False)

    #mean subtract and scaling
    im = np.float32(im)
    im -= self.mean
    im *= self.scale

    #random flip
    flip = np.random.choice(2)*2-1
    im = im[:, ::flip]

    #random crop
    y_offset = np.random.randint(im.shape[0] - self.outshape[0] - 8)
    x_offset = np.random.randint(im.shape[1] - self.outshape[1] - 8)
    return im[4+y_offset:4+self.outshape[0]+y_offset,
              4+x_offset:4+self.outshape[1]+x_offset]
    #return im
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号