![](https://img-blog.csdnimg.cn/20201014180756913.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
pytorch笔迹
网络通杀108
这个作者很懒,什么都没留下…
展开
-
ValueError: images is expected to be a list of 3d tensors of shape [C, H, W], torch.Size([480, 640]
原因 输入的图片张量维数不对,报错时输入张量的shape为(3,640,480),pytorch会认为有三张图片,每张图片张量的shape为(640,480),但是它要求图像格式为[C, H, W](3,640,480),故报错 实际上我们想要表达的是一张图片,图片shape为(3,640,480) 所以把shape变成(1,3,640,480)就好了 x = x.reshape([1, x.shape[0], x.shape[1], x.shape[2]]) 加这样一句话就行,x为输入的张量。 ...原创 2021-09-20 17:43:15 · 1245 阅读 · 0 评论 -
Pytorch使用GPU
pytorch默认是不适用gpu的,即使我们已经安装好了支持的cuda版本和cudnn,所以要使用gpu需要在程序里面设置一下。 步骤 import torch use_gpu = torch.cuda.is_available() 定义一个检查GPU是否可用的全局变量 加载模型、并设置模式: #下载预训练模型 model = torchvision.models.segmentation.deeplabv3_mobilenet_v3_large( pretrained=T原创 2021-09-20 17:16:22 · 13366 阅读 · 0 评论