在 ubuntu 16.04 中运行脚本时出现此错误。请耐心等待,我是 python 新手,我已经检查了互联网上已经可用的选项,但我无法修复它。
RuntimeError: cuda runtime error (10) : invalid device ordinal at torch/csrc/cuda/Module.cpp:32
Run Code Online (Sandbox Code Playgroud)
我目前正在运行这个文件。
from __future__ import print_function
from models import LipRead
import torch
import toml
from training import Trainer
from validation import Validator
print("Loading options...")
with open('options.toml', 'r') as optionsFile:
options = toml.loads(optionsFile.read())
if(options["general"]["usecudnnbenchmark"] and options["general"] ["usecudnn"]):
print("Running cudnn benchmark...")
torch.backends.cudnn.benchmark = True
#Create the model.
model = LipRead(options)
if(options["general"]["loadpretrainedmodel"]):
model.load_state_dict(torch.load(options["general"] ["pretrainedmodelpath"]))
#Move the model to the GPU.
if(options["general"]["usecudnn"]):
model = model.cuda(options["general"]["gpuid"])
trainer = Trainer(options) …
Run Code Online (Sandbox Code Playgroud) 在pytorch 上,在 Windows 10、conda 和 Cuda 9.0 上安装。
当我运行时 cmd 没有抱怨conda install pytorch cuda90 -c pytorch
,然后当我运行时pip3 install torchvision
我收到此错误消息。
Requirement already satisfied: torchvision in PATHTOFILE\python35\lib\site-packages (0.2.1)
Requirement already satisfied: numpy in PATHTOFILE\python35\lib\site-packages (from torchvision) (1.12.0+mkl)
Requirement already satisfied: six in PATHTOFILE\python35\lib\site-packages (from torchvision) (1.10.0)
Collecting pillow>=4.1.1 (from torchvision)
Using cached https://files.pythonhosted.org/packages/ab/d2/d27a21bd3e64db1ca1dc7dc16026a16d77f5c3ffca9ec619eddeea7c47ce/Pillow-5.1.0-cp35-cp35m-win_amd64.whl
Collecting torch (from torchvision)
Using cached https://files.pythonhosted.org/packages/5f/e9/bac4204fe9cb1a002ec6140b47f51affda1655379fe302a1caef421f9846/torch-0.1.2.post1.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in …
Run Code Online (Sandbox Code Playgroud) 我有一个训练有素的网络。我想计算输出与输入的梯度。通过查询 PyTorch 文档,torch.autograd.grad可能会有用。所以,我使用以下代码:
x_test = torch.randn(D_in,requires_grad=True)
y_test = model(x_test)
d = torch.autograd.grad(y_test, x_test)[0]
Run Code Online (Sandbox Code Playgroud)
model
是神经网络。x_test
是大小的输入D_in
和y_test
一个标量输出。我想将计算结果与数值差异进行比较scipy.misc.derivative
。所以,我通过设置一个索引来计算偏导数。
idx = 3
x_test = torch.randn(D_in,requires_grad=True)
y_test = model(x_test)
print(x_test[idx].item())
d = torch.autograd.grad(y_test, x_test)[0]
print(d[idx].item())
def fun(x):
x_input = x_test.detach()
x_input[idx] = x
with torch.no_grad():
y = model(x_input)
return y.item()
x0 = x_test[idx].item()
print(x0)
print(derivative(fun, x0, dx=1e-6))
Run Code Online (Sandbox Code Playgroud)
但我得到了完全不同的结果。由 计算的梯度torch.autograd.grad
为-0.009522666223347187
,而由计算的梯度scipy.misc.derivative
为-0.014901161193847656
。
计算上有什么问题吗?还是我用torch.autograd.grad
错了?
在 pytorch 中,我们需要NCHW
格式的图像,但我的图像是NHWC
.
将此图像提供给 CNN 的程序是什么?(我发现这个解决方案建议使用“置换”,但我应该在哪里以及如何使用它?)
我正在制作一个用于时间序列数据分析的机器学习程序,使用 NEAT 可以帮助完成这项工作。不久前开始学习TensorFlow,但似乎TensorFlow中的计算图通常是固定的。TensorFlow 中是否有工具可以帮助构建动态演化的神经网络?或者像 Pytorch 这样的东西会是更好的选择?谢谢。
我可以用它torch.cuda.device_count()
来检查 GPU 的数量。我想知道是否有等同于检查 CPU 数量的东西。
我正在处理非常稀疏的向量作为输入。我开始使用简单的Linear
(密集/完全连接的层)并且我的网络产生了非常好的结果(让我们在这里将准确度作为我的指标,95.8%)。
后来我尝试将 aConv1d
与 akernel_size=1
和 a一起使用MaxPool1d
,这个网络的效果稍微好一些(96.4% 的准确率)。
问题:这两种实现有何不同?Conv1d
一个单位kernel_size
不应该和一个Linear
层一样吗?
我试过多次运行,CNN 总是产生稍微好一点的结果。
这不是一个新问题,我找到了没有任何解决方案的参考文献first和second。我是 PyTorch 的新手,AttributeError: 'Field' object has no attribute 'vocab'
在PyTorch
使用torchtext
.
继本书之后,Deep Learning with PyTorch
我编写了与书中解释的相同的示例。
这是片段:
from torchtext import data
from torchtext import datasets
from torchtext.vocab import GloVe
TEXT = data.Field(lower=True, batch_first=True, fix_length=20)
LABEL = data.Field(sequential=False)
train, test = datasets.IMDB.splits(TEXT, LABEL)
print("train.fields:", train.fields)
print()
print(vars(train[0])) # prints the object
TEXT.build_vocab(train, vectors=GloVe(name="6B", dim=300),
max_size=10000, min_freq=10)
# VOCABULARY
# print(TEXT.vocab.freqs) # freq
# print(TEXT.vocab.vectors) # vectors
# print(TEXT.vocab.stoi) # Index
train_iter, test_iter …
Run Code Online (Sandbox Code Playgroud) 我想使用 skorch 在 Pytorch 中应用交叉验证,所以我准备了我的模型和我的 tensorDataset,它返回(图像、标题和标题长度),所以它有 X 和 Y,所以我无法在方法中设置 Y
net.fit(dataset)
Run Code Online (Sandbox Code Playgroud)
但是当我尝试时出现错误:
ValueError: Stratified CV 需要明确传递一个合适的 y
这是我的代码的一部分:
start = time.time()
net = NeuralNetClassifier(
decoder, criterion= nn.CrossEntropyLoss,
max_epochs=args.epochs,
lr=args.lr,
optimizer=optim.SGD,
device='cuda', # uncomment this to train with CUDA
)
net.fit(dataset, y=None)
end = time.time()
Run Code Online (Sandbox Code Playgroud) machine-learning computer-vision deep-learning pytorch skorch
我正在尝试使用 PyTorch LSTM 训练一个简单的 2 层神经网络,但在解释 PyTorch 文档时遇到问题。具体来说,我不太确定如何处理我的训练数据的形状。
我想要做的是通过小批量在一个非常大的数据集上训练我的网络,其中每个批次的长度为 100 个元素。每个数据元素将有 5 个特征。文档指出层的输入应该是形状(seq_len、batch_size、input_size)。我应该如何塑造输入?
我一直在关注这篇文章:https : //discuss.pytorch.org/t/understanding-lstm-input/31110/3,如果我正确解释了这一点,每个小批量应该是形状 (100, 100, 5 )。但在这种情况下,seq_len 和 batch_size 有什么区别?另外,这是否意味着输入 LSTM 层的第一层应该有 5 个单元?
谢谢!
pytorch ×10
python ×7
gpu ×1
gradient ×1
image ×1
iterator ×1
lstm ×1
neat ×1
nlp ×1
permutation ×1
python-3.x ×1
skorch ×1
tensorflow ×1
torchtext ×1