为了账号安全,请及时绑定邮箱和手机立即绑定

增加 Pytorch 中显示的图像大小

增加 Pytorch 中显示的图像大小

陪伴而非守候 2022-06-07 17:22:33
我想使用 Pytorch 数据加载器显示一些图像及其各自的标签。然而显示的图像是非常小的网格。如何增加每个图像的宽度,使其更大。这是我使用的代码:mean_nums = [0.485, 0.456, 0.406]std_nums = [0.229, 0.224, 0.225]def imshow(inp, title=None):    """Imshow for Tensor."""    inp = inp.numpy().transpose((1, 2, 0))    mean = np.array(mean_nums)    std = np.array(std_nums)    inp = std * inp + mean    inp = np.clip(inp, 0, 1)    plt.imshow(inp)    if title is not None:        plt.title(title)    plt.pause(0.001)  # pause a bit so that plots are updated# Get a batch of training datainputs, classes = next(iter(dataloaders['trainLoader']))# Make a grid from batchout = torchvision.utils.make_grid(inputs,nrow=2)imshow(out, title=[image_datasets['train'].classes[x] for x in classes])
查看完整描述

2 回答

?
狐的传说

TA贡献1804条经验 获得超3个赞

尝试在plt.figure(figsize=[width, height])之前插入plt.imshow并选择width, height 会让您满意的。


因此,例如,imshow函数可能是:


def imshow(inp, title=None):

    """Imshow for Tensor."""

    inp = inp.numpy().transpose((1, 2, 0))

    mean = np.array(mean_nums)

    std = np.array(std_nums)

    inp = std * inp + mean

    inp = np.clip(inp, 0, 1)

    plt.figure(figsize=[20, 20])

    plt.imshow(inp)

    if title is not None:

        plt.title(title)

    plt.pause(0.001)  # pause a bit so that plots are updated


查看完整回答
反对 回复 2022-06-07
?
千万里不及你

TA贡献1784条经验 获得超9个赞

这不是关于插入plt.figure(figsize=[20, 20]),而是关于在调用之前 makegrid插入它。


plt.figure(figsize=[20, 20])

out = torchvision.utils.make_grid(inputs,nrow=2)

# ... do whatever you want after ...

plt.imshow(out)


查看完整回答
反对 回复 2022-06-07
  • 2 回答
  • 0 关注
  • 248 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号