reader.py 文件源码

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

项目:prisma 作者: hijkzzz 项目源码 文件源码
def preprocess(image, size):
    shape = tf.shape(image)
    size_t = tf.constant(size, tf.float64)
    height = tf.cast(shape[0], tf.float64)
    width = tf.cast(shape[1], tf.float64)

    cond_op = tf.less(height, width)

    # ?????
    new_height, new_width = tf.cond(
        cond_op,
        lambda: (size_t, (width * size_t) / height),
        lambda: ((height * size_t) / width, size_t))

    resized_image = tf.image.resize_images(
            image,
            [tf.to_int32(new_height), tf.to_int32(new_width)],
            method=tf.image.ResizeMethod.BICUBIC)
    cropped = tf.image.resize_image_with_crop_or_pad(resized_image, size, size)

    return cropped
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号