basic_model.py 文件源码

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

项目:sea-lion-counter 作者: rdinse 项目源码 文件源码
def preprocessExample(self, image, coords, angle, shear_x, shear_y, scale):
    '''This function is meant to be run as a tf.py_func node on a single
    example.  It returns a randomly perturbed and correctly cropped and padded
    image and generates one or multiple targets.

      image, target = tf.py_func(preprocessExample, [image, coords, class_ids],
                                 [tf.float32, tf.float32])

    Args:
      image: A single training image with value range [0, 1].

    Returns:
      A tuple containing an image and a table of coordinates.
    '''
    size_in = image.shape[0]
    size_out = self.config['tile_size'] + 2 * self.config['contextual_pad']

    # h = base64.b64encode(struct.pack(">q", hash(image.tostring()))).decode()

    # data_preparation.imshow(image, coords=coords, save=True, title='%s_preprocessExampleA' %h)

    image = self.applyLinearTransformToImage(image, angle, shear_x, shear_y, scale, size_out)
    image = self.applyColorAugmentation(image, self.config['aug_color_std'], \
                                        self.config['aug_gamma_factor'])
    coords[:, 1:] = self.applyLinearTransformToCoords(coords[:, 1:], angle, shear_x,
                                                      shear_y, scale, size_in, size_out)
    target = self.generateCountMaps(coords)

    if self.config['draw_border'] and self.config['contextual_pad'] > 0:
      image = self.draw_border(image, self.config['contextual_pad'], self.config['tile_size'])

    # data_preparation.imshow(image, coords=coords, save=True, title='%s_preprocessExampleB' % h)
    # t = np.concatenate(np.moveaxis(target, -1, 0))
    # data_preparation.imshow(t, normalize=True, save=True, title='%s_preprocessExampleC' % h)

    return image.astype(np.float32), target
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号