image.py 文件源码

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

项目:tensorflow-cyclegan 作者: rickbarraza 项目源码 文件源码
def preprocess(self, image):
        if self.mods and self.mods['random_flip']:
            image = tf.image.random_flip_left_right(image)
        if self.mods and self.mods['random_saturation']:
            image = tf.image.random_saturation(image, .95, 1.05)
        if self.mods and self.mods['random_brightness']:
            image = tf.image.random_brightness(image, .05)
        if self.mods and self.mods['random_contrast']:
            image = tf.image.random_contrast(image, .95, 1.05)

        if self.mods and self.mods['crop_size'] > 0:
            crop_size = self.mods['crop_size']
            wiggle = 8
            off_x, off_y = 25 - wiggle, 60 - wiggle
            crop_size_plus = crop_size + 2 * wiggle
            image = tf.image.resize_image_with_crop_or_pad(image, off_y + crop_size_plus, off_x + crop_size_plus)
            image = tf.image.crop_to_bounding_box(image, off_y, off_x, crop_size_plus, crop_size_plus)
            image = tf.random_crop(image, [crop_size, crop_size, 3])

        image = tf.image.resize_images(image, size=(self.image_size, self.image_size))
        image = tf.image.convert_image_dtype(image, dtype=tf.float32)
        image = (image / 127.5) - 1.
        image.set_shape([self.image_size, self.image_size, 3])
        return image
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号