pen_data_handler.py 文件源码

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

项目:gy_mlcamp17 作者: gylee1103 项目源码 文件源码
def _random_preprocessing(self, image, size):
      # rotate image
      rand_degree = np.random.randint(0, 180)
      rand_flip = np.random.randint(0, 2)
      image = scipy.ndimage.interpolation.rotate(image, rand_degree, cval=255)
      if rand_flip == 1:
        image = np.flip(image, 1)

      # Select cropping range between (target_size/2 ~ original_size)
      original_h, original_w = image.shape
      crop_width = np.random.randint(self.target_size/2, min(self.target_size*2, original_w))
      crop_height = np.random.randint(self.target_size/2, min(self.target_size*2, original_h))
      topleft_x = np.random.randint(0, original_w - crop_width)
      topleft_y = np.random.randint(0, original_h - crop_height)
      cropped_img = image[topleft_y:topleft_y+crop_height,
          topleft_x:topleft_x+crop_width]
      output = scipy.misc.imresize(cropped_img, [self.target_size, self.target_size])
      # threshold
      output_thres = np.where(output < 150, -1.0, 1.0)

      return output_thres
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号