reader.py 文件源码

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

项目:neural_style_tensorflow 作者: burness 项目源码 文件源码
def preprocess(image, size, max_length):
    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(width, height) if max_length else 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))
    new_size = [tf.to_int32(new_height), tf.to_int32(new_width)]
    resized_image = tf.image.resize_images(image, new_size)
    normalised_image = resized_image - mean_pixel
    return normalised_image


# max_length: Wether size dictates longest or shortest side. Default longest
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号