我有火炬 1.6 和 python 3.8。训练 OpenNMT 时,会抛出以下错误 -
OSError: [WinError 126] 找不到指定的模块。加载“C:\Users\Girish\AppData\Local\Programs\Python\Python38\lib\sitepackages\torch\lib\caffe2_detectron_ops.dll”或其依赖项之一时出错。
我检查了该文件夹,该文件存在于该文件夹中。我尝试卸载 torch 并重新安装它,但没有帮助。
任何帮助将不胜感激。谢谢
如何检查 PyTorch 训练期间某些权重是否未更改?
据我了解,一种选择可以是在某些时期转储模型权重,并检查它们是否通过迭代权重进行更改,但也许有一些更简单的方法?
FashionMNIST 数据集有 10 个不同的输出类别。如何获取仅包含特定类的数据集的子集?就我而言,我只想要运动鞋、套头衫、凉鞋和衬衫类别的图像(它们的类别分别为 7、2、5 和 6)。
\n这就是我加载数据集的方式。
\ntrain_dataset_full = torchvision.datasets.FashionMNIST(data_folder, train = True, download = True, transform = transforms.ToTensor())
我\xe2\x80\x99ve遵循的方法如下。\n逐一迭代数据集,然后将返回的元组中的第一个元素(即类)与我所需的类进行比较。我\xe2\x80\x99m 卡在这里。如果返回的值为 true,我如何将此观察结果追加/添加到空数据集中?
\nsneaker = 0\npullover = 0\nsandal = 0\nshirt = 0\nfor i in range(60000):\n if train_dataset_full[i][1] == 7:\n sneaker += 1\n elif train_dataset_full[i][1] == 2:\n pullover += 1\n elif train_dataset_full[i][1] == 5:\n sandal += 1\n elif train_dataset_full[i][1] == 6:\n shirt += 1\n
Run Code Online (Sandbox Code Playgroud)\n现在,代替sneaker += 1
、pullover += 1
、sandal += 1 …
我正在使用 PyTorch Lightning 训练图像分类模型,并在具有多个 GPU 的机器上运行,因此我使用推荐的分布式后端以获得最佳性能ddp
(DataDistributedParallel)。这自然会分割数据集,因此每个 GPU 只能看到数据的一部分。
但是,对于验证,我想计算整个验证集(而不仅仅是一部分)的准确性等指标。我该怎么做呢?我在官方文档中找到了一些提示,但它们没有按预期工作或者让我感到困惑。所发生的情况validation_epoch_end
称为每次验证数据的num_gpus
次数。1/num_gpus
我想汇总所有结果并只运行validation_epoch_end
一次。
在本节中,他们指出,当使用 dp/ddp2 时,您可以添加一个附加函数,如下所示
def validation_step(self, batch, batch_idx):
loss, x, y, y_hat = self.step(batch)
return {"val_loss": loss, 'y': y, 'y_hat': y_hat}
def validation_step_end(self, self, *args, **kwargs):
# do something here, I'm not sure what,
# as it gets called in ddp directly after validation_step with the exact same values
return args[0]
Run Code Online (Sandbox Code Playgroud)
然而,结果并没有被聚合,validation_epoch_end
仍然被称为num_gpu
时间。这种行为不适合吗ddp
?还有其他方法可以实现这种聚合行为吗?
python parallel-processing distributed-computing pytorch pytorch-lightning
我正在尝试将 HuggingFace 变压器模型中的 Pegasus 新闻编辑室转换为 ONNX 格式。我遵循了Huggingface 发布的指南。安装先决条件后,我运行了以下代码:
!rm -rf onnx/
from pathlib import Path
from transformers.convert_graph_to_onnx import convert
convert(framework="pt", model="google/pegasus-newsroom", output=Path("onnx/google/pegasus-newsroom.onnx"), opset=11)
Run Code Online (Sandbox Code Playgroud)
并得到这些错误:
ValueError Traceback (most recent call last)
<ipython-input-9-3b37ed1ceda5> in <module>()
3 from transformers.convert_graph_to_onnx import convert
4
----> 5 convert(framework="pt", model="google/pegasus-newsroom", output=Path("onnx/google/pegasus-newsroom.onnx"), opset=11)
6
7
6 frames
/usr/local/lib/python3.6/dist-packages/transformers/models/pegasus/modeling_pegasus.py in forward(self, input_ids, attention_mask, encoder_hidden_states, encoder_attention_mask, head_mask, encoder_head_mask, past_key_values, inputs_embeds, use_cache, output_attentions, output_hidden_states, return_dict)
938 input_shape = inputs_embeds.size()[:-1]
939 else:
--> 940 raise ValueError("You have to specify either …
Run Code Online (Sandbox Code Playgroud) 我有一个非常简单的例子
import torch
if __name__ == "__main__":
DEVICE = torch.device("cuda" if torch.cuda.is_available() else "cpu")
m = torch.nn.Linear(20, 30).to(DEVICE)
input = torch.randn(128, 20).to(DEVICE)
output = m(input)
print('output', output.size())
exit()
Run Code Online (Sandbox Code Playgroud)
我得到:
Traceback (most recent call last):
File "test.py", line 9, in <module>
output = m(input)
File "/home/shamoon/.local/share/virtualenvs/speech-reconstruction-7HMT9fTW/lib/python3.8/site-packages/torch/nn/modules/module.py", line 889, in _call_impl
result = self.forward(*input, **kwargs)
File "/home/shamoon/.local/share/virtualenvs/speech-reconstruction-7HMT9fTW/lib/python3.8/site-packages/torch/nn/modules/linear.py", line 94, in forward
return F.linear(input, self.weight, self.bias)
File "/home/shamoon/.local/share/virtualenvs/speech-reconstruction-7HMT9fTW/lib/python3.8/site-packages/torch/nn/functional.py", line 1753, in linear
return torch._C._nn.linear(input, weight, bias)
RuntimeError: CUDA error: CUBLAS_STATUS_INTERNAL_ERROR when calling `cublasCreate(handle)` …
Run Code Online (Sandbox Code Playgroud) 我正在尝试训练深度学习架构,模型训练得非常完美。我在每个纪元后进行测试。对于 7 epoch,所有损失和准确性似乎都不错,但在测试期间的 8 epoch,测试损失变为 nan。我检查了我的数据,没有nan。而且我的测试准确度比火车高,这很奇怪。训练数据大小为 37646,测试数据大小为 18932,所以应该足够了。在成为 nan 测试之前,开始变得非常高,约为 1.6513713663602217e+30。这真的很奇怪,我不明白为什么会发生。非常感谢任何帮助或建议。
with torch.no_grad:AttributeError: __enter__
Run Code Online (Sandbox Code Playgroud)
我在运行 pytorch 代码时遇到此错误。
我有 torch==0.4.1 torchvision==0.3.0,我在 google colab 中运行代码。
我试图找到图中负边和正边的解释,如函数 train_test_split_edges Pytorch Geometric doc开头所述。根据文档文件,它说该函数应该将图分成“正和负训练/验证/测试边缘”。就此而言,正边缘或负边缘的含义是什么?根据代码,正边“似乎”是图的邻接矩阵的上三角形中的边的连接,负边是邻接矩阵的下三角形中的边。因此,如果 (1,0) 被认为是正边,那么在无向图中 (0,1) 就是负边。我对么?我没有找到任何有关图表中正边缘/负边缘含义的信息。
这是我的文件夹结构
\nimage-folders/\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 class_0/\n | \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 001.jpg\n | \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 002.jpg\n \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 class_1/\n | \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 001.jpg\n | \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 002.jpg\n \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 class_2/\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 001.jpg\n \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 002.jpg\n
Run Code Online (Sandbox Code Playgroud)\n通过使用ImageFolder
torchvision,我可以使用以下语法创建数据集:
\ndataset = ImageFolder("image-folders",...)
但这将读取整个子文件夹并创建 3 个目标类。我不想包含 class_2 文件夹,我希望我的数据集仅包含 class_0 和 class_1,除了删除/移动 class_2 文件夹之外,还有什么方法可以实现此目的?
\n