pytorch教程
阿迪修
天道酬勤
展开
-
Pytorch中指定GPU
第一种办法:DEVICE = "cuda:0" if torch.cuda.is_available() else "cpu"# 第二种办法:直接终端设置CUDA_VISIBLE_DEVICE=1 python my_script.py# 第三种办法:python 代码中设定import os os.environ["CUDA_VISIBLE_DEVICES"] = "2"转载:转载连接...原创 2021-03-24 15:47:56 · 398 阅读 · 0 评论 -
简单快速安装pytorch1.6,及torchvison0.7.0
1.打开你的Anacondapip install -i https://pypi.tuna.tsinghua.edu.cn/simple torch==1.6.0 torchvision==0.7.0 -f https://download.pytorch.org/whl/torch_stable.html很快就能安装完毕import torchtorch.__version__torch.cuda.is_available()参考链接:参考该作者的安装办法,都一样...原创 2021-03-16 15:56:22 · 3142 阅读 · 0 评论 -
RuntimeError: The size of tensor a (4) must match the size of tensor b (3)
RuntimeError: The size of tensor a (4) must match the size of tensor b (3) at non-singleton dimension 0读取格式不对改正方法image = Image.open(image_path).convert('RGB')需要转RGB模式```真的是救命的改正方法,租后死马当活马医的时候采用了这个办法,就成功的从三张拼接的图片分别去读取出来了。读取两张的拼接图片很简单实现。...原创 2021-03-16 10:06:21 · 8298 阅读 · 3 评论 -
zip函数
>>> a = [1,2,3]>>> b = [4,5,6]>>> c = [4,5,6,7,8]>>> zipped = zip(a,b) # 打包为元组的列表[(1, 4), (2, 5), (3, 6)]>>> zip(a,c) # 元素个数与最短的列表一致[(1, 4), (2, 5), (3, 6)]>>> zip(*zipped)原创 2021-01-24 22:42:53 · 71 阅读 · 0 评论 -
查看tensorboardX的过程
第一步训练完毕:有log出现:第二步:确认路径:C:\Users***>cd C:\Users\程晓辉\余老师–pytorch\data\chap4C:\Users***\余老师–pytorch\data\chap4>tensorboard --logdir “log”2020-12-18 09:59:50.954838: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully ope原创 2020-12-18 10:08:59 · 1323 阅读 · 0 评论 -
pytorch各个版本的whl文件下载地址
备忘:pytorch各个版本的whl文件下载地址https://download.pytorch.org/whl/torch_stable.html原创 2020-12-13 16:11:23 · 2984 阅读 · 0 评论 -
读取图像的六种方式
```python在这里插入代码片#图像读取方式1# import cv2# img_cv=cv2.imread(r"C:\Users\Administrator\Desktop\cxh-photos\demo3.jpg")# print("imgh_cv:",img_cv.shape)#图像读取方式2# from PIL import Image# import numpy as np# img_PIL=Image.open(r"C:\Users\Administrator\Desk.原创 2020-11-06 17:50:55 · 2203 阅读 · 1 评论 -
pytorch入门(3)张量操作以及线性回归
总结:torch.cat()不扩张张量的维度功能:将张量按维度dim进行拼接·tensors:张量序列·dim:要拼接的维度torch.chunk()将张量按维度dim进行平均切分。torch.split()将张量按照维度dim=?进行切分。torch.index_select()在维度dim上,按照index索引数据(在维度上,按照index索引数据返回值;依index索引数据的拼接的张量)torch.masked_select() 按照mask中的True进行索引(按照mask中的Tru原创 2020-05-23 22:56:51 · 141 阅读 · 0 评论 -
pytorch入门(2)torch.stack(特别绕的维度)
torch.stack总结:先看有几个t,两个t那么在拓展维度上(dim=0,1,2)的数字变成2。三个t那么(dim=0,1,2)的数字变成3。flag = True# flag = Falseif flag: t = torch.ones((2, 3)) t_stack = torch.stack([t, t], dim=0) print("\nt_stack:{} shape:{}".format(t_stack, t_stack.shape))'''第0维,就是原创 2020-05-23 17:12:29 · 574 阅读 · 0 评论 -
pytorch入门(1)的张量tensor创建
tensor张量创建的一个数组。张量用来存放图片0-255的数值。图像处理其实就是处理数字,利用卷积神经网络。1)torch.tensor():torch. tensor(data, dtype=None, device=None, requires_grad=False, pin_memory=False)功能:从data创建tensor·data:数据,可以是list,numpy·dtype:数据类型,默认与data的一致·device:所在设备,cuda/cpu·requires_原创 2020-05-23 16:13:47 · 1082 阅读 · 0 评论