![](https://img-blog.csdnimg.cn/20201014180756919.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
PyTorch
Kkkkaii
这个作者很懒,什么都没留下…
展开
-
RuntimeError: element 0 of tensors does not require grad and does not have a grad_fn
loss的时候出了问题导致 `loss.requires_grad=False`原创 2022-12-27 11:02:05 · 2045 阅读 · 1 评论 -
pytorch 多个 tensor 按位取与 / 按位取或
pytorch 中 `torch.logical_or` 只接受两个 input,但假如有一系列 inputs 都想按位取与该怎么做原创 2022-12-24 21:00:39 · 624 阅读 · 0 评论 -
torch.scatter中的scatter_sum能做什么事
TL;DL: 可以计算一个一个 tensor 中不同元素的数量,存成一个一维 tensor,新 tensor 中的每个元素就是 sum 出来的不同元素的数量。原创 2022-12-24 19:36:12 · 750 阅读 · 0 评论 -
fairseq train报错:fairseq-train: error: argument --user-dir: invalid Optional value: ‘./fairseq_models
明明应该有的args,fairseq好像读取不到,然后报 invalid Optional value原创 2022-09-29 14:37:06 · 962 阅读 · 5 评论 -
Pytorch如果batch size大于dataset size会发生什么
结论先给结论:**和batch size无关了。**DataLoader每次会把full size给出来,同时每个step就等于一个epoch相关ptrblck在以下这个回答中指出:DataLoader的时候设置batchsize之后他就会划分data,然后有个函数__len()__提前计算好了有多少个batch,如果1001个样本,batchsize是10,那__len__()就会返回101,同时最后一个batch将只有1个样本。https://discuss.pytorch.org/t/abo原创 2022-04-02 17:40:08 · 2583 阅读 · 0 评论 -
scipy和pytorch的sparse库有啥区别
这个问题具体是针对coo matrix这个存储方式问的sparse库首先sparse库是用来存储稀疏矩阵的,pytorch和scipy都有这么个库(好像pytorch比较高的版本才有)。sparse库最主要的就是稀疏矩阵的表示,一般使用三元组的方式存储:(行,列,值),比如scipy的 coo_matrix((data, (i, j)), [shape=(M, N)])pytorch和scipy的sparse有啥区别因为看到GNN一些代码里在处理邻接矩阵的时候会把pytorch的sparse转换成s原创 2022-03-29 23:38:33 · 1500 阅读 · 0 评论 -
fairseq 安装报错
fairseq 安装报错问题Running setup.py install for fairseq ... errorERROR: Command errored out with exit status 1:command: /Users/superman/anaconda/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/3h/3v_dnwl95tl9k9swb原创 2021-02-08 12:44:09 · 3200 阅读 · 5 评论 -
PyTorch 快速查看 pth 文件保存的参数
不需要 run 什么脚本来 load 然后 print,直接用命令行解决:(注:假设该环境下有 torch 包,该文件名 t.pth)import torch # 命令行是逐行立即执行的content = torch.load('t.pth')print(content.keys()) # keys()# 之后有其他需求比如要看 key 为 model 的内容有啥print(content['model'])进行快速检查非常方便...原创 2020-12-14 21:26:11 · 25097 阅读 · 3 评论 -
AttributeError: module ‘torch‘ has no attribute ‘vstack‘
AttributeError: module ‘torch’ has no attribute ‘vstack’感谢 Poe Dator 的解答,这里做个记录错误原因:似乎是PyTorch 1.8.0 之后才支持这个 torch.vstack解决办法:所以在这之前用 torch.cat([a,b], dim=0) 代替就行...原创 2020-11-27 16:21:50 · 2471 阅读 · 0 评论 -
PyTorch 多维 Tensor 乘法
PyTorch 多维 Tensor 乘法可太难了问题描述有俩矩阵:x: torch.Size([1, 3]) 和 y: torch.Size([3, 16, 256, 1024]),看起来是直接用某种乘法就能搞定,但是我试过 torch.mm(),torch.mul(),torch.matmul(),* 全都不行。解决办法后来才知道 torch.matmul 乘的机制很奇怪,我直接写怎么做吧:mat1 = x.float()mat2 = y.permute(2, 3, 0, 1).float(原创 2020-11-27 16:11:08 · 2083 阅读 · 0 评论 -
PyTorch Warning uint8 to bool
PyTorch Warning uint8 to bool问题报错如下:warning: indexing with dtype torch.uint8 is now deprecated, please use a dtype torch.bool instead. (function expandTensors)虽然只是warning,但是数据量一大就会导致比如 OSError: [Errno 5] Input/output error 导致Terminal 崩溃,所以还是要解决一下。解决之原创 2020-11-27 09:39:08 · 1596 阅读 · 5 评论 -
‘tuple‘ object has no attribute ‘log_softmax‘
'tuple' object has no attribute 'log_softmax'问题描述原因分析解决办法问题描述pytorch 运行深度学习代码,F.cross_entropy 出现问题:Traceback (most recent call last): File "main.py", line 217, in <module> acc = test_clean() File "main.py", line 201, in test_clean loss原创 2020-11-04 10:33:56 · 3915 阅读 · 0 评论