utils.py 文件源码

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

项目:tf-sr-zoo 作者: MLJejuCamp2017 项目源码 文件源码
def imgread(img_path, scale = 4):
    img = scipy.misc.imread(img_path)
    #img = scipy.misc.imresize(img, (128, 128))
    img = img /256.0
    h,w,c = img.shape
    new_h = pow(2, int(math.log(h, 2))+1)
    tmp1 = new_h - h 
    new_w = pow(2, int(math.log(w, 2))+1)
    tmp2 = new_w - w
    img = np.pad(img, ((0,tmp1), (0, tmp2),(0,0)), mode = 'constant')
    if scale != None:
        img = np.expand_dims(img,0)
        img = tf.convert_to_tensor(img)
        lr_w = new_w / scale
        lr_h = new_h /scale
        img = tf.cast(img, tf.float32)
        img_lr = tf.image.resize_images(img, [lr_h, lr_w])
        img_lr = tf.cast(img_lr,tf.float32)
        return img_lr, img
    return img
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号