栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

Pytorch对图片下采样到1/2尺度、1/4 尺度

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Pytorch对图片下采样到1/2尺度、1/4 尺度

from PIL import Image as Image
import torchvision.transforms.functional as T
import torch.nn.functional as F
import numpy as np
from torchvision import transforms
import matplotlib.pyplot as plt


path=r'C:UsersAdministratorDesktopPytorchdownsampleimage1.jpg'

# 显示图片
unloader = transforms.ToPILImage()  # reconvert into PIL image

def imshow(tensor, title=None):
    plt.figure()
    image = tensor.cpu().clone()  # we clone the tensor to not do changes on it
    image = image.squeeze(0)      # remove the fake batch dimension
    image = unloader(image)
    plt.imshow(image)
    if title is not None:
        plt.title(title)
    plt.show()

if __name__ == '__main__':
    image = Image.open(path)
    img = T.to_tensor(image)
    print(img.shape)
    x=img.unsqueeze(0)
    print(x.shape)

    imshow(x, title='Image_1')

    # 下采样1/2
    x_2 = F.interpolate(x, scale_factor=0.5)
    print(x_2.shape)
    imshow(x_2,title="Image_1/2")

    # 下采样
    x_4=F.interpolate(x_2,scale_factor=0.5)
    print(x_4.size())
    imshow(x_4,title="Image_1/4")

torch.Size([1, 3, 1080, 1920])


 torch.Size([1, 3, 540, 960])


torch.Size([1, 3, 270, 480])

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/343975.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号