sketch_data_handler.py 文件源码

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

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

      # Select cropping range between (target_size/2 ~ original_size)
      original_h, original_w = image.shape
      #crop_width = np.random.randint(self.target_size/3, min(self.target_size, original_w))
      #crop_height = np.random.randint(self.target_size/3, min(self.target_size, original_h))
      crop_width = self.target_size
      crop_height = self.target_size
      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])
      output = cropped_img

      output = (output - 128.0) / 128.0
      return output
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号